Vertex Arrays

Started by
2 comments, last by tuxx 22 years ago
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:
      
// 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 );
  
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]
[email=dumass@poppet.com]dumass@poppet.com[/email]
Advertisement
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.
[email=dumass@poppet.com]dumass@poppet.com[/email]
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]
Hey cool, thanks! I was so caught up on that Direct3D8 Vertex Buffer thing (with g_Vertices and pVertices) that I got a little weird. It works now. Thanks! I feel sorta stupid asking a stupid question that gets the answer in 10 minutes . Well, thanks!
[email=dumass@poppet.com]dumass@poppet.com[/email]

This topic is closed to new replies.

Advertisement