Archived

This topic is now archived and is closed to further replies.

Kito119

glDrawElements and STL vector

Recommended Posts

I made approximatively this : vector v1; v1.Push_back(20); etc... glVertexPointer (3, GL_INT, 0, &v1); glDrawElements(GL_QUADS, v1.size(), GL_INT, &v1); but i can''t see anything on the screen ! Can I use the vector type or do i have to use another type ?

Share this post


Link to post
Share on other sites
You''re giving the functions the address of the vector itself,
which is wrong.

Do this instead:

glVertexPointer (3, GL_INT, 0, &v1[0]);
glDrawElements(GL_QUADS, v1.size(), GL_INT, &v1[0]);


~~~~
Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
What do you mean by an array of indices, not vertices ?

Presently, i'm doing this with v1 in a loop
v1.PushBack(x)
v1.PushBack(y)
v1.PushBack(z)

then when i have to render

glColorPointer (3, GL_FLOAT, 0, &v2[0]);
glVertexPointer (3, GL_INT, 0, &v1[0]);
glDrawElements(GL_QUADS, v1.size(), GL_INT, &v1[0]);

------------------------------
Kito119

Life Sux when u were in love

[edited by - Kito119 on July 17, 2002 4:24:52 PM]

[edited by - Kito119 on July 17, 2002 4:28:32 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Kito119
glVertexPointer (3, GL_INT, 0, &v1);
glDrawElements(GL_QUADS, v1.size(), GL_INT, &v1);


You''re passing vertices there. glDrawElements takes indices; you already passed the vertices to glVertexPointer. If you don''t actually need indices, use glDrawArrays instead.

Share this post


Link to post
Share on other sites
indices are a list of vertices to draw. glDrawElements() takes a list of indices

to learn more about glDrawElements(), glDrawArrays(), vertex arrays and indices (which are a very powerful feature):

look here for the specification:
http://www.opengl.org/developers/documentation/OGL_userguide/OpenGLonWin-15.html

or here for the implementation(page search for vertex array dload the .zip file with working code):
http://www.codecolony.de/opengl.htm

basically the short of it all is that to use vertex arrays, you make and array of vertices (your vector is fine for that purpose). then you make a list of numbers that are the order in which you want vectors from your vector array to be drawn. for your case that array would just be incrementing GLubyte's from 0 -> vertexVector.size() so {0,1,2,3,4,5......size}

-me

[edited by - Palidine on July 17, 2002 4:37:58 PM]

Share this post


Link to post
Share on other sites