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.

Are you drawing in 2D only? It makes a difference to what you have to do.

just use Modelview matrix.

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.


#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

[QUOTE=giuseppe500;1244755]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?.[/QUOTE]
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.

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.

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].

very thanks.
I understand.
by