# simple viewport explanation

Can anyone explain me something basic about viewports that i can’t understand?
I’m trying to configure viewports in my application.
I’ve defined:
Gl.glOrtho(0, 2500, 0, 2500, -4.0, 4.0)

and i’m trying to create one viewport that will occupy 100% of the screen (for now, later i’ll need 3 with diferent width). So i tryed this:
Gl.glViewport(0, 0, 2500, 2500)

but it doesn’t work. But it works if i define the viewport as:
Gl.glViewport(0, 0, 400, 400)

How can this be possible if i have defined a width/height that is a lot smaller than the one i defined in glOrtho? Shouldn’t the viewport be very small? maybe i’m mixing everything wrong.

Have you checked this?

I’m using the Tao SimpleOpenGLControl. Don’t know if has something to do with that, but now that you say that i see that it has 365/302 inside a windows form

Well, tested it. You are absolutly right, but then again, if that its true, doesn’t Gl.glOrtho takes arguments in pixel units too?

No glOrtho does not take arguments in pixels, it just sets an orthographic or parallel projection.

For example if you set 2D projection like this:
Gl.glOrtho(0, 10, 0, 20, -1.0, 1.0)

All points whose coordinates (x,y) are in the interval [0 10]x[0 20] will be rasterized.

However you can set the projection in a way that it fits the window size. eg, for a 800x600 window:
Gl.glOrtho(0, 800, 0, 600, -1.0, 1.0)

a vertex whose coordinates are (40, 50) will be drawn exactly at the position (40, 50) in pixels unit (starting from the bottom left corner).

glViewport just set which portion of the window is used for drawing. By default, viewport is set to the dimensions of the created window.

Some background reading from the Redbook online will be beneficial. Chapter 3 explains all about the connections between viewport + projections + gluLookAt.

The arguments to Viewport are in pixel units and the rectangle you define with it must be no greater than the actual window itself.

``````