Jump to content
  • Advertisement
Sign in to follow this  
tonnot

OpenGL About drawelements / drawelement ?

This topic is 2556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
- 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!