View Full Version : drawing onto screen not exact screen coord?
01-11-2009, 09:48 AM
I am new to using OpenGL and I have many questions, but the one that has been bothering most is this one:
Why is it that if I draw a glVertix2d, for example, and the parameters i called it with are '0.1, 0.1' it appears in the center of the window, which coords are 250, 250. Should it not appear in the top left of the window, since 0.0 is the top left of the Frame?
01-11-2009, 10:25 AM
All depends on how you set up your 'camera transformation'. There are ways to setup your 'camera' so that OpenGL and 'window-pixel' coordinates match, but in general this is not the case.
The 'default' for OpenGL is to have the origin in the center of your viewport.
Oh, and btw for textures or other pixel/fragment based stuff the origin is in the bottom left corner, as OpenGL uses right hand coordinate systems.
01-11-2009, 10:37 AM
But I really want to adjust it to the windows' pixel because i am making a model move to wherever the user clicks, and the values returned from glutMouseFunc() are windows' pixels, so i need to move my model to those specific coordinates.
Is there some sort of way I can 'translate' windows' pixel to the from where i am drawing? Or how would I go upon doing what i want?
01-11-2009, 01:43 PM
When you need orthographic projection, you can do something like this:
// set a 2D orthographic projection
// wWidth and wHeight are window dimensions
glOrtho(0, wWidth, wHeight, 0, -1, 1);
This way, the (0,0) point correspond to the window upper left corner. (wWidth, wHeight) is the lower right corner.
Now you are free to modify the glOrtho parameters to move the origin to the window center for example.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.