PDA

View Full Version : Using Texture Objects



ksanim
05-05-2001, 05:06 PM
I'm having difficulty accessing a texture object. When I choose a texture object that's already been bound, the texture isn't being activated and utilized by the texture mapping functions that follow.Here's a sample of my code.
//initialization
//generate object IDs
GLuint textures[4]
glGenTextures(4,textures);

//Set properties of texture object
glBindTexture(GL_TEXTURE_2D,textures[0]);

glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );

glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPM AP_NEAREST );

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

gluBuild2DMipmaps( GL_TEXTURE_2D, 3,
m_pRGBImage->sizeX, m_pRGBImage->sizeY,
GL_RGB, GL_UNSIGNED_BYTE, m_pRGBImage->data );

If you're wondering, m_pRGBImage is a pointer to the bitmap data. I know that's not the problem because I can create mipmaps with this code. It's the texture objects that don't work.

Afterwards I tried to access this bitmap as follows.

//call texture object already bound
glBindTexture(GL_TEXTURE_2D,textures[0]);

I expected this code to work, but my functions for mapping textures to curves that followed didn't use a texture. Can anyone tell me what I'm doing wrong?

thanks.

Korval
05-05-2001, 05:15 PM
Did you glEnable(GL_TEXTURE_2D)? Does the code work without binding texture objects?

ksanim
05-05-2001, 05:19 PM
Yes. It works without binding texture objects. I know I have the capability of using texture objects since I'm runnig 1.1.

hjhhk
05-06-2001, 05:32 PM
If your application is running on Windows, the pixelmap array must be bounded as 4bytes. Also it is safe that the bitmap has a size of powers of 2, though you use gluBuild2DMipmaps().

hjhhk.mytripod.co.kr

Sheepie
05-07-2001, 12:15 AM
I don't know if you simply copied and pasted the code, is it possible that the-

GLuint textures[4]

is declared in the Function as opposed to globally?

It's late here and the code looks good otherwise, and that is the only thing you are having the problem with. I've made similar mistakes. :P

ksanim
05-07-2001, 08:04 AM
Sheepie,

That's what I thought as well, but that array is declared only once, as a global.

Hjhhk,

The byte alignment doesn't seem to be the problem. I can use textures with the 1 byte alignment, I just can't bind them. I did try using the 4 byte alignment, but to no avail.

DaViper
05-08-2001, 12:17 AM
My best guess is that you have to set the TexParameter again after the new Bind call, I am not sure right now what the default values are...

I had this problem once and setting the Texparameter again helped

Chris

NeoTuri
05-08-2001, 12:54 PM
I've never had to change my glTexParameter values after a call to gluBuildMipmaps2D or glTexImage2D() on a bound texture object.

The only diff in code that I can see is that glPixelStorei() call. It's been my general habit to keep my textures at least on a 4-byte alignment to avoid any trivial problems (with drivers or the like).

Maybe it may be something else that is between the initialization and the first use of the texture object that's causing the problem?

DaViper
05-09-2001, 02:49 AM
Originally posted by NeoTuri:
I've never had to change my glTexParameter values after a call to gluBuildMipmaps2D or glTexImage2D() on a bound texture object.

I not talking of bound Textur, I am talking of rebinding. You obviously don't have to set your TexParamter for a bound Textur more than once.

Chris

NeoTuri
05-09-2001, 04:13 AM
Have you considered destroying that specific texture object and reallocating it?

Sheepie
05-09-2001, 11:43 PM
Now that I think of it, I ran into a very similar problem with the Model Editor I am making. When I Generated textures originally, they would not bind correctly. I found that by doing a-

if glIsTexture(texture)
glDeleteTextures(size,texture)

before call glGenTexture, the code worked like a charm.

The only reason I can imagine that this happens is that possibly OpenGL never removed the texture references or something along those lines. I did delete the textures before exiting the program but the above was still required.

On a sidenote, this also happened with my Display Lists.

This is possibly what NeoTuri was hinting at in his post. I apologize that I didn't remember this before I posted last time. http://www.opengl.org/discussion_boards/ubb/frown.gif

tbhall
10-09-2001, 04:03 AM
I'm having a similar problem... actually. Just posted a new note to the list then found this.

Just to clarify, it seems like you're saying that we have to manually delete the texture objects before you exit? Is this good practice, or does not deleting them actually cause problems?

I have a rather similar problem even the 1st time I run the program after a fresh reboot.

Brett

tbhall
10-09-2001, 04:07 AM
Oh, whoops one more thing. Someone mentioned the 4-byte alignment thing, is this driver dependent or hardware dependent?

I'm also using RGB not RGBA but haven't implemented Alpha yet in my application. I wonder if that will fix it. The strange thing is that I only have the problem with binding in my MFC code, the W32 code for my previous version worked great on the same hardware/driver setup...

Thanks
Brett