Sign in to follow this  
Kris2456

Vertex Array Question

Recommended Posts

Kris2456    100
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
CRACK123    235
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
zedzeek    529
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this