Hi, now I want to generate a float texture and the code likes the following:
glGenTextures(1, &_iTexture);
glBindTexture(GL_TEXTURE_2D, _iTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//read data from a file through the function
//: read_img
float* pData = read_img(cPath, _iWidth, _iHeight);
//especiall this one
glTexImage2D(GL_TEXTURE_2D, 0, 1, _iWidth, _iHeight, 0, GL_RED, GL_FLOAT, pData);
But I cann’t get a correct result. Someone pointed out that there is something wrong with this statement "glTexImage2D(GL_TEXTURE_2D, 0, 1, _iWidth, _iHeight, 0, GL_RED, GL_FLOAT, pData);
". He said that "The third parameter is “internal format”, which can’t be set to “1”. That means you have a GL error. Because you didn’t specify a float internal format, this won’t be a float texture, and therefore you have 8-bit fixed-point values in the texture. "
But I don’t understand why the third parameter cann’t be set to 1.
Any suggestions are appreciated, thank you in advance!
If I want to generate a float texture image that each pixel is composed of one component. Then I set the parameter ‘component’ to 1 and parameter ‘type’ to GL_RED(because I only use one component), so I get the following code:
it’s not GL_RED. if you want just one component - use GL_LUMINANCE!
e.g.
glTexImage2D(GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_FLOAT, data);
something like this will generate simple(grayscale) texture with float values
After setting up such a float texture(all the data are equal to 0.1), I warp it onto a square. If I use the following code to retrieve data from the framebuffer:
hm… as I understood the texture is working and set on simple quad, but when you try to readpixel to buffer it’s data equal to 0. (maybe not correctly)
where did you render this quad?
i’m not shure, but reading goes from bottom-left corner of framebuffer, maybe you redered it in upperleft? anyway how do you render it?
void TexImage2D( enum target, int level,
int internalformat, sizei width, sizei height,
int border, enum format, enum type, void *data );
type refers to the data representation per color component in memory(not in texture) format refers to the data structure, rgba, rgba, luminance… in memory internalformat refers to the representation of the texture components in the resulting texture
So calling TexImage2D with type=GL_FLOAT , format=GL_RGB and internalformat=GL_RGB8, will still result in a 8-bit per component texture.
Try setting your internalformat to GL_RGB16 or GL_LUMINANCE16. It is however not guaranteed that 16 bits will be assigned per component (section 3.8.1 opengl spec)
If you want 32 bit components, take a look at the GL_ATI_texture_float and/or GL_NV_float_buffer extensions at http://oss.sgi.com/projects/ogl-sample/registry/
They provide additional internal format representations.