starkr
April 26th, 2009, 02:37 PM
Hey gurus. I've got a challenge for you, or maybe I'm just retarded and my problem is very simple. Can't figure it out though.
Here's some context to my problem.
Case is that I'm trying to draw a cube using a vertex array, and drawing the sides out by triangles. I want to use triangles rather than quads in order to use the same method for drawing different shapes just changing the number of vertices that glDrawArrays() use.
Thus far I've been using two shapes: 1. 3D triangle. 8 triangle faces, 24 vertices. 2. 3D cube. 12 triangle faces, 36 vertices. My method checks the type of shape I want to draw and determines how many vertices it contains. This way I should be able to use the same set of vertex array calls to draw the shape, just giving glDrawArrays() the number of vertices the current shape actually contains. This works fine for the triangles, but leaves my cubes a complete mess. Thus I've written the code below, which should produce a cube made up of 12 triangles. I've double checked all the vertices and they check out. Thus I believe my trouble lies somewhere in the actual drawing below my array definition.
GLfloat testArray2[] = {
-5,-5,5, 5,-5,5, 5,5,5,
-5,-5,5, 5,5,5, -5,5,5
-5,5,5, 5,5,5, 5,5,-5,
-5,5,5, 5,5,-5, -5,5,-5,
5,-5,5, 5,-5,-5, 5,5,-5,
5,-5,5, 5,5,-5, 5,5,5,
-5,-5,5, 5,-5,-5, 5,-5,5,
-5,-5,5, -5,-5,-5, 5,-5,-5,
-5,-5,5, -5,5,-5, -5,-5,-5,
-5,-5,5, -5,5,5, -5,5,-5,
-5,-5,-5, 5,5,-5, 5,-5,-5,
-5,-5,-5, -5,5,-5, 5,5,-5};
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT,0,testArray2);
glDrawArrays(GL_TRIANGLES,0,36);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
Have I missed some vital information as to how the vertex arrays work? Or do I simply HAVE to use quads?
Here's some context to my problem.
Case is that I'm trying to draw a cube using a vertex array, and drawing the sides out by triangles. I want to use triangles rather than quads in order to use the same method for drawing different shapes just changing the number of vertices that glDrawArrays() use.
Thus far I've been using two shapes: 1. 3D triangle. 8 triangle faces, 24 vertices. 2. 3D cube. 12 triangle faces, 36 vertices. My method checks the type of shape I want to draw and determines how many vertices it contains. This way I should be able to use the same set of vertex array calls to draw the shape, just giving glDrawArrays() the number of vertices the current shape actually contains. This works fine for the triangles, but leaves my cubes a complete mess. Thus I've written the code below, which should produce a cube made up of 12 triangles. I've double checked all the vertices and they check out. Thus I believe my trouble lies somewhere in the actual drawing below my array definition.
GLfloat testArray2[] = {
-5,-5,5, 5,-5,5, 5,5,5,
-5,-5,5, 5,5,5, -5,5,5
-5,5,5, 5,5,5, 5,5,-5,
-5,5,5, 5,5,-5, -5,5,-5,
5,-5,5, 5,-5,-5, 5,5,-5,
5,-5,5, 5,5,-5, 5,5,5,
-5,-5,5, 5,-5,-5, 5,-5,5,
-5,-5,5, -5,-5,-5, 5,-5,-5,
-5,-5,5, -5,5,-5, -5,-5,-5,
-5,-5,5, -5,5,5, -5,5,-5,
-5,-5,-5, 5,5,-5, 5,-5,-5,
-5,-5,-5, -5,5,-5, 5,5,-5};
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT,0,testArray2);
glDrawArrays(GL_TRIANGLES,0,36);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
Have I missed some vital information as to how the vertex arrays work? Or do I simply HAVE to use quads?