我使用SFML / OpenGl
当我正方形纹理(由2个三角形组成)和图像时,会出现1个不需要的三角形:
错误是屏幕中间的小棕色三角形。
这是我的代码: 绘图功能:
glUseProgram(shader->getProgramID());
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, coordTexture);
glEnableVertexAttribArray(2);
glUniformMatrix4fv(glGetUniformLocation(shader->getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));
glUniformMatrix4fv(glGetUniformLocation(shader->getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));
sf::Texture::bind(&textTest, sf::Texture::Normalized);
glDrawArrays(GL_TRIANGLES, 0, 9);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(0);
sf::Texture::bind(NULL);
glUseProgram(0);
参数:
shader = new Shader(vertexSource, fragmentSource);
float t = taille/2;
float points[] = { -t,-2.0,-t, -t,-2.0,t, t,-2.0,-t,
t,-2.0,-t, t,-2.0,t, -t,-2.0,t};
float text[] = {
0.0,0.0, 0.0,1.0, 1.0,0.0,
1.0,0.0, 1.0,1.0, 0.0,1.0,
};
for (int i = 0; i < 6*3; i++)
{
vertices[i] = points[i];
this->couleurs[i] = 1.0;
}
for (int i = 0; i < 6 * 2; i++)
{
this->coordTexture[i] = text[i];
}
shader->charger();
textTest.loadFromFile("lama.jpg");
这很奇怪,因为当我改变时:
float text[] = {
0.0,0.0, 0.0,1.0, 1.0,0.0,
1.0,0.0, 1.0,1.0, 0.0,1.0,
};
到(切换坐标):
float text[] = {
1.0,0.0, 1.0,1.0, 0.0,1.0,
0.0,0.0, 0.0,1.0, 1.0,0.0,
};
不需要的三角形消失了,但当然纹理的结果并不好。