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 6 of 6

Thread: coordinates and point on click

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    111

    coordinates and point on click

    hello.
    I have create a system that draws little circles or points in opengl 3 where I click the mouse in a qt opengl widget.
    The problem are the coordinates: the circle is not drawed in the position of the mouse when i click.
    I divide the point x for the width and the point y for the height for and I have a point from 0 to 1
    But how i can trasform these points from 0 to 1 to the opengl coordinates?
    i must use the opengl viewport?
    or the ortho matrix?
    how?



    ps.

    the glwidget is on a mdi window

    thanks.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Are you drawing in 2D only? It makes a difference to what you have to do.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    19
    just use Modelview matrix.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    111
    yes , i'm drawing in only in 2d.
    I try to add a matrix to my shader, for example MVO with the orto matrix and send it to the shader.
    Code :
    #version 330
    in vec3 VertexPosition;
    uniform mat4 MVO;
    void main()
    {
        gl_Position = vec4( VertexPosition, 1.0 ) * MVO;
     
    }
    i call glorto with left,right,bottom and top but if i set a ortho from left -1 and right 1 and from bottom -1 to top 1 if i try to draw at position -1,-1 i see my object correctly,but if i set glortho from left 0 right 1 and from bottom 0 to top 1 i don't see nothing on the render when i draw at 0,0.
    Why?.
    How i can convert qt coordinates from x,y,height and width from -1 to 1(if is not possible to set a glortho matrix with coordinates from 0 to 1)?.
    thanks

  5. #5
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,161
    Quote Originally Posted by giuseppe500 View Post
    yes , i'm drawing in only in 2d.
    I try to add a matrix to my shader, for example MVO with the orto matrix and send it to the shader....i call glorto with left,right,bottom and top but if i set a ortho from left -1 and right 1 and from bottom -1 to top 1 if i try to draw at position -1,-1 i see my object correctly,but if i set glortho from left 0 right 1 and from bottom 0 to top 1 i don't see nothing on the render when i draw at 0,0.
    Why?.
    How can you use shaders and call glOrtho to setup projection? Do you set MVO somewhere in the application? That's where projection is set, not with glOrtho.

    Quote Originally Posted by giuseppe500 View Post
    gl_Position = vec4( VertexPosition, 1.0 ) * MVO;
    Did you have a matrix calculus in the school? Matrix multiplication is not commutative! In OpenGL you should multiply matrix with the vector. Legacy OpenGL is still uncompromisingly required at the beginners level, since some operations are forced to be done on correct way. Shaders give too much freedom which leads to such mistakes.

    Quote Originally Posted by giuseppe500 View Post
    How i can convert qt coordinates from x,y,height and width from -1 to 1(if is not possible to set a glortho matrix with coordinates from 0 to 1)?
    If we know that after all transformation, objects appear at the screen at the coordinates: v' = Viewport * Proj * View * Model * v, then v = Model^-1 * Vew^-1 * Proj^-1 * Viewport^-1 * v'. Between Projection and Viewport transformation, there is a perspective division, but I guess that is not of interest in your case. In your case, probably, only this is required: v = Proj^-1 * Viewport^-1 * v'. Inverse Viewport transformation maps [0,Width]/[0,Height] to [-1,1], and inverse Proj transformation maps [-1,1] to [left, right]/[bottom, top].

    In short, you don't have to know anything said before, just map [0, Width] -> [left, right] and [0, Height] -> [bottom, top].
    Last edited by Aleksandar; 11-23-2012 at 08:24 AM.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    111
    very thanks.
    I understand.
    by

Posting Permissions

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