View Full Version : Questions about gltexImage2D()
02-11-2007, 12:27 AM
I use 24 or 32 bits targa images in my app and I load each component of the image( R As an example ) in a GLubyte value. So I use the GL_UNSIGNED_BYTE as the type parameter of the function glTexImage2D(). It means that each component of the image is stored in an 8-bit unsigned integer value. I also use GL_RGBA or GL_RGB constants as the internalformal of this function.But wah tdoes happen if I use GL_R3G3B2 as the internalformat?In this case R, G and B are not an 8-bit unsigned integer value. So what does happen in this case?
If the internal format does not match the source format, OpenGL converts the image data to the internal format.
In you example, R, G and B channels are downscaled from 8 bits to 3 (R and G) or 2 (B). If your source image is 32 bits, the A channel is discarded.
02-11-2007, 01:11 AM
The internal format tells the driver what format you want it stored in. GL_RGBA or GL_RGB is not very clear to the driver what you want. Better use GL_RGBA8 or GL_RGB8
GL_R3G3B2 could mean that the driver will decide to lower quality to that format or it might choose to stay with GL_RGBA8.
The driver always chooses and will try to match a supported format by the GPU.
glGetTexParameter could be used to get the internal format.
02-11-2007, 09:11 AM
What does happen if I set the type parameter to GL_FLOAT?( For floating point textures ). As I said before, I load each component of the targa file in a GLubyte value.
Then OpenGL will parse the imge data wrong and you get a garbage texture. You told it to interpret each channel as a float, but that's not what the image data contains.
02-11-2007, 03:03 PM
Format and type are client format and type, describing the data that you're passing to GL.
Internalformat is exactly that-- the format OpenGL is going to store the texture in internally. If it doesn't match the client format/type, there will be a conversion during upload.
If you want an floating point internal format, use an internal format like RGBA32F_ARB. Note that float textures are not a part of core OpenGL yet, so you must use an extension.
02-11-2007, 10:29 PM
When exporting the RGB( or RGBA ), each component consist of 8 bits. In this case, can I use GLfloat values to save each component of the targa image?As I know, floating point values 32 bits( I don't know about GLfloat, but it's clear that it occupies more than 8 bits ). So can I save an 8-bit value to a 32- bit value?
Another question is about the GL_FLOAT type. If I say each component is a floating point value, then sum of R, G, B and A is 4 * 32 bits. But GL_RGBA32F_ARB says that "each RGBA component" consist of 32 bits( Am I correct ).
So I'm confused about the floating point textures.
1: Of course you can store your image data as a float unstead of a byte. But you don't gain anything by doing that really. Your original image is still 8 bits, so you cannot get a higher color resolution or anything by storing each component as a float.
2: A component is a single color channel. If "each RGBA component" is 32 32 bit, then the pixel is 32 bits times 4 color channels (RGBA is 4 components) bits large. Exactly the same result as you got.
02-11-2007, 11:11 PM
1)So Is there an application to export the targa images with more than 8 bits in each component?
TGA doesn't support anything above 8 bits per channel. You have to use another format if you want higher color resolution. PNG for example can store 16 bits per channel for example. There are also other formats with even higher resolution or floatingpoint components.
I don't know of any program than can actually use higher color resolutions, but they do exist.
02-12-2007, 01:35 AM
Originally posted by Bob:
PNG can store 16 bits per channel for example.
So to work with PNGs, I should use GL_HALF_FLOAT_ARB ?
Are there any image types that support 32 bits per channel?
02-12-2007, 02:54 PM
No, the PNG 16 bit format is integer so the itnernal format will be GL_RGBA16 or GL_RGB16, GL_LUMINANCE16.
For floating point, DDS. I think they support 16 and 32 bit float.
02-12-2007, 11:23 PM
I taked a quick look at DDS file fromat and DXTex tool. The input of the DXTex tool is a bitmap file. Then this tool can convert the bitmap file to the DDS file( with many options ). So converting the bitmap file to a DDS file will not add the quality of the image, since bitmap file consist of 8 bits per component and converting this value to a floating point value does not add the quality( It only adds the bits ).
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.