GL_TRIANGLES works but GL_QUADS displays nothing

…衆ロ難τιáo~ 提交于 2021-01-29 15:55:55

问题


So I'm swapping from one program to another, and I can't figure out why but GL_QUADS will no longer display with the same code. To try and figure out why old code was not working, I made this new, simple code and it STILL does not work.

The setup:

vector <vec3f> squarepoints;
vec3f temper(-0.5f, 0.5f, 0.5f);
squarepoints.push_back(temper);
temper.x += 1.0f;
squarepoints.push_back(temper);
temper.y -= 1.0f;
squarepoints.push_back(temper);
temper.x -= 1.0f;
squarepoints.push_back(temper);
vector <unsigned int> squareindex;
squareindex.push_back(0);
squareindex.push_back(1);
squareindex.push_back(2);
//squareindex.push_back(0);
//squareindex.push_back(2);
squareindex.push_back(3);
GLuint VAOO;
GLuint IBOO;
GLuint VBOO;


glGenVertexArrays(1, &VAOO);
glBindVertexArray(VAOO);

glGenBuffers(1, &VBOO);
glBindBuffer(GL_ARRAY_BUFFER, VBOO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vec3f) * squarepoints.size(), &squarepoints[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT,GL_FALSE, 0, 0);       


glGenBuffers(1, &IBOO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * squareindex.size(), &squareindex[0], GL_STATIC_DRAW);
glBindVertexArray(0);

The drawing:

glBindVertexArray(VAOO);
    glDrawElements(GL_QUADS, squareindex.size(), GL_UNSIGNED_INT, 0);
    glBindVertexArray(0);

This displays nothing. Now if I add in the two commented lines in the setup to make it 6 points and change it to GL_TRIANGLES in the drawing, it all displays perfectly. I am not sure where the fault is lying here, but I've been trying to fix my model loading and other features so long that I'm sure I'm just overlooking something super obvious at this point.


回答1:


GL_QUADS have been removed from core OpenGL 3.1 and above.



来源:https://stackoverflow.com/questions/61387287/why-the-graphic-shown-when-the-primitive-is-triangle-but-it-disappeared-when-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!