Jump to content
  • Advertisement
Sign in to follow this  
brohan

Confused Reagrding glvertexpointer

This topic is 4238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having a problem reagrding glvertexpointer using with gldrawelements Below is my source code : load(): vertex= new GLfloat[num_vert]; for(int i=0;i<num_vetex;++i) { fscanf(fp,"%f ",&vertex); } fscanf(fp,"%d\n",&num_index); index=new GLubyte[num_index]; for(int j=0;j<num_index;j++) { fscanf(fp,"%d \n",&index[j]); } Draw: glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,vertex); glColor3f(1.0f,1.0f,0.0f); glDrawElements(GL_TRIANGLES,num_index,GL_UNSIGNED_BYTE,index); while vertex is GLfloat array and index is a GLubyte array which are declared globally if I use the above code it works fine and the primitve is rendered properly even if I change a code like below which logically is same, nothing is rendered on the screen. The only thing I change is the reading elemnet reversely and storing it reversly which should not make a difference in the way it is stored in buffer. the revised code is : load(): vertex= new GLfloat[num_vert]; for(int i=(num_vetex-1);i>=0;--i) { fscanf(fp,"%f ",&vertex); } fscanf(fp,"%d\n",&num_index); index=new GLubyte[num_index]; for(int j=(num_index-1);j>=0;--j) { fscanf(fp,"%d \n",&index[j]); } Draw: glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,vertex); glColor3f(1.0f,1.0f,0.0f); glDrawElements(GL_TRIANGLES,num_index,GL_UNSIGNED_BYTE,index);

Share this post


Link to post
Share on other sites
Advertisement
Hi brohan,
Because you read one float value one at a time, the order of (x,y,z) might be swapped in the second code.
The first code reads x, y, and z in order and store vertex array. But it seems to me that the second code reads the x-value(the first one) and puts it at last, which is actually z-value. So it looks like zyx zyx zyx ...in the array.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!