Results 1 to 6 of 6

Thread: glViewport from top left, not bottom left

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2006
    Posts
    19

    glViewport from top left, not bottom left

    Bonjour.

    The program I am writing is completely 2D. All
    the math and logic assumes a coordinate system
    where x = 0 is the left and y = 0 is the top of
    the window.

    The problem:

    glViewport, which I expect to use a lot, in
    various parts of the code, expects the y value to
    be the bottom of the window. Sooner or later,
    I'm bound to forget to adjust y and end up with
    a blank screen or other hard to track down visual
    error.

    Essentially I'm looking for something like this:

    Code :
    void cam_viewport(int x, int y, int w, int h)
    {
      glViewport(x, adjust_y(y), w, h);
    }
    Any ideas how this can be implemented? I'm sure
    the solution is simple but I can't quite seem to
    get it.

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: glViewport from top left, not bottom left

    glWievport(x, y - h, w, h);

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2006
    Posts
    19

    Re: glViewport from top left, not bottom left

    Yes, I tried that and got a totally blank screen.

    There's probably something suspect in my code
    elsewhere.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2006
    Posts
    19

    Re: glViewport from top left, not bottom left

    If I do this:

    Code :
    void cam_viewport(int x, int y, int w, int h)
    {
      glViewport(x, y - h, w, h);
    }
     
    cam_viewport(0, 0, 640, 480);
    GL_INVALID_VALUE is generated by passing a
    negative value to glViewport().

  5. #5
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: glViewport from top left, not bottom left

    Sorry, it should be:
    glViewport(x, sh - y - h, w, h);
    where sh = screen height (in pixels)

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2006
    Posts
    19

    Re: glViewport from top left, not bottom left

    Yes, that's it.

    Why I couldn't work this out alone, I'll never
    know. I seem to be having one of those weeks.

    Thank you.

Similar Threads

  1. Bottom-left axes as these from Blender
    By kaaali in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-28-2011, 11:12 AM
  2. Is the origin of an image in the bottom left corner in OpenGL?
    By surgptr in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-01-2003, 12:11 PM
  3. Colors stretch to bottom left corner??
    By untoxik in forum OpenGL: Linux
    Replies: 3
    Last Post: 03-19-2002, 02:37 AM
  4. How to read buffers from upper left corner to bottom of the image?
    By Zoran Zivkovic in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 04-11-2001, 05:50 AM
  5. Black area around left and bottom edges of window
    By imported_ben in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-02-2001, 12:54 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