Results 1 to 6 of 6

Thread: simple viewport explanation

  1. #1
    Member Newbie
    Join Date
    Sep 2009
    Location
    Corroios, Portugal
    Posts
    48

    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.

    My thanks in advanced

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: simple viewport explanation

    In your previous thread, marshats asked you this:

    Quote Originally Posted by marshats
    Gl.glViewport takes arguments in pixel units. Does your monitor have 2500x2500 pixel resolution?
    Have you checked this?

  3. #3
    Member Newbie
    Join Date
    Sep 2009
    Location
    Corroios, Portugal
    Posts
    48

    Re: simple viewport explanation

    My monitor has 1024/768
    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

  4. #4
    Member Newbie
    Join Date
    Sep 2009
    Location
    Corroios, Portugal
    Posts
    48

    Re: simple viewport explanation

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

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: simple viewport explanation

    Quote Originally Posted by appdeveloper
    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.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    CA
    Posts
    408

    Read Redbook for precise viewport explanation

    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.

    To follow up on dletozeun's reply,
    glOrtho maps global X,Y,Z cooridinates to the viewport pixel cooridinates I,J as follows
    suppose you set
    Code :
    Gl.Viewport(10,20,50,50)
    Gl.glOrtho(0, 34.2, 0, 90.6, -1.0, 1.0)
    A point at (XYZ)=(0,0,0) would be mapped to the window at the far lower left pixel (IJ)=(10,20) and a point at (XYZ)=(34.2,90.6,0) would be mapped to the upper right window pixel (IJ)=(10+50,20+50). Points outside of the ortho box will simply be clipped ie not plotted to the screen.

    So glOrtho allows you to define your global coordinate system in convenient units (ie not in pixels) and points will be automatically mapped back to the viewport pixels -- this is a valuable feature because it is best to avoid thinking in terms of pixels and think in terms of global coordinates appropriate to you model. Typically, the only time you think in terms of pixels is when you set Viewport, and from then on openGL maps your global coordinate system back to the screen for you without you needing to think about pixels again. This is a great help when you allow the window size to change and you only have to change the code accordingly in one spot, the Gl.Viewport() settings!

Similar Threads

  1. Simple Explanation of Projection Transformation
    By openujs in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-16-2005, 10:04 PM
  2. Some explanation about a simple code
    By w00 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-28-2005, 12:56 AM
  3. just an explanation
    By grimoire in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-18-2004, 07:52 PM
  4. Clipping Volume - A Simple Explanation
    By plates in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-28-2001, 06:40 AM
  5. Viewport or multiple viewport in a window!
    By Boubou in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 11-30-2000, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean