PDA

View Full Version : glDrawElements



11-27-2005, 09:04 AM
Hello, i dont really get what's possible with glDrawElements.
I want to read whats happening in glDrawElements.
When i call this function like
glDrawElements(GLenum mode,GLsizei count,GLenum type,const GLvoid *indices)
{
//code here
}

Then what does "count" contain? Is it possible to check if an object is drawn by a number.
So for example something like this.

if(count == 1200)
{
//the cube is drawn
}

jide
11-27-2005, 11:27 AM
Take a good opengl programming book or at least see good tutorials about gl, check nehe on a search engine for example.

11-27-2005, 01:58 PM
I already checked that site, and it definitly doesnt answer my question in the tutorials.

11-28-2005, 02:02 AM
I belive count indicates the no of elements

for example consider the following example
Following is array which describing the indices of a model.
Here we want to render a model using triangle data,Since triangle contains 3 vertices, we refer the count as 3.

static GLint Indices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23, 24, 25, 26, 24, 26, 27, 28, 29, 30, 31, 32, 33,34, 35, 36, 37, 38, 39, 40, 41, 42, 40, 42, 43};
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, &Indices[0]);

Suppose if we want to render as polygon, which is represneted by 4 vertices, we will refer count as 4.

example
glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &Indices[0]);

Hope this helps you

Rajesh.R
IRIS,CAIR
Bangalore
rajeshr@cair.res.in

Bob
11-28-2005, 04:39 AM
Originally posted by <Rajesh>:
I belive count indicates the no of elements

for example consider the following example
Following is array which describing the indices of a model.
Here we want to render a model using triangle data,Since triangle contains 3 vertices, we refer the count as 3.

static GLint Indices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23, 24, 25, 26, 24, 26, 27, 28, 29, 30, 31, 32, 33,34, 35, 36, 37, 38, 39, 40, 41, 42, 40, 42, 43};
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, &Indices[0]);

Suppose if we want to render as polygon, which is represneted by 4 vertices, we will refer count as 4.

example
glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &Indices[0]);

Hope this helps you

Rajesh.R
IRIS,CAIR
Bangalore
rajeshr@cair.res.inOpenGL already knows how many vertices there are in a triangle; three, so you don't have to say it. What you haven't told OpenGL though is how large the index array is, you've only provided a pointer to the first element, but made no indication of where it ends.

count is the number of indices in the index array. In that example, count should be 60, as there are 60 indices (if I counted them correct).