PDA

View Full Version : Rotation problems in Ortho view mode...



bbliksted
03-18-2006, 05:50 AM
Hey...

Why does this code generate a texture as expected when ROTATE_ANGLE=89 deg, but a black texture when ROTATE_ANGLE=90 deg (or more)...




void viewer::ViewOrtho(void)
{
glMatrixMode(GL_PROJECTION); // Select Projection
glPushMatrix(); // Push The Matrix
glLoadIdentity(); // Reset The Matrix
glOrtho( -TEXTURE_WIDTH/2, TEXTURE_WIDTH/2, -TEXTURE_HEIGHT/2, TEXTURE_HEIGHT/2, -1, 1 ); // Select Ortho Mode
glMatrixMode(GL_MODELVIEW); // Select Modelview Matrix
glPushMatrix(); // Push The Matrix
glLoadIdentity(); // Reset The Matrix
}

// Set Up A Perspective View
void viewer::ViewPerspective(void)
{
glMatrixMode( GL_PROJECTION ); // Select Projection
glPopMatrix(); // Pop The Matrix
glMatrixMode( GL_MODELVIEW ); // Select Modelview
glPopMatrix(); // Pop The Matrix
}

// Render texture...
void viewer::RenderTexture(void)
{
ViewOrtho(); // Set orthogonal projection mode
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
glViewport(0,0,TEXTURE_WIDTH, TEXTURE_HEIGHT); // Viewport

glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // render attachment 0
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffers[bufferWrite]);

// Assign texture position to shader
#ifdef ENABLE_SHADER
enablePaintBrushShader();
#endif

glRotatef(ROTATE_ANGLE, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-TEXTURE_WIDTH/2, -TEXTURE_HEIGHT/2, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(TEXTURE_WIDTH/2, -TEXTURE_HEIGHT/2, 0.0f);
glEnd();
#ifdef ENABLE_SHADER
disableShaders();
#endif
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind fbo 0

// Set Perspective projection mode
ViewPerspective();
}

// FS
uniform sampler2D texture;
void main()
{
vec4 texelColor0 = texture2D(texture, vec2(gl_TexCoord[0])); // Get current color of texel
gl_FragColor = texelColor0;
}

// VS
void main()
{
// now normalize the light's direction. Note that according to the
// OpenGL specification, the light is stored in eye space.
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}Any suggestions?