glRasterPos and pixel coordinates
Hi,
I have some very basic question. I am using bitmap fonts and I want to position the text at lower-left corner. First I zoomout from the screen, but I dont know how to precisely position the text by glRasterPos without trial-error. I get confused how to relate a change in raster position with its actual projection on the viewport in pixel units. For instance, if lower-left corner has the coordinates of (0,0) and with w,h (640, 480) - the viewport, I want text to be at (10,10) in pixels, regardless of the change in the size of client area. Then, what should be the first two arguments (x and y) of RasterPos and what kind of transformations should take place? Should I calculate it by myself through congruent triangles? Or is there any other way around? Some explanation would really help.
Thank you very much,
--Kemal
[edited by - kemalican on February 9, 2004 5:42:28 AM]
--Kemal
I used this code to exactly position text and OpenGL windows after my 3D drawing:
The reason i started the coordinate system at -1.0 and ended it 1.0 earlier whas that the view seemed to be moved one pixel to the left and is something i still don''t get. Anyway this made it work correctly for me.
glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-1.0,scrw-1,scrh,0.0,-1.0,1.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();
The reason i started the coordinate system at -1.0 and ended it 1.0 earlier whas that the view seemed to be moved one pixel to the left and is something i still don''t get. Anyway this made it work correctly for me.
Thank you. I was struggling with perspective projection, I couldnt think of switching to ortographic projection instead.
But, it would still be great to learn how to accomplish this with perspective projection also; the relation between translations and pixels of viewport. Just curious.
--Kemal
But, it would still be great to learn how to accomplish this with perspective projection also; the relation between translations and pixels of viewport. Just curious.
--Kemal
--Kemal
Why not use glWindowPos to place the raster position directly in window coordinates instead? No need to mess with matrices if you don''t fully know how it affects the raster position, how it maps to physical pixels, and (*cough*) why it sometimes not end up exactly where you want it.
The theory behind glRasterPos is that the coordinate you pass is transformed by the modelview and projection matrix. After projection, is''t either being marked as valid if inside the clipping volume, or invalid if not. Then, before ending up on the screen, it passed through the viewport transform to get the pixel coordinates. So the raster position is treated the same as a vertex coordinate.
The theory behind glRasterPos is that the coordinate you pass is transformed by the modelview and projection matrix. After projection, is''t either being marked as valid if inside the clipping volume, or invalid if not. Then, before ending up on the screen, it passed through the viewport transform to get the pixel coordinates. So the raster position is treated the same as a vertex coordinate.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement