Results 1 to 6 of 6

Thread: How do I?

  1. #1

    How do I?

    I wish to create a cad like interface using glortho or gluortho2d, the problem is how do I make y coordinates like windows coordinates?

    (this means increase downwards instead of upwards)

    thanx

  2. #2
    Junior Member Newbie
    Join Date
    May 2001
    Location
    Pawtucket, Rhode Island, USA
    Posts
    10

    Re: How do I?

    You could rotate your coordinate system so that the positive y axis is downward. I don't think this puts the origin at the top left of the screen though. I might be wrong.

  3. #3
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: How do I?

    http://www.3dgamedev.com/resources/openglfaq.txt
    ----------------------------------------------------------------------
    Subject 4.03: How do I set up OpenGL matrix stack for rasterization-only?

    Something like:
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, width, height); /* viewport size in pixels */

    will mean that the 3D point (0,0,0) is in the center of the viewport,
    and that
    (1,1,0) is the top-right corner of the viewport.

    To get a 1:1 pixel mapping, with (0,0,0) in the top-left of the
    viewport and (width,height,0) in the bottom-right, do this:
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(2.0f / (float)width, -2.0f / (float)height, 1.0f);
    glTranslatef(-((float)width / 2.0f), -((float)height / 2.0f), 0.0f);
    glViewport(0, 0, width, height); /* viewport size in pixels */

  4. #4
    Senior Member Regular Contributor
    Join Date
    May 2001
    Location
    Germany, Hannover
    Posts
    160

    Re: How do I?

    its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy ...

  5. #5
    Member Contributor
    Join Date
    Feb 2000
    Location
    Brisbane,QLD, Australia
    Posts
    99

    Re: How do I?

    when you get your mouse position say now it is returning mousey = 10

    now just do this
    mousey = screen_size_y - mousey;

  6. #6

    Re: How do I?

    Originally posted by T2k:
    its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy ...
    Thanx that worked lustfully.

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