Sign in to follow this  
Code-R

OpenGL Orthographic viewport problems

Recommended Posts

I'm trying to use an ortho viewport with FBOs. when I don't setup the orthographic view, rendering is fine. when I try to use it, nothing is rendered. here's my opengl calls log:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,1)
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
glDisable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0.000000,1024.000000,0.000000,768.000000,-1.000000,1.000000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glColor4fv([1.000000,1.000000,1.000000,1.000000])
glTranslatef(512.000000,384.000000,0.000000)
glActiveTextureARB(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glEnable(GL_DEPTH_TEST)
glBindTexture(GL_TEXTURE_2D,3)
glBegin(GL_QUADS) Textures[ (0,3) ] 
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([0.000000,0.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([0.000000,1.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([1.000000,1.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([1.000000,0.000000,0.000000])
glEnd()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
//Frame ends here
//This part draws the FBO to a fullscreen quad. it's tested, and it works.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0)
glPushAttrib(GL_CURRENT_BIT | GL_POINT_BIT | GL_LINE_BIT | GL_POLYGON_BIT | GL_POLYGON_STIPPLE_BIT | GL_PIXEL_MODE_BIT | GL_LIGHTING_BIT | GL_FOG_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_HINT_BIT | GL_EVAL_BIT | GL_LIST_BIT | GL_TEXTURE_BIT | GL_SCISSOR_BIT)
glDisable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0.000000,1024.000000,768.000000,0.000000,-1.000000,1.000000)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glActiveTexture(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D,1)
glBegin(GL_QUADS) Textures[ (0,1) ] 
glColor3f(1.000000,1.000000,1.000000)
glTexCoord2f(0.000000,0.000000)
glVertex3f(0.000000,768.000000,0.000000)
glTexCoord2f(1.000000,0.000000)
glVertex3f(1024.000000,768.000000,0.000000)
glTexCoord2f(1.000000,1.000000)
glVertex3f(1024.000000,0.000000,0.000000)
glTexCoord2f(0.000000,1.000000)
glVertex3f(0.000000,0.000000,0.000000)
glEnd()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glPopAttrib()
wglSwapBuffers(0xd601137f)=true 

any ideas? TIA

Share this post


Link to post
Share on other sites
glPushAttrib(GL_CURRENT_BIT | GL_POINT_BIT | GL_LINE_BIT | GL_POLYGON_BIT | GL_POLYGON_STIPPLE_BIT | GL_PIXEL_MODE_BIT | GL_LIGHTING_BIT | GL_FOG_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | *****GL_VIEWPORT_BIT***** | GL_TRANSFORM_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_HINT_BIT | GL_EVAL_BIT | GL_LIST_BIT | GL_TEXTURE_BIT | GL_SCISSOR_BIT);

I noticed you Pushed the GL_VIEWPORT_BIT, now i dont know if it is that but try removing

glPopAttrib() --> And see if u get results!

Share this post


Link to post
Share on other sites
nop, that wasn't it. besides, this part is in the part that renders the fb to a fullscreen quad, and i'm sure it works, becuase when I draw stuff in non-ortho, it shows up perfectly ok.

any ideas?

Share this post


Link to post
Share on other sites
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([0.000000,0.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([0.000000,1.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([1.000000,1.000000,0.000000])
glMultiTexCoord2fv(GL_TEXTURE0,0xb225a4)
glVertex3fv([1.000000,0.000000,0.000000])

crap im such an idiot... its right infront of me!!!!

Okay in Projection your screen looks like this


-1------------>X +1
|
|
|
|
Y+1

And thats why it works on projection compared to ur current ortho settings
which are
0------------>X +1024
|
|
|
|
Y+786


The reason is GL_VIEWPORT already set the Drawing area, all you do when you edit the projection matrix is change how the stuff get Transformed onto that area.

Try Replacing your ortho values with
glOrtho(0.000000,1.024*2,0.000000,0.768*2,-1.000000,1.000000)

Share this post


Link to post
Share on other sites
nope, didn't work. I'm wondering why the part that renders the fbo to a fullscreen quad using a similar method works, but this doesn't...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
well, I think I know what it is

glOrtho(0.000000,1024.000000,768.000000,0.000000,-1.000000,1.000000);

should be.

glOrtho(0.000000, 0.000000, 1024.000000, 768.000000,-1.000000,1.000000);

Share this post


Link to post
Share on other sites
Thanks! I got it now! actually, it should be (0,1024,768,0), as I use the bottom left as the origin. Thanks again everyone, ratings++.

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