quads? triangles? glvertex4f?? glvertex3f??

Hi!
im reading data from an obj file
the mesh is made of quads (its a cube)
I understand everything about the OBJ format
but I dont understand how to pass the data to opengl
in the way that
for example:

f 1/1/1 3/2/3 4/3/4 2/4/2

thats the first face, vertices 1,3,4,2 are used
Thats ok, but how do I pass this to opengl?
using glvertex4f(1,3,4,2) ??? I made the cube with all the correct data and it was a mess!
So can anyone tell me how to use glvertex4f or should I use glvertex3f always? im using glbegin with Quads as well!

else how can i convert from quads to triangles so i can easly render with glvertex3f ? (if not help me please)

glVertexnf specifies a single vertex directly. The number refers to the number of coordinate axes you want to specify.

If you’re rendering a single QUAD, you need to specify 4 vertices, e.g.:

glBegin(GL_QUADS);
glVertex3f(-10,-10, 5);
glVertex3f( 10,-10, 5);
glVertex3f( 10, 10,-5);
glVertex3f(-10, 10,-5);
glEnd();

If OBJ specifies the vertices and then links quads by vertex index, then vertex arrays combined with glDrawElements would be a good way to improve performance.

thanks
i think i got it now :slight_smile: im using arrays on a forbidden language so it will be pretty hard to know which data goes where

but what happens when you have some faces that are quads and some others that are triangles?? can i use gl_quads anyway?

You can easily treat triangles as if they were quads,
by collapsing two nodes. In other words, you repeat
the last third node as a fourth node to a quad. This
might introduce artifacts in the picture… As an
alternative, treat quads as two triangles, so that
you only specify triangles after all (I do that).

Also, you can build vertex array objects so that you
can specify the triangles once, and then basically
call lists of arrays for each of the objects. This
is what you do when you want performance out of the
hardware… Read the “red book” for more details
(VBOs, vertex arrays, etc).

Finally, there are certain things for which you can
use your creativity to do, like treating quads as
two triangles, etc. But if you want performance,
you are better off using techniques that other
people have developed and are well documented in
the forum among other places.

i was going to use display lists hm
wouldnt i gain more performance also, if i only supported triangulated data? and do a small check to see if its not triangulated, then halt the operation? because its simple to triangulate a mesh in almost any program its possible and if supporting quads so then ill transform them into triangles (which makes sense because at the end everything is a triangle) could eat up some performance even if the method is fast. the problem is that i want to fully support the OBJ format (including materials but that sounds easy thing). so vertex arrays in opengl? im already using arrays for all the data of the mesh but didnt knew opengl had arrays for this.

alright i found some articles about locked vertex buffers etc im going to read them thanks! any question i have i guess that if i cant manage it myself… it will come up to here!