drawing lines

I am wondering why my coordinate system seems to go with my viewport and not my window.
I have a window (500 x 400) and a viewport (350 x 250) that I have put in the middle of the window. Why are my lines drawn with origin at the bottem-left corner of the VIEWPORT and not the window?! i.e. with the dimensions above, if I draw a line from (0,0) to (0,10) I should not be able to see it because it lies outside of the viewport, BUT there it is going from (0,0) to (0,10)inside the viewport! Doesn’t make sense to me.
This is the basic code:
glOrtho(0, viewportWidth, 0, viewportHeight,-1.0, 1.0);

glViewport(75, 75, 350, 450);


Any help is much appreciated.

Basically, glViewPort is specifying what part of the window to use, so your call:
glViewport(75, 75, 350, 450);
is saying draw into this rectangle within the window.

Whereas your call:
glOrtho(0, viewportWidth, 0, viewportHeight,-1.0, 1.0);
is saying set the GL coordinate system to be from 0 to viewportWidth in the x direction and 0 to viewportHeight in the y direction within the viewport. It also sets the clipping planes.

So, if you wanted to do like you stated you should call glOrtho like this:

glOrtho(75, viewportWidth + 75, 75, viewportHeight + 75,-1.0, 1.0);

or something similar. That should give you some ideas how it could be used. Personally, I prefer having (0,0) in the center and base my width and height on various factors, but everyone has their preference.

[This message has been edited by shinpaughp (edited 02-22-2003).]

Thank you very much. I basically want to be able to pan around an image and make the viewport bigger and smaller on command. Would the code you said provide this?
glOrtho(75, viewportWidth + 75, 75, viewportHeight + 75,-1.0, 1.0);

Secondly, the thought of putting the origin in the middle of the screen is intriguing, how is that done?
I really appreciate your help!!

[This message has been edited by Cerv36 (edited 02-23-2003).]

I think the diffrence between glortho, viewport and window size is a common error on new programmers.
Also is the understanding of how 3D graphics
3D graphics work with vectors, only when rendered to the screen does it be come pixels.

viewport is the area in which to render to in the window, so what every your ortho is set to will be displayed inside the viewport.

ortho is the 3D area in the shape of a cube, that the data will be processed to be displayed in the viewport.

So if you create a ortho view with a 10 X 10 area and draw a line 10 units long starting at 0,0 to 10,10. No mater how you change your view port the line will always be across it.

To pan or scale a object in 3D, look the glTranslate, glscale and glRotate commands.

A lot of examples will have viewport, window and ortho view the same size so the world coords match. This is good if you want you mouse movement to match world for doing 2D work or ease.

Now you do not have to have viewport, window and orther view match.

On my website I have some examples of the center of the window being 0,0.

I am not sure what you are trying to do by making your view port smaller?
If you give a little more detail maybe we can point you in the right direction.

Also maybe looking at my examples may help also.

Well, definitely listen to nexusone. He’s been doing this far longer than me. Look at his tutorials as well as tutorials on nehe.gamedev.net and other sites. Personally, I haven’t looked at any of them, but I hear they are good.

For glOrtho, you are basically setting the coordinate system that will lie within the box. If you have glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0) anything with an x or y or z coordinate greater than 1.0 or less than -1.0 will not be visible. And, the bottom left corner of your viewport will have coordinate (-1.0, -1.0) and top right of viewport will be (1.0, 1.0), so in your case use glOrtho(-width/2, width/2, -height/2, height/2, -1.0, 1.0) or something similar.

Good luck and good programming.