PDA

View Full Version : Opengl GL wrong portview position



Washiro
05-22-2012, 03:20 PM
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



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



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


and this is the result

http://dl.dropbox.com/u/61491349/imeji%20o/OPENGL.png

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

I wanted to happen was this.

http://dl.dropbox.com/u/61491349/imeji%20o/DirectX.png

could understand?

aqnuep
05-22-2012, 06:29 PM
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).

mhagain
05-22-2012, 06:49 PM
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.

Washiro
05-23-2012, 09:26 AM
Thanks!
the problem was the windows size.