About drawelements / drawelement ?

Started by
4 comments, last by V-man 12 years, 8 months ago
Hello:
I dont know if this can be done easily.
I have a 3dfloat matrix where I store 5 points for a pentagon . In example, I have 10 pentagon.
I can create an index matriz to store :
1.- The index of every point
2.- or the index of the beggining point of every pentagon.
Is there a way to say Opengl to draw the 10 pentagons only with 2 lines of code ?
One to specify the index matrix and the other to draw_elements following the indexes.

I dont know if it can be done using drawlements, but I dont know how to write the code ?


Any help ?
Thanks.
Advertisement

Is there a way to say Opengl to draw the 10 pentagons only with 2 lines of code ?


NO. OpenGL supports triangles though, so construct a single list with the vertices, and another list with indices that describe a pentagon as 3 traingles. You won't ever get as low as 2 calls though (because you'll need to set the vertex attrib pointers, enable the attrib arrays, draw the elements, and then disable the attrib arrays afterwards. It is 'possible' to set the data for a single pentagon as a GL_POINT and use a geometry shader to generate the triangles automatically if you want. For so few pentagons, it's probably not worth the bother though
The code I have in mind works fine with QUADS.
Opengl see at the index matrix looking 4 points and drawelements (GL_CUAD) goes jumping 4,4,4,4 ....
To draw pentagons or a fixed number poligon using drawelements i have to write a for () :

for (n=0; n<number_of _polygons;n++)
glDrawElements(GL_LINE_LOOP,5, GL_UNSIGNED_SHORT, &indices +5*n );

[font="Arial"]
(indices moves in fives automatically)[/font]

I'm planing to draw an undeterminated number of polygons, opened or closed, every one with a know number of points.
So,I'm afraid tha I have I to apply a clicle to a gldrawelements or there is a trick ?

Thanks
If you are going to draw with lines, your problem is using GL_LINE_LOOP.
Use GL_LINES instead and you can draw many pentagon outlines with just a single call to glDrawElements.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanks
Besides drawin pentagons, etc. I'd want to write a fastest way to draw big vectorial worlds .
They are composed by a undetermined big number of lines, and for each line I have a color, line type and the points for each line.

I have the 3d matrix for all the float points of a world.
To draw it, I can :
- do a for loop trought all the polyline matrix and call drawelements
- do a unique call to ... what ?

Any help ? Thanks
- do a unique call to ... what ?[/quote]
It depends on the GL version you are targetting. If you are targetting old GL (which is 2.1 and below)
let's look at http://www.opengl.org/wiki/Vertex_Arrays

They are calling glEnableClientState to enabled the array types that they need and then they are calling the pointer function such as glVertexPointer and then they fire with
glDrawRangeElements or glDrawElements (whatever you prefer).

That page was using client side arrays. If you prefer to use IBO/VBO with your GL 2.1 code, there are a few pages at http://www.opengl.org/wiki/General_OpenGL

If I misunderstood your question, let us know.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement