PDA

View Full Version : Problem about float texture!



phide
12-10-2003, 12:13 PM
How to construct a float texture using normal byt iamge data?
I used following code:
glBindTexture( GL_TEXTURE_2D , floatTexture ) ;

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0,
GL_FLOAT_RGB32_NV, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE,
textureImage->data);

where textureImage->data is normal byte image data. But, when I rende
somthing with this floatTexture, all is black! Any onw has idea about that?

Dongsheng

NitroGL
12-10-2003, 12:20 PM
Read the NV_float_buffer extension spec, it says that the texture target must be GL_TEXTURE_RECTANGLE_NV.

zeckensack
12-10-2003, 01:11 PM
And filtering must be GL_NEAREST.

phide
12-10-2003, 08:48 PM
Thanks!

I used GL_TEXTURE_RECTANGLE_NV now. It still does not work!

And, I have my owe fragment program. I modified the demo from nVidia "simple_float_pbuffer." Following is the core code.

The results are strange. If I only replace the first fragment with mine, result is OK! But If I replace all two fragments with mine! Results are wroung! So, the rendering to float buffer is OK! Copy to float texture is OK! Rendering with a float buffer texture is NOT OK!

Any ideas?


---------------
float buffer Initialization
---------------
glGenTextures(1, &fptexture);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGB32_NV, 256, 256, 0, GL_RGB, GL_FLOAT, NULL);

--------------------
display code
---------------------

void display(void)
{
static float rot = 0.0;
int width = fpbuffer.getWidth();
int height = fpbuffer.getHeight();

fpbuffer.activate();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw rotating quad with nvidia logo
glColor3f(1.0, 1.0, 1.0);
glRotatef(rot, 0.0, 0.0, 1.0);
glTranslatef(-0.5, -0.5, -1.3);

// glEnable(GL_FRAGMENT_PROGRAM_NV);
// glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTexture2D);
// glBindTexture(GL_TEXTURE_2D, logotexture);
cgGLBindProgram(vProgram);
cgGLEnableProfile(vProfile);

cgGLBindProgram(fProgram);
cgGLEnableProfile(fProfile);

cgGLSetStateMatrixParameter( paraVpModelViewProj,
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY ) ;

cgGLSetTextureParameter( paraFpTexture, logotexture ) ;
cgGLEnableTextureParameter( paraFpTexture ) ;

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.0);
glEnd();

cgGLDisableTextureParameter( paraFpTexture ) ;
cgGLDisableProfile(vProfile);
cgGLDisableProfile(fProfile);

// glDisable(GL_FRAGMENT_PROGRAM_NV);

// copy contents of pbuffer to a texture
glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, width, height);
fpbuffer.deactivate();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw a single quad with the texture containing a snapshot of the
// floating point pbuffer
// glEnable(GL_FRAGMENT_PROGRAM_NV);
// glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, readTextureRECT);
// glBindTexture(GL_TEXTURE_RECTANGLE_NV, fptexture);

cgGLBindProgram(vProgram);
cgGLEnableProfile(vProfile);

cgGLBindProgram(fProgram);
cgGLEnableProfile(fProfile);

cgGLSetStateMatrixParameter( paraVpModelViewProj,
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY ) ;

cgGLSetTextureParameter( paraFpTexture, fptexture ) ;
cgGLEnableTextureParameter( paraFpTexture ) ;

glTranslatef(-0.5, -0.5,-0.9);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(width, 0.0); glVertex2f(1.0, 0.0);
glTexCoord2f(width, height); glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, height); glVertex2f(0.0, 1.0);
glEnd();

cgGLDisableTextureParameter( paraFpTexture ) ;
cgGLDisableProfile(vProfile);
cgGLDisableProfile(fProfile);

// glDisable(GL_FRAGMENT_PROGRAM_NV);

rot += 0.5;
glutSwapBuffers();
}

-------------------
Cg code: fragment
------------------------
void main(float4 Position : POSITION ,
float2 texCoord : TEXCOORD0 ,
out float4 color : COLOR,
uniform sampler2D texture)
{
float4 texColor = tex2D( texture,texCoord ) ;
// color.x = 1.0 ;
// color.y = 0.0 ;
// color.z = 0.0 ;
// color.w = 1.0 ;
}


--------------------
Cg code: Vertex
--------------------

void main(float4 Position : POSITION ,
float2 texCoord : TEXCOORD0 ,
out float4 oPosition : POSITION ,
out float2 oTexCoord : TEXCOORD0 ,

uniform float4x4 ModelViewProj)
{
oPosition = mul(ModelViewProj, Position);
oTexCoord = texCoord ;
}