Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Opengl GL wrong portview position

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    4

    Opengl GL wrong portview position

    I'm having some problems with the glViewport, because the point xy 0.0 window is wrong.
    if I try to draw a line in the coordinates 1.1 and 32.32, the line does not appear in the window, it seems that the drawing area begins at the edge of the window.

    I do not know if I was clear.
    but I will post the picture of the problem here

    im using this code, to create the viewport

    Code :
    glViewport(0,0,640,480);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f,640,480,0.0f,0.0f,1.0f);

    and this code to draw the triangle

    Code :
    glBegin(GL_TRIANGLES);
    glVertex2f(mouse_x,mouse_y);
    glVertex2f(1.0f,1.0f);
    glVertex2f(320.0f,470.0f);
    glEnd();

    and this is the result



    see? the point glVertex2f(1.0f,1.0f); its much behind the window

    I wanted to happen was this.



    could understand?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    947
    The problem is probably with the windowing system framework that you use. Are you sure you don't get your mouse positions relative to the whole window's top left corner instead of the window's client area's top left corner in case of the OpenGL application?

    At least I don't see anything wrong with the code you've copy-pasted here (though I don't see how you set up your modelview matrix).
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    982
    Quote Originally Posted by aqnuep View Post
    The problem is probably with the windowing system framework that you use. Are you sure you don't get your mouse positions relative to the whole window's top left corner instead of the window's client area's top left corner in case of the OpenGL application?

    At least I don't see anything wrong with the code you've copy-pasted here (though I don't see how you set up your modelview matrix).
    Almost definitely correct - I can see from your screenshot that your window client area is actually about 624x442 which suggests that you've created the window at this dimension rather than adjusting the size to account for title bar and borders, and that this has likely carried over into your mouse code too.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    4
    Thanks!
    the problem was the windows size.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •