# glortho troubles

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have setup my screen with 4 viewports with all perspective. I am trying to set my bottom left viewport to an ortho projection but it doesn't work. Here is the code ww and hh are the width and height of my window Gl.glViewport(0,0,ww,hh); //clear the color buffer to the clear color Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); // Clear the matrix Gl.glLoadIdentity(); //bottom left Gl.glViewport(0, 0, ww/2, hh/2); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0.0,ww/2,0.0,hh/2,-1.0,100.0);; Gl.glMatrixMode(Gl.GL_MODELVIEW); // Viewing transformation Glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); Render(); I've noticed by using small values like -1 and 1 in glortho seem to work. I dont get it. Thanks for any help Cheers :)

##### Share on other sites
Quote:
 Original post by one mindHi, I have setup my screen with 4 viewports with all perspective. I am trying to set my bottom left viewport to an ortho projection but it doesn't work.

It doesn't work? What, more exactly, goes wrong? Could you post a screenshot or otherwise describe what is happening?

##### Share on other sites
Why are you using a far clip plane of 100.0f in glOrtho? I always use 1.0f and it works fine for me.

##### Share on other sites
Hi, I'm just using 100 for testing, why? what should it be?
Anyway, the code i have above renders a blank screen.
Here is code I am using i got from Nate Robbins example

Gl.glOrtho(-ratio, ratio, -ratio, ratio, -10, 256);

Where ratio = width/height;

This works well except when the window is sized down in one axis, like if u make the window smaller by dragging the right edge left, the ortho view dissappers.

Does anyone have like an exact formula for the input of orthogl?

Thanks again :)

##### Share on other sites
I only use Ortho for 2d rendering, but mine is set up something like (assuming 640, 480 display)

glOrtho( 0, 640, 0, 480, -1, 1 )

##### Share on other sites
Quote:
 Original post by one mindHi, I'm just using 100 for testing, why? what should it be?

Well, it should be as much as you need :)
I don't see why there would be a problem with a far plane at distance 100. Just make sure all objects that should be visible are between the near and far planes.

Quote:
 Anyway, the code i have above renders a blank screen.Here is code I am using i got from Nate Robbins exampleGl.glOrtho(-ratio, ratio, -ratio, ratio, -10, 256);Where ratio = width/height;This works well except when the window is sized down in one axis, like if u make the window smaller by dragging the right edge left, the ortho view dissappers.

Well, the ratio says how many times greater the width is than the height, right? So if you do like this:
Gl.glOrtho(-ratio, ratio, -1.0, 1.0, -10, 256);

the view volume's width and height will have the same ratio as the window's width and height.
Try it, and see if it works better :)

##### Share on other sites

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628701
• Total Posts
2984287

• 22
• 10
• 9
• 13
• 13