当我直接在glDrawElements()
传递我的索引数据时,一切正常。但是当我使用vao和vbo时,根本没有绘制模型。
不使用vao和vbo并取消注释注释部分可以正常工作。
以下是代码
全球资料
#include<GL\glew.h>
#include<GL\freeglut.h>
#include"OBJFileParser.h"
GLfloat *vertexData;
GLuint* indices;
int size;
ObjParser* parser = ObjParser::getObjParser();
下面的渲染功能
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, -8);
glDrawElements(GL_TRIANGLES,size,GL_UNSIGNED_INT, (void*)0);
//This works fine
//glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, indices);
glutSwapBuffers();
}
下面的初始化功能
void init() {
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50, 1, 5, 20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Just parsing the obj file
parser->parseObj("file.txt");
vertexData = parser->getVertexData();
indices = parser->getIndices();
size = parser->getIndicesSize();
GLuint vaoId;
GLuint vboId[2];
glGenVertexArrays(1, &vaoId);
glBindVertexArray(vaoId);
glGenBuffers(2, vboId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId[0]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vboId[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
//This works fine
/*glVertexPointer(3, GL_FLOAT, 0, vertexData);
glEnableClientState(GL_VERTEX_ARRAY);*/
}
下面的主要功能
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(10, 10);
glutCreateWindow("My Window");
glewInit();
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
答案 0 :(得分:0)