How do I keep a 3D model on the screen in OpenGL?
Posted
by
NoobScratcher
on Game Development
See other posts from Game Development
or by NoobScratcher
Published on 2012-04-10T13:54:46Z
Indexed on
2012/04/10
17:47 UTC
Read the original article
Hit count: 251
I'm trying to keep a 3D model on the screen by placing my glDrawElement
functions inside the draw function with the declarations at the top of .cpp. When I render the model, the model attaches it self to the current vertex buffer object. This is because my whole graphical user interface is in 2D quads except the window frame. Is there a way to avoid this from happening? or any common causes of this?
Creating the file object:
int index = IndexAssigner(1, 1);
//make a fileobject and store list and the index of that list in a c string
ifstream file (list[index].c_str() );
//Make another string
//string line;
points.push_back(Point());
Point p;
int face[4];
Model rendering code:
int numfloats = 4;
float* point=reinterpret_cast<float*>(&points[0]);
int num_bytes=numfloats*sizeof(float);
cout << "Size Of Point" << sizeof(Point) << endl;
GLuint vertexbuffer;
glGenVertexArrays(1, &vao[3]);
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, points.size()*sizeof(points), points.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, num_bytes, &points[0]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, points.size(), &points[0]);
glEnableClientState(GL_INDEX_ARRAY);
glIndexPointer(GL_FLOAT, faces.size(), faces.data());
glEnableVertexAttribArray(0);
glDrawElements(GL_QUADS, points.size(), GL_UNSIGNED_INT, points.data());
glDrawElements(GL_QUADS, faces.size(), GL_UNSIGNED_INT, faces.data());
© Game Development or respective owner