glDrawElements and STL vector

Started by
5 comments, last by Kito119 21 years, 9 months ago
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 ?
------------------------------Kito119Life Sux when u were in loveManou.... Aishiteru Imasu...
Advertisement
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!
神はサイコロを振らない!
You''re passing an incorrect array type to glDrawElements. It should be an array of indices, not vertices.

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]
------------------------------Kito119Life Sux when u were in loveManou.... Aishiteru Imasu...
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.

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]
glDrawElements(GL_QUADS, v1.size(), GL_INT, &v1.front());

&v1.front() is what i typically use, but v1[0] should do the same

This topic is closed to new replies.

Advertisement