Sorry about the lenght of this post…
I wrote a class that is supposed to display outline, texture mapped fonts (using standard procedures for doing so on Win platform).
I’m working on a simple game engine.
Let’s say I have a simple class called CTestCube. In the constructor, I have this code: ( I have a class CTexture working ok)
cubeTexture[0].LoadTexture(“Me.tga”); //.bmp file loading seems to be ****ed…!
glGenTextures(1, &cubeTexture[0].texID);
glBindTexture(GL_TEXTURE_2D, cubeTexture[0].texID);
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_T, GL_REPEAT);
Then, in the OnDraw() of this cube, I have:
glBindTexture(GL_TEXTURE_2D, cubeTexture[0].texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, cubeTexture[0].width, cubeTexture[0].height, 0, GL_RGB, GL_UNSIGNED_BYTE, cubeTexture[0].data);
before passing in to the OpenGl.
This all renders quite fast.
Now, for my outline fonts class, I 've placed everything in the OnDraw() function, which in part looks like this:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); // use bilinear filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // repeat texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texture->width, texture->height, GL_RGB, GL_UNSIGNED_BYTE, texture->data);
// we want OpenGL to automatically generate the texture coordinates for the text
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
This is called every frame…
Ok, so my problems are:
-
This slows the display to crawl… obviously I’m doing something wrong here…
So, basically, where is the proper placement in terms of OnDraw() and constructor, of commands, such as :
gluBuild2DMipmaps
glTexParameteri
glBindTexture
glGenTextures
which can be called at the beginning and which need to be called everyframe (assuming that every object will have a difference texture (and every object has a pointer to CTexture). -
When the fonts gets rendered, they change all the texturing of my other objects… what is the proper way in terms of good OO design to fix this? Call glPushAttrib(GL_TEXTURE_BIT) before foing the glBindTesture/glGenTextures/glTexParameteri?
Thank you for your help,
Luke