Advertisement

[newbye] how many glbegin/end?

Started by May 18, 2003 04:32 AM
15 comments, last by Thor82 21 years, 9 months ago
hi all, i am REALLY NEW in opengl programming, and making some stupid code to try some poly i thought: if i have X triangles to draw, Y quads and Z poly it is better to use only once glbegin(polygon) or glbegin(gltriangles) . . . glend() glbegin(glquads) . . . glend() and so on? thanks since now for helping! There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...
It''s better to use vertex arrays
Advertisement
Thats right just confuse the poor guy even more

I don''t think it will make much difference in a small program. I think OpenGL is optimized to use GL_TRIANGLE and GL_QUAD. So its probably best to use them, but I dont think it will matter if you just use GL_POLYGON.

Hyperdev

"To err is human, to really mess up requires a computer"
"To err is human, to really mess up requires a computer"
the less glBegins/glEnds the faster...
well obviously in a program like first tuts its not a great difference...

i made a class objectlist
which has (obviously) a list of objects

an object has a list of faces (and other things but for now i need help on this)

a face has a list of vertexes

a list of vertexes has N vertex coords and an unsigned long
to hold how many vertexes are there in the list

i made a control like this FOR EACH FACE DRAWN:

unsigned long n=List.Count(); //how many vertexes
if(n == 3)
glBegin(GL_TRIANGLES);
else
if(n == 4)
glBegin(GL_QUADS);
else
if(n > 4)
glBegin(GL_POLYGON);
else
glBegin(GL_POINT);


//draw things

glEnd()

is this a bad way?
how could you improve this?
thanks!!


[edited by - Thor82 on May 18, 2003 8:48:24 AM]

[edited by - Thor82 on May 18, 2003 8:49:38 AM]
There aren''t problems that can''t be solved with a gun...
nobody could help me?
There aren''t problems that can''t be solved with a gun...
Advertisement
Patience young grasshopper.

Since you are making a list of vertices to represent an object I would recommend you take a look at display lists in OpenGL, Check the Red Book (it''s on gamedev''s site someone on line) or the OpenGL spec (what I use these days) for more info on it. It may help for what you want to do, at the very least it will speed up your rendering.

-B

I need no signature... well, alright.http://www.derzwerg.net
hi walshb,
i create objects that are supposed to be different from each other, it''s because of this that i have a list of vertexes,

now i read the tutorial about display list,but i don''t think that this could be a good choise if i have ALL different object right? but if i have for example N boxes i make a display list with a box and stop right?

There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...
Are you looking for performance, or the simplest way to do it?

I think it would be easier to use GL_TRIANGLES... And also then you would only have to use glBegin/glEnd once for every object...

And, as for display lists:

1. Generate list "name"
2. Begin the list
3. Render your object, just as if you were rendering to the screen..
4. End the display list

You can repeat this for every object you want to have...

And to render them use glCallList...
Thor, I believe the answer you are looking for is the following:

THE FEWER GLBEGINS AND GLENDS PER FRAME, THE FASTER IS THE RENDERING

If I were you I would try to use only triangles and call the following code ONCE per frame:


        glBegin(GL_TRIANGLES);for ( int a = 0; a < numTriangles; a++ ){  glVertex3f( tri[a].v[0].x, tri[a].v[0].y, tri[a].v[0].z );  glVertex3f( tri[a].v[1].x, tri[a].v[1].y, tri[a].v[1].z );  glVertex3f( tri[a].v[2].x, tri[a].v[2].y, tri[a].v[2].z );}glEnd();    


Now if you MUST have triangles, quads, and polys, do the same but using the GL_POLYGONS parameter instead and treat your triangles and quads like 3-sided and 4-sided polygons.


[edited by - Keermalec on May 22, 2003 10:08:45 AM]

This topic is closed to new replies.

Advertisement