PDA

View Full Version : White textures if don't use mipmapping...



architekt
08-03-2002, 09:09 PM
For some reason, if I use mipmapping, I can see my textures, but if I don't use mipmapping, they all show up white. Here's the code I used to display them using mipmapping:

glGenTextures(1, &tex_id);
glBindTexture(GL_TEXTURE_2D, tex_id);
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);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, tile_width, tile_height, GL_RGBA, GL_UNSIGNED_BYTE, gfx_data);

If I replace that last line with the following:

glTexImage2D(GL_TEXTURE_2D, 0, 4, tile_width, tile_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, gfx_data);

Then all my images appear white. Any clue as to what I'm doing wrong? Thanks for your help.

SirKnight
08-03-2002, 09:22 PM
I noticed that you have the line "glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);" before gluBulit2DMipmaps yet you already defined the texture wrap s before as repeat. Why are you now saying texture wrap s is clamp? Also in yout glTexImage2D call you have '4' as the third parameter. You should have GL_RGBA since its obvious that's what you are using in your program. GL_RGBA is not 4. GL_RGBA = 0x1908

Maybe this will help some?

-SirKnight

architekt
08-03-2002, 09:32 PM
unfortunately, that still shows white textures. I got rid of the GL_REPEAT lines and replaced them with GL_CLAMP also.

Catz
08-03-2002, 11:59 PM
gluBuildMipmaps takes care of irregularly sized textures. I can't remember if you must specify images with width and height being a power-of-2 or multiple-of-2 to glTexImage. Check to see if your source images have a width or height of an odd number, or non-power-of-2. I'm pretty confident that's where your problem lies.

kevinhoque
08-04-2002, 03:12 AM
SirKnight, I don't know if you are aware but the online help that comes with VC++ 6.0 is only opengl 1.0 complient. i.e.

void glTexImage2D(
GLenum target,
GLint level,
GLint components,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels
);

Parameters
target
The target texture. Must be GL_TEXTURE_2D.
level
The level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
components
The number of color components in the texture. Must be 1, 2, 3, or 4.

etc...

As can be seen, this is a legacy function definition. The current function has the same signature and so hence the confusion.

architekt, try to get yourself an up-to-date OpenGL programming textbook and don't use MSDN that comes with VC6 if that is in fact what you are doing. Alternatively, use the online version of msdn
http://msdn.microsoft.com/

as this is more up-to-date and the basic opengl functions are listed and explained correctly.

Good luck

evanGLizr
08-04-2002, 06:03 AM
Originally posted by architekt:
For some reason, if I use mipmapping, I can see my textures, but if I don't use mipmapping, they all show up white

If your texture state is inconsistent (i.e. you use a texture which is not complete for the current texture setup), OpenGL mandates to disable texturing, which is what you are getting (white rendering).

The most common error is to set a texture filter which requires mipmaps (i.e, setting GL_TEXTURE_MIN_FILTER to something different to GL_LINEAR or GL_NEAREST), but not providing the texture image for all the mipmap levels.

In the snippet you posted, the filter setup doesn't require mipmaps:

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

So unless you are modifying the TEXTURE_MIN_FILTER elsewhere to force to use mipmaps, I cannot see anything wrong there.

Check for opengl errors after each call (glGetError), and check that tile_width and tile_height are powers of two (unless you use borders, in which case they should be powers of two + 2).

V-man
08-04-2002, 07:49 AM
Originally posted by kevinhoque:
SirKnight, I don't know if you are aware but the online help that comes with VC++ 6.0 is only opengl 1.0 complient. i.e.


Nope, it is 1.1 since the gl version that comes with windows is 1.1, plus there are a few mistakes in there.

There is nothing wrong with giving 4 as the components number. If you have an RGBA8888 image, you can either pass 4 or GL_RGBA or GL_RGBA888.

If the driver raises an error flag for 4, then it is a bug.

V-man

jwatte
08-04-2002, 08:31 AM
If MIP mapping is on, but all texture levels are not correctly specified, the texture is not mipmap complete and GL behaves as if texturing is disabled. It's in the spec.

I suggest setting TexParameter MIN_FILTER to LINEAR if you don't build all mipmap images.

architekt
08-04-2002, 12:11 PM
It was the power of 2 issue. I forgot that my tile height was 31, not 32. Thanks for your help =)

architekt
08-04-2002, 12:17 PM
But on that note...is there any way to use a non power of 2 texture without distorting it? I assume mipmapping is the only answer, but can you use mipmapping without distortion? Every time I've tried it my image looks slightly different than what it should look like, but if I don't use mipmapping and have a power of 2 texture things look fine.

SirKnight
08-04-2002, 02:21 PM
There is nothing wrong with giving 4 as the components number. If you have an RGBA8888 image, you can either pass 4 or GL_RGBA or GL_RGBA888.


Oh I see, I was not aware of that. Doh! Well sorry about that. http://www.opengl.org/discussion_boards/ubb/smile.gif

-SirKnight

knackered
08-04-2002, 02:21 PM
This extension:-
http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_rectangle.txt

I was unaware that the glu mip map generator scales your input texture to pow2....weird, it should just throw an error.

SirKnight
08-04-2002, 02:22 PM
Oh also, good to hear it's working now! I didn't even think of the power of 2 thing. I just figured that your textures had the correct dimensions. I guess that's what I get for assuming. http://www.opengl.org/discussion_boards/ubb/wink.gif

-SirKnight

kevinhoque
08-04-2002, 03:36 PM
V-man I had some problems a while back with the legacy numeric values with up-to-date nvidia drivers. I find that it's safer to use the symbolic constants. As to whether the docs are 1.1 or 1.0 don't want to argue with you there. The runtime is definitely 1.1 and so are the headers and libraries - not sure that the docs are quite this up-to-date though. The doc's explanation of glTextImage2D is 1.0 *not* 1.1. [Although that could just be another mistake on microsoft's part.] Still, I think the rule of thumb is not to rely on the docs that come with VC6. The docs that come with the new Win32 platform SDK are much more reliable as are those on microsoft's website. Better still, use the official guide. :-)

jwatte
08-04-2002, 07:22 PM
You can use non-power-of-two images with no need for extensions or scaling, as long as you don't need texture coordinate clamp or repeat.

Figure out which power of 2 is greater than the size of your texture dimension, and make the texture that size using TexImage. The load the lower left corner of the texture with your data using TexSubImage. Scale your texture coordinates appropriately. Done.

knackered
08-04-2002, 11:48 PM
Texture memory is not cheap - don't waste it in this way.

V-man
08-05-2002, 08:45 AM
Originally posted by knackered:
This extension:-
http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_rectangle.txt

I was unaware that the glu mip map generator scales your input texture to pow2....weird, it should just throw an error.

That extension sucks for doing texturing (lack of mipmap support, and a couple of other things).
It is better to apply a correction transform to the texture matrix, or deal with the texcoords (and vertices to). The later can be messy.

PS: gluBuild2DMipmaps should let us control if we want to scale up or scale down. We might want 250 to become 128 or 256, for example.

V-man

knackered
08-05-2002, 11:37 AM
Originally posted by V-man:
That extension sucks for doing texturing (lack of mipmap support, and a couple of other things).
It is better to apply a correction transform to the texture matrix, or deal with the texcoords (and vertices to). The later can be messy.

Mmm, you obviously have far more texture memory than you know what to do with, vman.
The texture rectangle extension has its uses, believe me (nvidia tend not to produce extensions that 'suck'). It doesn't sound like it will be particularly useful to this guy, though - he should simply scale his textures to be pow2 before importing them...it really isn't difficult using something like paint shop pro, photoshop or even imagerobot (if there's loads of textures to be done).