Имею вот такой Tessellator:
#include "Tessellator.h"
Tessellator::~Tessellator() {
delete vertexFormat;
}
Tessellator* Tessellator::Color(float r, float g, float b, float a) {
colors.push_back(r);
colors.push_back(g);
colors.push_back(b);
colors.push_back(a);
return this;
}
Tessellator* Tessellator::Tex(float u, float v) {
texCoords.push_back((GLfloat) u);
texCoords.push_back((GLfloat) v);
return this;
}
Tessellator* Tessellator::Begin(int primitiveMode) {
if (drawing)
throw std::runtime_error("Already drawing");
this->primitiveMode = primitiveMode;
this->drawing = true;
return this;
}
void Tessellator::Draw() {
if (!drawing)
throw std::runtime_error("Isn't drawing");
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &vertices[0]);
glColorPointer(4, GL_FLOAT, 0, &colors[0]);
glDrawArrays(primitiveMode, 0, static_cast<GLsizei>(vertices.size() / 2));
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
this->vertices.clear();
this->colors.clear();
this->drawing = false;
}
Tessellator* Tessellator::Vertex(float x, float y) {
vertices.push_back((GLfloat) x);
vertices.push_back((GLfloat) y);
return this;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_ALPHA_TEST);
glShadeModel(GL_SMOOTH);
tessellator->Begin(GL_QUADS);
tessellator->Color(0.0f, 0.0f, 1.0f)->Vertex(0, 0);
tessellator->Color(0.0f, 0.0f, 1.0f)->Vertex(width, 0);
tessellator->Color(1.0f, 1.0f, 0.0f)->Vertex(width, height);
tessellator->Color(1.0f, 1.0f, 0.0f)->Vertex(0, height);
tessellator->Draw();
glShadeModel(GL_FLAT);
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
Но вместо удачного результата каждый раз получаю бред (иногда я получаю правильный результат):
OpenGL Version: 4.6.0 NVIDIA 391.35