efficiency of making 3D objects

there are 2 ways im working with to create 3D bjects right now. The examples I’ll use are with making cubes.

1st way:
Draw all the sides in a function one by one.

2nd way:
Make a function that draws a square. Then a function that calls that function 6 times, rotating the axes each time you draw a side. When finished, rotate back to the original state.

Both ways create the same cube perfectly. The 2nd way has less code, and has a better style in my opinion. However, I’m assuming that glRotate() is O(1). If not, then the 1st one may be uglier, but more efficient.

Any idea what type of operation glRotate() is?

make objects in maya and load them in, forget trying to do it yourself

Forget maya (costs $$$), use anim8or or ac3d and save to 3ds format. Then use any of the many 3ds loader routines available to import 3ds into your code. Finally, have a beer.

Personally I like procedural modeling so I think doing it at runtime is cool.

About the question…
What exactly means ‘draws a cube’ and ‘draws a quad called six times’?
Personally, I did something similar a year ago (or more?). Of curse, drawing all the cube at once would be faster but the performance gain would be minimal, unnoticeable at least, especially if you cache the results.
So, by this point of view, I would have a ‘drawQuad’ routine called six times becouse It can be recycled to do other things with ease (parallelepipeds, planes, some faces of the edges).
Please note however that I would cache the results, so ‘drawQuad’ should be called ‘genQuadVertices’.

Don’t mind about the performance trouble right now.


no dont forget maya, just download the personal learning edition. Obviiously when trying to do any
real apps like games you will not be able to make complex objects at runtime


I meant exactly what you assumed. Have a DrawQuad routine which draws a quad, and a DrawCube routine that draws a cube by calling DrawQuad 6 times. I explained it as a function though. I use those words interchangably. I consider functions and routines the same, functions just return thing. I should probably get out of that habit.

And being that I am just begining OpenGL I’m not going to use other programs to learn how to use it. That’s just silly.

If I understand you properly you are considering writing a function which draws a cube which is based on a function that draws a square, am I right?
If so, there isn’t anything you should worry about. It would surely make your code simpler and better to read.
If you are thinking about performace,remember that calling functions also take some time. You can optimize your function by defining square-drawing func. by “inline” (if you write in C). It tells the compiler to replace calls to this function by functions body. It makes your application bigger but your quad-drawing function won’t be making jumps to sub-functions.
I hope you understand me


There is a third way to generate a cube(box), that is with display list.

You have a data set like this:

GLfloat cube[24][3] = {{ x, y, z}, …
In which the cube has 24 vertex points, which is your data supplied by the array.

You use the gl functions to create a list in which you call as a routine.

nehe.gamedev.net is a good place to start with some good tutors on how to program with openGL.

Any idea what type of operation glRotate() is?

Just as the name implies, it is the rotation of the object, based around the origin of 0,0,0.

[This message has been edited by nexusone (edited 05-27-2003).]

Yeah, forget Maya.

The Personal Learning Edition saves meshes in a non-commercial file format. I’m not aware of any file format specification or available mesh loading code for those ‘special’ .mp files.

Also, if you’re just doing a cube, go ahead and put it in a display list and move on.

However, if you’re planning on more than just a very few (hardcoded) objects, use a free modelling package like anim8or and import the 3DS mesh as suggested.

If you really want to do run-time object creation, it seems to me that whatever vertex, material, texture values you hard-code, or load from your own text file, etc. would have no advantage over using a modelling program which makes changes very easy to make.

Unless I’ve misunderstood this whole thread of course…

Whoops, excuse me… I misunderstood the post.
And I still don’t understand.
Oh well, just forgot it.


by what type of operation glRotatef( ) is, I was asking what type of algorithm it uses…N, N^2, logN, etc.

thanks everyone for your help, I’ve pretty much got it down pat =).

You want to know the O of glRotate? It’s O(1) (Or whatever constant) There is basically just a single matrix multiplication.

Basically like so…
ROTATION_MATRIX = CreateMatrix(angle, x, y, z);

There’s no N involved, just a set number of operations.

[This message has been edited by Deiussum (edited 05-29-2003).]