slow code

i display some cubes on the screen, then i display some text and then some cubes again and it gets very slow, i tried using glFlush(); to fix this but it didnt work, also while runing the program and if i move the window it displasys the previus scenes like if was still drawing them but the next scene just gets on top of it

Hi !

Maybe you could post the rendering code here, it is difficult to say what could be wrong without looking at it, glClear() is used to erase the old contents of the buffers, make sure you call this before you start to render each frame.

Mikael

int Scena1(int duracion) //araña roja
{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glPushMatrix();			
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glShadeModel(GL_SMOOTH);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);	
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
		glLoadIdentity();									
		
		glColor3f(rojo,0.0f,0.0f);
		glTranslatef(-0.5f,-0.5f,closer);
		glDepthMask(GL_FALSE);
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glBegin(GL_QUADS);
			glTexCoord2f( 0.0f, 1.0f);	glVertex2f( 0.0f, 1.0);
			glTexCoord2f( 1.0f, 1.0f);	glVertex2f( 1.0  , 1.0); 
			glTexCoord2f( 1.0f, 0.0f);	glVertex2f( 1.0  , 0.0f);
			glTexCoord2f( 0.0f, 0.0f);	glVertex2f( 0.0f, 0.0f);
		glEnd();
		glDepthMask(GL_TRUE);
		glDisable(GL_TEXTURE_2D);
		rojo+=0.05/8;
		glPopMatrix();			
	
		if(tiempo>=Escena1+7000) 
			closer-=(5.0f/32)/2;

	if(tiempo>=duracion)
	{
		glFlush();
		return 0;
	}
	
}
int Scena2(int duracion)// cubo con carros. texturas->>araña ka pointer c2 tbird tsuru
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();									
	glPushMatrix();			
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glShadeModel(GL_SMOOTH);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();									
	glColor3f(1.0f,1.0f,1.0f);
	glTranslatef(0.0f,0.0f,-5.0f);
	glRotatef(xrot,1.0f,0.0f,0.0f);
	glRotatef(yrot,0.0f,1.0f,0.0f);
	glRotatef(zrot,0.0f,0.0f,1.0f);
	glDepthMask(GL_FALSE);
	
	glBindTexture(GL_TEXTURE_2D, texture[1]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texture[2]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
	glEnd();
		
	glBindTexture(GL_TEXTURE_2D, texture[3]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
	glEnd();
	
	glBindTexture(GL_TEXTURE_2D, texture[4]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
	glEnd();
		
	glBindTexture(GL_TEXTURE_2D, texture[5]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
	glEnd();
	
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
	glEnd();

	glDepthMask(GL_TRUE);
	glDisable(GL_TEXTURE_2D);
	glFlush();
	glPopMatrix();
	glFlush();
	if(tiempo>=duracion)
	{
		glFlush();
		return 0;
	}
}

those are two scenes i know they are not optimized or anything but thats because im a newbie

Are you using a double buffered GL window?

If not, try calling glFinish() after all rendering for 1 frame is done.

Nico

What is the above code that is calling your 2 functions ? You talk about displaying text, either I don’t see any text output code here (I may look too fast however).

At a glance…

*You have a redundant Clear() in each function.

*The LoadIdentity() call before PushMatrix() is questionable.

Your problem is probably in another function, as jide pointed out.

im sorry for the text output, that its because its another scene, im calling those scenes using

 int DrawGLScene(GLvoid)
{
	if(tiempo>=Escena1)
		Scena1(10000);	
	if(tiempo>=Escena2)
		Scena2(22000);
	if(tiempo>=Escena3)
		Scena3(118000);
	
	if(tiempo>=Escena4)
		Scena4(600000);
	fin = GetTickCount();
	tiempo = (fin - inicio);
	z+=2;
	xrot+=0.6f;
	yrot+=0.4f;
	zrot+=0.8f;
	return TRUE;						
} 

in your drawglscene func the time variable is constantly raised

however you only check if teh time is greater than a value when you call the drawfuncs.
that means that once time is above e.g. “Escena2”, you are also above “Escena1”, thats why you end up drawing all scenes on top of each other

a fix would be revert those if’s and make them else if.
e.g

if (tiempo>=Escena4)…
else if (tiempo >= Escena3) …
else if …

I think it would be good to put the glClear call in the DrawGLScene instead to avoid any problems.
Same thing with the glFlush/glFinish.

Mikael

hey crazy butcher thanks a lot, that was it, million thanks