PDA

View Full Version : Render to texture Problem



apapaxionga
11-16-2011, 04:12 AM
i want to get four value and I calculate each value in the fragment shader by using glVertex to pass the value to Shader, ande then i want to keep this value in a 2X2 texture.How?
i use fbo to bind a texture ,but it seems that i don't get the correct texture i want. Why?


The texture Bind to FBO:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

////////////////////////////////////////////////////////////
glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, 1, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);

BindShader()
BindFbo()

glBegin()
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);
glEnd();

UnBindFbo();
UnBindShader();

/////////////////////////////////////////////
Fragment Shader:
void FragmentProgram (
out float4 color0 : COLOR0,
float3 N : TEXCOORD0
)
{
................
color0=float4(value I need , value I need , value I need , value I need);
}

V-man
11-17-2011, 07:38 AM
It looks like you want to render a fullscreen quad. Perhaps you need to call

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

and use -1.0 to +1.0 values for you vertices.

http://www.opengl.org/wiki/FAQ#Fullscreen_quad