PDA

View Full Version : Texturing Problem



qwert
09-18-2001, 05:29 AM
Hi all,

I'm working with MFC and have got a dialog box: in the "OnInitDialog" I load my texture up like this:
glEnable(GL_TEXTURE_2D);

memset(TextureImage,0,sizeof(void *)*1);

if (TextureImage=LoadBMP("toltex.bmp"))
{
glGenTextures(1, &m_textureID);
glBindTexture(GL_TEXTURE_2D, m_textureID);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
}

In the "OnRender"-Function I set up the texture:
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, m_textureID);


Of course, for the triangles I define the Texcoords... http://www.opengl.org/discussion_boards/ubb/smile.gif
So now, this way nothing happen. My object appears untextured. But if I put the first (and expensive) loading-code in the render-function, the texturing works... Any ideas?

qwert

dantas
09-18-2001, 07:59 AM
I do the same thing, but I have the glTexEnvf call in the initialization and it works fine. I believe you need to define the ENV_MODE (and COLOR) before you call the glTexImage2D function.

qwert
09-18-2001, 09:11 PM
I put the env-mode as you said (With Color you mean the vertexcolor? Yes, I set that before), but nothing changed... http://www.opengl.org/discussion_boards/ubb/frown.gif

It seems as he would lose the texture somehow. With my win32-app at home it wrks fine, too. It seems as MFC causes this problem, but that's also strange. I thought MFC doesn't influence OpenGL. Any Guess?

qwert
09-18-2001, 10:20 PM
Maybe this could be a hint, it seems strange to me, but I don't know how to interprete this:

After calling "glGenTextures(1, &m_texture[0]);", the m_texture[0] (I changed the name) contains "3452816845". When I let running a working demo from nehe's page, his texture-varaible contains "1".
Does this mean, that he couldn't find a place in memory to store my texture?

Bob
09-18-2001, 10:27 PM
Theoretically, 3452816845 should be a perfectly valid texture ID. Only 0 is an invalid texture ID. But if you throw that number into a decimal-to-hexadecimal converter, you will see that the hexadecimal version of that number is 0xCDCDCDCD. Makes me believe that the variable is still unchanged (some compilers fill uninitialized variables with a bit pattern for easy recognition of uninitialized variables when debugging). This, in turn, makes me believe you are asking for a texture ID before you have a valid rendering context. Without context, OpenGL functions do nothing.

qwert
09-18-2001, 10:30 PM
Yes, you're right Bob. I loaded the "LoadTexture" too soon. Thanks for your help.

qwert