// Make a cube
float VertexList[] = {
// X, Y, Z
-1.0f,-1.0f, 1.0f, // Front face
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f,-1.0f, // Back face
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f, // Top face
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f, // Bottom face
1.0f,-1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f,-1.0f, // Right face
1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f, // Left face
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
};
void *pVertexList;
float TexCoordList[] = {
// TEX1, TEX2,
0.0f, 0.0f, // Front face
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
1.0f, 0.0f, // Back face
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f, // Top face
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
1.0f, 1.0f, // Bottom face
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 0.0f, // Right face
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
0.0f, 0.0f, // Left face
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
};
void *pTexCoordList;
// Here I've made two seperate arrays, one for the vertice data
// and one for the texels. I've also made the corrisponding
// pointers to fill them into the memory.
// Note that this code here is part of an initialization function
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// copy the vertex/texel arrays into a pointer
memcpy(pVertexList,VertexList,sizeof(VertexList));
memcpy(pTexCoordList,TexCoordList,sizeof(TexCoordList));
// Set the vertex/texel arrays
glVertexPointer( 3, GL_FLOAT, 0, pVertexList );
glTexCoordPointer( 2, GL_FLOAT, 0, pTexCoordList );
// Note that the following code is part of the rendering func.
glRotatef(angle,1.0f,1.0f,1.0f);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glDrawArrays( GL_QUADS, 0, 72 );
Vertex Arrays
Hi,
I'm learning vertex arrays for OpenGL, but I didn't seem to code it right. I can't really figure out the problem because I know very little about Vertex Arrays. I'll give you a bit of a code dump here:
If you can figure out what's wrong, that would be great. Thanks in advance!
[edited by - tuxx on April 12, 2002 8:14:18 PM]
[edited by - tuxx on April 12, 2002 8:17:44 PM]
[edited by - tuxx on April 12, 2002 8:19:16 PM]
PS: It compiles and all, but when you run it it gives you a Windows error message (at least I think that''s what those are called)
glFramework 03.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
glFramework 03.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
Uh, you do malloc pVertexList and pTexCoordList, do you ? You are copying data in undefined pointers otherwise...
Why don't you just do that (without this memcpy stuff):
glVertexPointer( 3, GL_FLOAT, 0, VertexList );
glTexCoordPointer( 2, GL_FLOAT, 0, TexCoordList );
[edited by - Yann L on April 12, 2002 8:25:36 PM]
Why don't you just do that (without this memcpy stuff):
glVertexPointer( 3, GL_FLOAT, 0, VertexList );
glTexCoordPointer( 2, GL_FLOAT, 0, TexCoordList );
[edited by - Yann L on April 12, 2002 8:25:36 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement