Sign in to follow this  
Code-R

Rendering A Fullscreen quad using an orthographic viewport.

Recommended Posts

Code-R    136
After rendering my scene to a texture using FBOs, I want to setup a fullscreen quad that I overlay the image over. the thing is, I don't see anything except when I translate with some -Z value. what would be causing that? code:
void FinalizeScene()
{
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	glLoadIdentity();
	glTranslatef(0,0,-1);
	glDepthFunc(GL_ALWAYS);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClientActiveTextureARB(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, FrameTexture);
	glGenerateMipmapEXT(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glColor4f(1,1,1,1);
	glOrtho(0, ViewportWidth, 0, ViewportHeight, -1, 1);
	glBegin(GL_QUADS);
	glTexCoord2f(0,0);
	glVertex2f(0,0);
	glTexCoord2f(0,1);
	glVertex2f(0,ViewportWidth);
	glTexCoord2f(1,1);
	glVertex2f(ViewportHeight, ViewportWidth);
	glTexCoord2f(1,0);
	glVertex2f(ViewportHeight,0);
	glEnd();
	SwapBuffers(hDC);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferObject);
}

Share this post


Link to post
Share on other sites
James Trotter    432

void FinalizeScene()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glLoadIdentity();
glTranslatef(0,0,-1); <-- Is that really supposed to be there?
glDepthFunc(GL_ALWAYS);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClientActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, FrameTexture);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor4f(1,1,1,1);
glMatrixMode(GL_PROJECTION); <-- Insert this line
glLoadIdentity(); <-- And this one
glOrtho(0, ViewportWidth, 0, ViewportHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(0,1);
glVertex2f(0,ViewportWidth);
glTexCoord2f(1,1);
glVertex2f(ViewportHeight, ViewportWidth);
glTexCoord2f(1,0);
glVertex2f(ViewportHeight,0);
glEnd();
SwapBuffers(hDC);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferObject);
}


Don't know if this is the correct fix... You might try to use gluOrtho2D instead of glOrtho.

Edit: And another thing. Instead of setting the depth function to GL_ALWAYS, you might as well disable depth testing: glDisable(GL_DEPTH_TEST);
Hope this helps.

Share this post


Link to post
Share on other sites
zedzeek    529
the easiest method for a fullscreen quad is
set both modelview + project to the identity matrix
and draw a quad of coordinates (-1,-1) -> (1,1)

Share this post


Link to post
Share on other sites
Code-R    136
now the code for fianlizeScene is:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glLoadIdentity();
//glTranslatef(0,0,-1);
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClientActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, FrameTexture);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor4f(1,1,1,1);
glOrtho(0, ix_FrameWidth, 0, ix_FrameHeight, 0, 1);
//gluOrtho2D(0,ix_FrameWidth, 0, ix_FrameHeight); // not working.
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(0,1);
glVertex2f(0,ix_FrameWidth);
glTexCoord2f(1,1);
glVertex2f(ix_FrameHeight,ix_FrameWidth);
glTexCoord2f(1,0);
glVertex2f(ix_FrameHeight,0);
glEnd();
SwapBuffers(hDC);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferObject);



I can see the textured quad, but it's unaligned with the screen. any ideas?

Share this post


Link to post
Share on other sites
Daaark    3553
I just set my viewport to ortho and draw a quad as if It was a2d screen with Depth testing turned off.


glOrtho(0, nWidth, 0, nHeight, -1, 1);

glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f);
glVertex2i(0,nHeight-1);
glTexCoord2f(0.0f,0.0f);
glVertex2i(0,0);
glTexCoord2f(1.0f,0.0f);
glVertex2i(nWidth-1,0);
glTexCoord2f(1.0f,1.0f);
glVertex2i(nWidth-1,nHeight-1);
glEnd();



Whya re you making mipmaps of your frame texture? Seems you'll only ever need 1 of them? Am I missing something? You seem to be doing a lot of work there for little effect.

Share this post


Link to post
Share on other sites
blueshogun96    2265
Quote:
Whya re you making mipmaps of your frame texture?

It is a good idea to use a mipmapped texture in OpenGL if his texture widh and height are not powers of two. If this is the case, than using a different texture filtering method would cause a MAJOR slowdown in his application.

But here's my reccomendation. Click the link on my sig and try using that method. But the point (0,0) is in the bottom left hand corner so you will have to do some minor calculations to move the (0,0) coordinate back to the top.

Share this post


Link to post
Share on other sites
Kalidor    1087
Quote:
Original post by Code-R
now the code for fianlizeScene is:
*** Source Snippet Removed ***
I can see the textured quad, but it's unaligned with the screen. any ideas?
You still aren't switching to the projection matrix before you call glOrtho (at least not in what you posted).
Quote:
Original post by James Trotter
	glMatrixMode(GL_PROJECTION); <-- Insert this line
glLoadIdentity(); <-- And this one
glOrtho(0, ViewportWidth, 0, ViewportHeight, -1, 1);


And yeah, there's no need for mipmaps if the texture will always be the same size on screen.

EDIT: Just a note, gluOrtho2D is the same as glOrtho with the near and far parameters set to -1 and 1, respectively.

Share this post


Link to post
Share on other sites
Code-R    136
ok, so now it's

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, ix_FrameWidth, 0, ix_FrameHeight, 0, 1);
//glTranslatef(0,0,-1);
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClientActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, FrameTexture);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor4f(1,1,1,1);
//gluOrtho2D(0,ix_FrameWidth, 0, ix_FrameHeight);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(0,1);
glVertex2f(0,ix_FrameWidth);
glTexCoord2f(1,1);
glVertex2f(ix_FrameHeight,ix_FrameWidth);
glTexCoord2f(1,0);
glVertex2f(ix_FrameHeight,0);
glEnd();
SwapBuffers(hDC);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferObject);



The results are much better, but they're still not perfect. the quad doesn't fill the screen, it leaves a border on the right/bottom. any ideas?

Share this post


Link to post
Share on other sites
Shanjaq    151
Here's what I do:


// Push back and cache the current state of depth testing and lighting
// and then disable them.
glPushAttrib( GL_TEXTURE_BIT | GL_DEPTH_TEST | GL_LIGHTING );

glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );

// Push back the current matrices and go orthographic for background rendering.
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho( 0, 1024, 768, 0, -1, 1 ); //or whatever size you want

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

//build the background
glBindTexture(GL_TEXTURE_2D, Texture); // Select Our Texture
glBegin(GL_QUADS); // Draw The Quad
glColor3f( 1.0, 1.0, 1.0 );
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, float(nWindowHeight), 0.0f); // Bottom Left
glTexCoord2f(1.0f, 0.0f); glVertex3f( float(nWindowWidth), float(nWindowHeight), 0.0f); // Bottom Right
glTexCoord2f(1.0f, 1.0f); glVertex3f( float(nWindowWidth), 0.0f, 0.0f); // Top Right
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); // Top Left
glEnd(); // Done Drawing The Quad


// Pop everything back to what ever it was set to before we started

glMatrixMode( GL_PROJECTION );
glPopMatrix();

glMatrixMode( GL_MODELVIEW );
glPopMatrix();

glPopAttrib();




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this