Skip to main content
gamedev.net
🔒 Locked

Vertex array problem

Started by flmn Dec 20, 2004 at 12:28 AM 1 replies 350+ views
Original Post
flmn
flmn
i try a simplest Vertex array, but it doesn't work, i can see anything , Can anyone help me with this? thanks here some codes: #define MESH_SIZE (1<<4) #define BUFFER_OFFSET(i) ((char *)NULL + (i)) //------------------------------------------------------------------------------ struct Vertex3 { Vertex3() : x(0.0f), y(0.0f), z(0.0f) {} float x, y, z; }; struct Normal3 { Normal3() : nx(0.0f), ny(1.0f), nz(0.0f) {} float nx, ny, nz; }; //------------------------------------------------------------------------------ Vertex3 Vertex[MESH_SIZE*MESH_SIZE]; Normal3 Normal[MESH_SIZE*MESH_SIZE]; GLuint Index[4*(MESH_SIZE-1)*(MESH_SIZE-1)]; //------------------------------------------------------------------------------ //!!!!!!!!!!!!!!!!!!!!!!! in init(): for (int i = 0; i < MESH_SIZE; ++i) { for (int j = 0; j < MESH_SIZE; ++j) { Vertex[i*MESH_SIZE+j].x = i; Vertex[i*MESH_SIZE+j].z = j; } } int numIndex = 0; for (unsigned int iv=0; iv<MESH_SIZE-1; iv++) { for (unsigned int iu=0; iu<MESH_SIZE-1; iu++) { Index[numIndex++] = (iv+1)*MESH_SIZE+iu; Index[numIndex++] = iv*MESH_SIZE+iu; Index[numIndex++] = iv*MESH_SIZE+iu+1; Index[numIndex++] = (iv+1)*MESH_SIZE+iu+1; } } //------------------------------------------------------------------------------ //!!!!!!!!!!!!!!!!!!!!!!! in render(): glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_NORMAL_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, Vertex); glNormalPointer(GL_FLOAT, 0, Normal); glIndexPointer(GL_UNSIGNED_INT, 0, Index); //glDrawArrays( GL_POINTS, 0, MESH_SIZE*MESH_SIZE ); glDrawElements ( GL_QUADS, 4*(MESH_SIZE-1)*(MESH_SIZE-1), GL_UNSIGNED_INT, Index); glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_NORMAL_ARRAY );
nts
nts
take out the glIndexPointer you dont need it, used for color indexing

otherwise that looks like it should work, is your camera pointed in the right direction?

does other data work, are you drawing anything else. Are you specifying any color cause if not they'll appear black and if you have a black background will make hard to see them :p
flmn
flmn
i have someother codes, these worked

glBegin(GL_QUADS);
for (int i=0; i < 4*(MESH_SIZE-1)*(MESH_SIZE-1); ++i) {
glNormal3f(Normal[Index].nx, Normal[Index].ny, Normal[Index].nz);
glVertex3f(Vertex[Index].x, Vertex[Index].y, Vertex[Index].z);
}
glEnd();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.