Not rendering very fast....

I have a 2D program that I made to practice with file programing. Everthing works fine, but it renders at less than 1 frame per second. I wanted to see where it was slowing down, so I wrote my own profiler. Its not the most accurate thing, but I am sure it is the actuall drawing code slowing it down. I have 2 triangels that make up a square in a call list. I use the call list to draw a 10*10 grid with different textures. So, the call list is called a total of 100 times per frame, which takes over a second. Any ideas why its drawing so slow?? I’m programming on a 300Mhz AMD, so I wasn’t expecting much but with 2d graphics it should be at least 30 frames a second I would think. I’m using borland if that makes a difference. thx

Try to use double buffering,
example :


PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER|
PFD_TYPE_RGBA,

Had that problem as well. I found out, that it’s the texture switching. Load all textures into the video buffer first and refer to them by names, instead of sending a new texture to the video buffer and dropping the old for every polygon.

GLuint textures[100];

glGenTextures(100,textures);
for (int i = 0;i < 100;i++) {
glBindTexture(GL_TEXTURE_2D,textures[i]);
glTexImage2D( /* define texture image here / );
/
specify parameters and other texture properties here */
}

Then just switch the texture by glBindTexture() when rendering the scene.

[This message has been edited by mm_freak (edited 11-10-2002).]

Thank you both, but neither one was the problem. I already have double buffering on. I was loading all my textures at startup and just rebinding it when I was changing textures. If no one else has any ideas, I’ll just chalk it up to a really slow onboard video card. On my 1.4Ghz with a G-force 3, the whole thing was rendering like several hundred times a second. Part of the problem might be my profiler too. I think it is measuring CPU time not actual time. Does anyone know how to access system time down to the millisecond?

To test the speed of a certain routine, I would get the number of milliseconds elapsed since the system was started (GetTickCount() under Win32: DWORD GetTickCount(void)). After the routine, get the milliseconds again and from that subtract the older value and you’ll have the time elapsed. Note that even this way could be inaccurate (system-dependent), but the result accuracy should be something around 20 to 40 ms.

DWORD etm;

etm = GetTickCount();
/* draw here */
etm = GetTickCount() - etm;
printf("Time elapsed: %lu ms
",etm);

I rewrote my profiler using a different method than you sugested. I used QueryPreformanceCounter(). It seems to be very accurate. I found out that the SwapBuffers(ghDC) is taking .4 seconds and

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1,-1,0);
for(int i=0; i&lt;10;i++)
{
    for(int j=0; j&lt;10; j++)
    {
            glPushMatrix();
            glBindTexture(GL_TEXTURE_2D, texture[screenb[(10*i)+j]]);
            glTranslatef(.2*j,.2*i,0);
            glCallList(boxlist);
            glPopMatrix();
    }
}

is taking .6 seconds. Anyone know why this is taking so long? Especially the SwapBuffers, which is completely taken care of by opengl. Thx