|
Post by adh on Jun 22, 2004 16:32:37 GMT -5
I saw the example in the manual that explain the mouse position and when you click in the screen, it is writen a X. I want to make somethig similar but instead a X, it will be writen an opengl point.
The problem is that the text coordenates are not the same that screen opengl coordenates, Anyone knows the equivalencie ( I think it is writen that way) between both.
Can I use the example like a base for the thing I want to make
thanks.
|
|
|
Post by Tom Mulgrew on Jun 22, 2004 22:18:33 GMT -5
This might help you get started: ' Setup a 2D projection to replace the default 3D one. ' (0, 0) will correspond to the top left corner of the screen ' (rangex#, rangey#) to the bottom right const rangex# = 120, rangey# = 100 ' Setup screen glMatrixMode (GL_PROJECTION) glLoadIdentity () glOrtho (0, rangex#, rangey#, 0, 0, 1) glMatrixMode (GL_MODELVIEW)
' Disable some 3D features that aren't much needed in 2D glDisable (GL_DEPTH_TEST) glDisable (GL_CULL_FACE) dim x#, y#
while true glClear (GL_COLOR_BUFFER_BIT) ' Default mouse range is 0 to 1, so multiply by screen range. x# = mouse_x () * rangex# y# = mouse_y () * rangey# ' Draw a cross at the mouse position glBegin (GL_LINES) glVertex2f (x#, y# - 10) glVertex2f (x#, y# + 10) glVertex2f (x# - 10, y#) glVertex2f (x# + 10, y#) glEnd () SwapBuffers () wend
This basically switches OpenGL to 2D, by replacing the 3D projection matrix with a simpler one that simply drops the Z coordinate (leaving just the x and y). You can pretty much setup any range you want for your screen coordinates. OpenGL will automatically scale everything accordingly. -Tom
|
|