Jump to content
  • Advertisement
Sign in to follow this  
Kris2456

Vertex Array Question

This topic is 5170 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

Hello, i am working on a .OBJ file loader so i get the hang of model loading. I plan to use vertex arrays in my model loader so that things are drawn faster, but theres one thing i dont understand. Heres my problem: I have two functions, one for loading the file, and one for drawing. The one that loads packs the data into a vertex array, and the one that draws, well... draws it. To enable arrays i have to use glEnableClientState(). So in my load function i want to have:
//in load function
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

...Pack stuff into array....

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);



//In draw function
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

...Draw stuff from array....

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

Its just that im not sure if disabling the client state before drawing will work. I've never used arrays before. So is it possible?

Share this post


Link to post
Share on other sites
Advertisement
You should do the rendering totaly in render/draw function in my opinion.


void Draw()
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(...);

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(...);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(...);

glDrawElements(....);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}



In load function just build the vertices/normals/textures etc. No need to call glEnableClientState or glDisableClientState.




Share this post


Link to post
Share on other sites
these commands //in load function
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

...Pack stuff into array....

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

only make a difference if youre drawing something thus dont stick them in the loading code

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!