Hi, i’m new to this forum. The main reason is that i need help solving a problem i have in my app, but i hope i can help other people too with their probs.
Here is mine:
I have coded an app in windows that uses glut for window managing. The app has the option to (de)activate textures at runtime pressing a button. There are only 4 textures im using:
- grass : a 512x512 bitmap image
- water: a 256x256 bitmap image
- shark skin: 2 TGA images at 64x64
The problem as the title states is that textures deactivated i have 64 fps but whenever i activate textures fps drops to 7-9 fps!!
A friend of mine told me it might have to be related to doing several texture bindings in the rendering function. But i can’t believe that the use of so low number (4) of separate textures (not in an atlas) isnt supported!!
I’ll post some code, ive followed the example that comes in the red book:
void IniciarWaterRunning(TTextura *tex)
{
TexturaBMPCargar("res/texturas/water.bmp", tex);
glGenTextures( 1 , &tex->tex_Id);
glBindTexture(GL_TEXTURE_2D, tex->tex_Id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, tex->formato,
tex->ancho, tex->largo, 0,
tex->formato, GL_UNSIGNED_BYTE,
tex->img_data);
}
void FinalizarWaterRunning(TTextura *tex)
{
free(tex->img_data);
glDeleteTextures(1, &tex->tex_Id);
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
alutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(100, 100);
glutCreateWindow("myapp");
inicializar();
IniciarWaterRunning(&tex_agua); /
IniciarRocas(&tex_suelo);
glutReshapeFunc(visualReshape);
glutDisplayFunc(visualRendering);
glutFullScreen();
glutSpecialFunc(teclasEspeciales);
glutKeyboardFunc(teclado);
glutMouseFunc(raton);
glutMotionFunc(motion);
glutMainLoop();
//finaliza el contexto de dispositivo de Audio
alutExit();
FinalizarWaterRunning(&tex_agua);
FinalizarRocas(&tex_suelo);
FinalizarAudioModelo(audio);
finalizar();
}
Following here are several rendering functions that are called in the main rendering function.
void DrawWaterRunning(/*some parameters here*/)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if(control->texturas == VERDADERO)
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, tex_agua.tex_Id);
.
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_POLYGON);//plano Zmax
glColor4f(1,1,1,0.4f);
glTexCoord2f( 0, 0 + offset_agua);
glVertex3f(recinto->min[X], recinto->min[Y], recinto->max[Z]);
glTexCoord2f( 5, 0 + offset_agua);
glVertex3f(recinto->max[X], recinto->min[Y], recinto->max[Z]);
glTexCoord2f( 5, 2 + offset_agua);
glVertex3f(recinto->max[X], recinto->max[Y], recinto->max[Z]);
glTexCoord2f( 0, 2 + offset_agua);
glVertex3f(recinto->min[X], recinto->max[Y], recinto->max[Z]);
glEnd();
glBegin(GL_POLYGON); //plano Xmax
glColor4f(1,1,1,0.4f);
glTexCoord2f( 0, 0 + offset_agua);
glVertex3f(recinto->max[X], recinto->min[Y], recinto->min[Z]);
glTexCoord2f( 5, 0 + offset_agua);
glVertex3f(recinto->max[X], recinto->min[Y], recinto->max[Z]);
glTexCoord2f( 5, 2 + offset_agua);
glVertex3f(recinto->max[X], recinto->max[Y], recinto->max[Z]);
glTexCoord2f( 0, 2 + offset_agua);
glVertex3f(recinto->max[X], recinto->max[Y], recinto->min[Z]);
glEnd();
glBegin(GL_POLYGON); //plano Zmin
glColor4f(1,1,1,0.4f);
glTexCoord2f( 0, 0 + offset_agua);
glVertex3f(recinto->min[X], recinto->min[Y], recinto->min[Z]);
glTexCoord2f( 5, 0 + offset_agua);
glVertex3f(recinto->max[X], recinto->min[Y], recinto->min[Z]);
glTexCoord2f( 5, 2 + offset_agua);
glVertex3f(recinto->max[X], recinto->max[Y], recinto->min[Z]);
glTexCoord2f( 0, 2 + offset_agua);
glVertex3f(recinto->min[X], recinto->max[Y], recinto->min[Z]);
glEnd();
glBegin(GL_POLYGON); //plano Xmin
glColor4f(1,1,1,0.4f);
glTexCoord2f( 0, 0 + offset_agua);
glVertex3f(recinto->min[X], recinto->min[Y], recinto->min[Z]);
glTexCoord2f( 5, 0 + offset_agua);
glVertex3f(recinto->min[X], recinto->min[Y], recinto->max[Z]);
glTexCoord2f( 5, 2 + offset_agua);
glVertex3f(recinto->min[X], recinto->max[Y], recinto->max[Z]);
glTexCoord2f( 0, 2 + offset_agua);
glVertex3f(recinto->min[X], recinto->max[Y], recinto->min[Z]);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
glPopMatrix();
}
In the next function i do several bindings for the same model.
DrawModel(/**/)
{
(.....)
if (activar_texturas == VERDADERO)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, loco->stexturas.texturas[0].tex_Id);
}
glBegin(GL_POLYGON);
glNormal3f( 0,-1, 1); glTexCoord2f(0.5, 0); glVertex3f( 0.5,-1.5, 1.5); //0
glNormal3f( 0,-1, 1); glTexCoord2f( 0, 0); glVertex3f(-0.5,-1.5, 1.5); //1
glNormal3f( 0, 1, 1); glTexCoord2f( 0,0.5); glVertex3f(-0.5, 1.5, 1.5); //3
glNormal3f( 0, 1, 1); glTexCoord2f(0.5, 0.5); glVertex3f( 0.5, 1.5, 1.5); //2
glEnd();
glBegin(GL_POLYGON);
glNormal3f( 0, 1,-1); glTexCoord2f( 0,0.5); glVertex3f(-0.5, 1.5,-1.5); //5
glNormal3f( 0, 1,-1); glTexCoord2f(0.5, 0.5); glVertex3f( 0.5, 1.5,-1.5); //4
glNormal3f( 0,-1,-1); glTexCoord2f(0.5, 0); glVertex3f( 0.5,-1.5,-1.5); //6
glNormal3f( 0,-1,-1); glTexCoord2f( 0, 0); glVertex3f(-0.5,-1.5,-1.5); //7
glEnd();
if (activar_texturas == VERDADERO)
glBindTexture(GL_TEXTURE_2D, loco->stexturas.texturas[1].tex_Id);
glBegin(GL_POLYGON);
glNormal3f( 0, 1, 1); glTexCoord2f( 0.2F, 0); glVertex3f( 0.5, 1.5, 1.5); //2
glNormal3f( 0, 1, 1); glTexCoord2f( 0, 0); glVertex3f(-0.5, 1.5, 1.5); //3
glNormal3f( 0, 1,-1); glTexCoord2f( 0, 1); glVertex3f(-0.5, 1.5,-1.5); //5
glNormal3f( 0, 1,-1); glTexCoord2f( 0.2F, 1); glVertex3f( 0.5, 1.5,-1.5); //4
glEnd();
(.........)
}
You can see that i do the binding once when i load the texture in the init function and i bind again each time i need to draw the polygon with the texture. I thought this was the right way to do it.
If someone can shed a light over here i d appreciate it very much!! T
Thanks in advance.