PDA

View Full Version : Bind GL_TEXTURE_RECTANGLE_NV texture!



phide
12-11-2003, 09:46 AM
Can I bind a float GL_TEXTURE_RECTANGLE_NV texture to a fragment program using
cgGLSetTextureParameter( paraFpTexture, fptexture ) ?

I used following code to test it, but the result it all black. http://www.opengl.org/discussion_boards/ubb/frown.gif Any idea?

---------------------------------------------
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);
--------------------------------------------

jra101
12-11-2003, 10:09 AM
Can you post the Cg code that's fetching from the rectangular texture?

phide
12-11-2003, 10:20 AM
void main( float4 Position : POSITION ,
float2 texCoord : TEXCOORD0 ,

out float4 color : COLOR,

uniform samplerRECT texture)
{
float4 texColor = texRECT( texture, texCoord ) ;

color = texColor ;
// color.x = 1.0 ;
// color.y = 0.0 ;
// color.z = 0.0 ;
// color.w = 0.0 ;
}

phide
12-11-2003, 10:21 AM
void main( float4 Position : POSITION ,
float2 texCoord : TEXCOORD0 ,

out float4 oPosition : POSITION ,
out float2 oTexCoord : TEXCOORD0 ,

uniform float4x4 ModelViewProj)
{
// transform vertex position into homogenous clip-space
oPosition = mul(ModelViewProj, Position);

oTexCoord = texCoord ;
}

jra101
12-11-2003, 10:57 AM
What fragment profile are you using? What data is in the floating point texture?

phide
12-11-2003, 11:17 AM
CG_PROFILE_FP30

The float texture are read color.

phide
12-11-2003, 11:20 AM
Actually, I render a normal texture to the a float pBuffer, and then copy them to a float texture. Later, for easy to test, I used a all red texture.

--------------------------------------------
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);

// 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);

phide
12-11-2003, 11:24 AM
Vertex program is the same with above one.
Here is the fragment program.

-----------------------------------------
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 ;
}

phide
12-11-2003, 11:41 AM
Oh!

I made a stupid mistake! http://www.opengl.org/discussion_boards/ubb/frown.gif
I comment out a useful code
color = texColor!

Sorry! http://www.opengl.org/discussion_boards/ubb/smile.gif