GL_TRIANGLES 有效,但 GL_QUADS 不显示任何内容
GL_TRIANGLES works but GL_QUADS displays nothing
所以我要从一个程序切换到另一个程序,但我不知道为什么 GL_QUADS 将不再显示相同的代码。为了弄清楚为什么旧代码不起作用,我编写了这个新的、简单的代码,但它仍然不起作用。
设置:
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);
图纸:
glBindVertexArray(VAOO);
glDrawElements(GL_QUADS, squareindex.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
这什么都不显示。现在,如果我在设置中添加两条注释行以使其成为 6 点,并在绘图中将其更改为 GL_TRIANGLES,它就会完美显示。我不确定这里的故障出在哪里,但我一直在尝试修复我的模型加载和其他功能,以至于我确定此时我只是忽略了一些非常明显的东西。
GL_QUADS have been removed 来自核心 OpenGL 3.1 及更高版本。
所以我要从一个程序切换到另一个程序,但我不知道为什么 GL_QUADS 将不再显示相同的代码。为了弄清楚为什么旧代码不起作用,我编写了这个新的、简单的代码,但它仍然不起作用。
设置:
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);
图纸:
glBindVertexArray(VAOO);
glDrawElements(GL_QUADS, squareindex.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
这什么都不显示。现在,如果我在设置中添加两条注释行以使其成为 6 点,并在绘图中将其更改为 GL_TRIANGLES,它就会完美显示。我不确定这里的故障出在哪里,但我一直在尝试修复我的模型加载和其他功能,以至于我确定此时我只是忽略了一些非常明显的东西。
GL_QUADS have been removed 来自核心 OpenGL 3.1 及更高版本。