PDA

View Full Version : What's wrong with the texture ??



08-04-2004, 06:20 AM
Hello!

Maybe I am weird - I just can't find a mistake in this code. I'd like to create a texture out of textureData. Suprisingly, when I bind it no texture seems to be applied.


GLubyte TextureData[32][32][3];

for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
TextureData[i][j][0] = 0;
TextureData[i][j][1] = 255;
TextureData[i][j][2] = 0;
}
}

glGenTextures(1, &amp;m_pTexture[0].m_ID)

glBindTexture(GL_TEXTURE_2D, m_pTexture[0].m_ID);

glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, &amp;TextureData[0][0][0]);I would be thankful for your help! Thanks in advance ...

Bob
08-04-2004, 06:53 AM
The default minification filter requires a complete mipmap set, or the texture is considered invalid. Either set the minification filter to a non-mipmap filter, or upload a complete mipmap set (all mipmap level down to 1x1).

08-04-2004, 08:38 AM
Actually, I use a non-mipmap filtering.


// Minification function
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_NEAREST);

// Magnification function
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_NEAREST);What can be wrong then ??

Thanks

dvm
08-04-2004, 12:50 PM
Maybe you should try to play with the parameters of glTexImage2D. Specifically, the type and format parameters. Usually you could have some trouble loading the data into memory properly. While trying out various combinations you will probably get access violation errors, so you could include it in a try catch block as well. In my case almost 100% of the cases where a program was running correctly but the texture was not displaying was improper setting of the above parameters. Also try to do a debug run and see if by the time you're about to call glTexImage2D the pointer to the data is valid (maybe you don't load the file properly). Hope it helped!

plasmonster
08-04-2004, 01:43 PM
Suprisingly, when I bind it no texture seems to be applied.What exactly do you mean by this? Image specification is but one step of the process.

08-04-2004, 09:37 PM
Perhaps he doesnt have a valid RC at that time.
Anyway placing some glGetError() calls wont hurt.

Sumpfratte
08-04-2004, 11:33 PM
I'm not sure, but why do you use 3 for the internal format of glTexImage2D?
If I look at gl.h, 3 stands for GL_LINE_STRIP ("#define GL_LINE_STRIP 0x0003")
Use instead GL_RGB, I think that is what you want.

And I hope you have not forget glEnable(GL_TEXTURE_2D); ;)

plasmonster
08-05-2004, 12:41 AM
I'm not sure, but why do you use 3 for the internal format of glTexImage2D?The GL understands that 3 is the number of components (GL_RGB would work too). You can use 1, 2, 3 or 4.

08-05-2004, 01:06 AM
Originally posted by Q:
What exactly do you mean by this? Image specification is but one step of the process.[/QB]Simply nothing happens. I got only a nasty-white non-texturized triangle. :)

I definately have a valid RC then. Hmmm... Yup, I can try glGetError(). Maybe I'll find something. Anyway, I was debbuging the app and everything seemed to be correct.

Thanks for you replies! :)

08-05-2004, 01:30 AM
GL_NO_ERROR is returned. What's more I am 100% sure that a right texture ID is used. No way I could mistake something like texture coordinates assingment - although, I'll check it. :]

08-05-2004, 02:04 AM
OK. I got it. Look at the following code :

Wrong :

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glBindTexture(GL_TEXTURE_2D, m_pTexture[0].m_ID);Right :

glBindTexture(GL_TEXTURE_2D, m_pTexture[0].m_ID);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);I am really confused. I thought that texture filters are stored rather as global state variables. From the code above it appears that each texture binding changes a filtering. Am I right?

ZbuffeR
08-05-2004, 08:44 AM
glTexParameter and glTexEnv are applied to current texture, and even to current texture unit if you use multitexture.

Relic
08-05-2004, 10:06 PM
Not quite.
TexParameter are part of texture objects (wrap modes, filer mode, priority, border color, etc.). There exists an immediate mode texture object, the one with id 0, which gets these parameters if you didn't call BindTexture before. Look up the specs.
If you call BindTexture all the parameters set for that object are restored automatically. No need to call TexParameter again.
The pitfall here is that there are also defaults and the critical is the min filter which defaults to GL_LINEAR_MIPMAP_NEAREST and needs a full mipmap chain to make the texture object consistent. Binding inconsistent texture objects disables the texture unit.