TRANSLATE

Does anyone know if the gltranslate command would be faster than using an incremenation as such:

glBegin(GL_POLYGON);
glVertex3f(.482f + s, .490f + a, 0.0f);
glVertex3f(.485f + s, .499f + a, 0.0f);
glVertex3f(.485f + s, .490f + a, 0.0f);
glEnd();
glPopMatrix();

Experts always say that “Immediate Mode” (as you are using in your code) is only used for testing purposes.

Real Games and software either use Display Lists (where you can’t modify vertex arrays as they are saved to memory), or vertex arrays (where you can). *

So if you are want performance speed and you decide to use a display list, your subject it’s out of the question, since you can’t modify vertex data, you can just do matrix transformations (gltranslate, glscale, glrotate, etc).

If you instead decide display lists, then…
you must wait for another expert to answer other half of the question as I don’t know :stuck_out_tongue:

*There are now some more advanced methods such as Vertex Buffer, and such, but I would recommend to you start with Display Lists. Easy to use and fast.

I see nothing wrong in using immediate mode for simple things like sky etc.

Hovewer, as Rodrix pointed out, immediate mode is very slow. Translate (Rotate and such) are basically free, as they only modify the transformation matrix. Each vertex is being transformed by that matrix anyway, so you loose nothing. Using Translate is more convenient and less error-prone for small immediate mode batches. And using immediate mode for large models is a very bad idea.

Hence: stick to glTranslate :slight_smile:

I’m trying to get a charachter to move across the screen smoothly, I have specified the following: glTranslatef(s, a, 0); with s and a changing in very small increments. Now by using these small increments the charachter does move across the screen smoothly, however, it is a very ‘slow’ process. I need to speed up the rate of this charachters movement.

As both of you have suggested, I put the data segment involving the charachter and movement into a display list. Nonetheless, the charachter still moves across the screen slowly. Here is my DISPLAY LIST:

glNewList(1, GL_COMPILE_AND_EXECUTE);

glPolygonMode(GL_FRONT, GL_FILL);

glPushAttrib(GL_CURRENT_BIT);

//HEAD OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, .92, .92);

glBegin(GL_POLYGON);
glVertex3f(.47f, .48f , -0.15f);
glVertex3f(.47f, .50f , -0.15f);
glVertex3f(.485f, .50f , -0.15f);
glVertex3f(.485f, .49f , -0.15f);
glVertex3f(.489f, .49f , -0.15f);
glVertex3f(.489f, .488f , -0.150f);
glVertex3f(.485f, .488f , -0.150f);
glVertex3f(.485f, .478f , -0.150f);
glEnd();

glPopMatrix();

//EYE OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);

glBegin(GL_POLYGON);
glVertex3f(.480f , .490f , -0.150f);
glVertex3f(.485f , .499f , -0.150f);
glVertex3f(.485f , .490f , -0.150f);
glEnd();
glPopMatrix();

//MOUTH OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(0.65, 0.0, 0.0);

glBegin(GL_POLYGON);
glVertex3f(.482f , .480f , -0.150f);
glVertex3f(.482f , .482f , -0.150f);
glVertex3f(.485f , .482f , -0.150f);
glVertex3f(.485f , .480f , -0.150f);
glEnd();
glPopMatrix();

//HAIR OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(0.65, 0.50, 0.0);

glBegin(GL_POLYGON);
glVertex3f(.469f , .497f , -0.150f);
glVertex3f(.472f , .501f , -0.150f);
glVertex3f(.485f , .501f , -0.150f);
glVertex3f(.485f , .497f , -0.150f);
glVertex3f(.47f , .492f , -0.150f);
glEnd();
glPopMatrix();

//EAR OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(1.00, 0.75, 0.75);

glBegin(GL_POLYGON);
glVertex3f(.473f , .487f , -0.150f);
glVertex3f(.471f , .492f , -0.150f);
glVertex3f(.478f , .487f , -0.150f);
glEnd();
glPopMatrix();

//BODY OF MAIN CHARACHTER
glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(.40, 0.40, 0.40);

glBegin(GL_POLYGON);
glVertex3f(.470f , .455f , -0.150f);
glVertex3f(.470f , .479f , -0.150f);
glVertex3f(.485f , .479f , -0.150f);
glVertex3f(.485f , .455f , -0.150f);
glEnd();
glPopMatrix();

//LEGS OF MAIN CHARACHTER

glPushMatrix();
glTranslatef(s, a, 0);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3f(.40, 0.40, 0.40);

glBegin(GL_POLYGON);
glVertex3f(.471f , .445f , -0.150f);
glVertex3f(.471f , .455f , -0.150f);
glVertex3f(.484f , .455f , -0.150f);
glVertex3f(.484f , .445f , -0.150f);
glEnd();
glPopMatrix();

glPopAttrib();

glEndList();

I should note that the charachter is moving across a very large background texture. Maybe this is where the problem really is?

www.geocities.com/zadeh1979/grass3

FOr this case, because I have an animation, I shouldn’t be using Display lists?

Is Vertex Arrays what I have to use?

Wow! I guess you seriously missunderstand how GL works…

Ok, one after another…

First, you should compile your display list only once (in a setup stage) and execute it when you need to draw the character (via glCallList).

Second: why are you using this PushMatrix/translate…PopMatrix parts??? Would it be not much easier just to do PushMatrix/Translate only once and then render the whole character?

Third: why do you clear the depth buffer every 5 vertices??? This is probably the part where it goes so slow! Clearing operation is one of most expencive ones. If you don’t need depth buffer, just disable the depth test with glDisable(GL_DEPTH_TEST).

Fourth: if you can, render your whole character as one batch (this is, one call to glBegin…glEnd paradigm). I am shure you can split it into triangles or rects.

Ok, to sum it up, i propose you do this:

  1. Create a display list during a setup state (but after your context is valid!):

    glNewList(listId, GL_COMPILE);
    glBegin(…) render character glEnd()
    glEndList;

If you must, you can just use multiple begin…end parts as you have now. But please, please remove all clear, push pop and other calls from there!

  1. In your rendering loop you can then do

    glPushMatrix;
    glTranslate(…);
    glCallList(listid);
    glPopMatrix;

Thank you, I will try it and see what happens.

I fixed it up, but my charachter still moves across the screen slowly.

glNewList(1, GL_COMPILE);

glPolygonMode(GL_FRONT, GL_FILL);

glPushAttrib(GL_CURRENT_BIT);

//HEAD OF MAIN CHARACHTER
glColor3f(1.0, .92, .92);
glBegin(GL_POLYGON);
glVertex3f(.47f, .48f , -0.042f);
glVertex3f(.47f, .50f , -0.042f);
glVertex3f(.485f, .50f , -0.042f);
glVertex3f(.485f, .49f , -0.042f);
glVertex3f(.489f, .49f , -0.042f);
glVertex3f(.489f, .488f , -0.0420f);
glVertex3f(.485f, .488f , -0.0420f);
glVertex3f(.485f, .478f , -0.0420f);
glEnd();

//EYE OF MAIN CHARACHTER
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(.480f , .490f , -0.0420f);
glVertex3f(.485f , .499f , -0.0420f);
glVertex3f(.485f , .490f , -0.0420f);
glEnd();

//MOUTH OF MAIN CHARACHTER
glColor3f(0.65, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f(.482f , .480f , -0.0420f);
glVertex3f(.482f , .482f , -0.0420f);
glVertex3f(.485f , .482f , -0.0420f);
glVertex3f(.485f , .480f , -0.0420f);
glEnd();

//HAIR OF MAIN CHARACHTER
glColor3f(0.65, 0.50, 0.0);
glBegin(GL_POLYGON);
glVertex3f(.469f , .497f , -0.0420f);
glVertex3f(.472f , .501f , -0.0420f);
glVertex3f(.485f , .501f , -0.0420f);
glVertex3f(.485f , .497f , -0.0420f);
glVertex3f(.47f , .492f , -0.0420f);
glEnd();

//EAR OF MAIN CHARACHTER
glColor3f(1.00, 0.75, 0.75);
glBegin(GL_POLYGON);
glVertex3f(.473f , .487f , -0.0420f);
glVertex3f(.471f , .492f , -0.0420f);
glVertex3f(.478f , .487f , -0.0420f);
glEnd();

//BODY OF MAIN CHARACHTER
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.470f , .455f , -0.0420f);
glVertex3f(.470f , .479f , -0.0420f);
glVertex3f(.485f , .479f , -0.0420f);
glVertex3f(.485f , .455f , -0.0420f);
glEnd();

//LEGS OF MAIN CHARACHTER

if (l == 0)
{
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.471f , .445f , -0.0420f);
glVertex3f(.471f , .455f , -0.0420f);
glVertex3f(.484f , .455f , -0.0420f);
glVertex3f(.484f , .445f , -0.0420f);
glEnd();
}

if(l == 1)
{
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.468f , .443f , -0.0420f);
glVertex3f(.473f , .455f , -0.0420f);
glVertex3f(.477f , .453f , -0.0420f);
glVertex3f(.471f , .443f, -0.0420f);
glEnd();
}

glPopAttrib();

glEndList();

//CALL LIST
glPushMatrix;
glTranslatef(s, a, 0);
glCallList(1);
glPopMatrix;

try this for your translate call :slight_smile:

glTranslatef(4s, 4a, 0);

Could it be this 1MB image I am using a texture that is making the process slow?

www.geocities.com/zadeh1979/grass3

ZBuffer… Thank you for suggesting multiplying the s and a variables by a factor of 4. This helps get the charachter across the scene quickly, but not SMOOTHLY.

I want to keep the translation variables very small so it looks like the charachter is gliding across the screen through continious space (this is traditionally how it has been done in older adventure games for the nes/snes). But I want this to occur quickly as well. (Just like how a mouse pointer smoothly and rapidly moves across the screen).

I’m starting to think that the huge texture i’m using (1MB, posted above) for the background scene, is preventing faster execution of my animation, but I need someone who knows what they are doing to confirm this.

The texture size shouldn’t matter to the speed, unless it’s way to big or something like that, but 1 MB souldn’t be a problem.
But you could test with a lower size if you want (though i doubt that i will change anything).

Do you know exactly what your FPS is?
(you can use fraps to get the fps)

And finaly, what do the s and a variables contain?

I’VE PUT THE s and a variables in the SPECIAL KEYS FUNCTION. As keystrokes are registered, the values of s and a are incremented. Then with the translate command I substitute s and a, respectively for x and y. The translation operation is performed on the display list defining the charachter vertices.

void SpecialKeys(int key, int x, int y)
{
if (key == GLUT_KEY_RIGHT)
s = s - .004;

if (key == GLUT_KEY_LEFT)
s = s + .004;

if (key == GLUT_KEY_UP)
a = a + .004;

if (key == GLUT_KEY_DOWN)
a = a - .004;

glutPostRedisplay();
}

I just downloaded FRAPS and it’s estimating between 16-18 FPS !!

It’s not the texture either, I just switched to a 16 bit version of the image (it looks nasty), but this doesn’t change the frame rate. Hum, the only other thing i can think of is my video card. It’s a piece of junk Intel integrated 82945G.

Maybe I should have brought this up earlier, but im using OPENGL’s timer function that refreshes the screen every 1ms, I belive. Could this be acting as a limiting speed factor? If so, what should I do about it?

void TimerFunction(int value)
{
glutTimerFunc(1, TimerFunction, 1);
glutPostRedisplay();
}

In reply to a private message I pointed out that a timedelta might help smooth the translation over time :stuck_out_tongue:

Glut is not part of OpenGL, but you can find the documentation for it here:
http://www.opengl.org/documentation/specs/glut/spec3/spec3.html

Hope this helps.

Just to be sure, you mention a 1mb texture, you don’t upload it for each frame right ?

Actually…

void RenderScene(void)
{

GLuint texture = 0;

glbmp_t bitmap;

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glbmp_LoadBitmap(“grass2.bmp”, 1, &bitmap);

//generate and bind the OpenGL texture
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);

//copy data from bitmap into texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glViewport(0, 0, 1024, 1024);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(85.0, 1.0, -5.0, 0.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(.50 , .52 , -.05, 0.50 , 0.52 , 0.0, 0.0, 10.0, 0.0);

glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);

glShadeModel(GL_SMOOTH);

glFrontFace(GL_CCW);
//glEnable(GL_CULL_FACE);

glBegin(GL_QUAD_STRIP);

glTexCoord2f(1.0, 0.0);
glVertex3f(1.0f, 0.0f, 0.0f);

glTexCoord2f(1.0, 1.0);
glVertex3f(1.0f, 1.0f, 0.0f);

glTexCoord2f(0.0, 0.0);
glVertex3f(0.0f, 0.0f, 0.0f);

glTexCoord2f(0.0, 1.0);
glVertex3f(0.0f, 1.0f, 0.0f);

glEnd();

glDeleteTextures(1, &texture);
glbmp_FreeBitmap(&bitmap);

YES, THAT WAS IT!! I was reloading the texture on every single loop. THANK YOU Zbuffer, And everyone else who helped!

Now it’s so fast, I have to slow it down! :slight_smile: