glVertex: how to use other version of this call
I can only use glVertex3f in my computer, which specifies the position of vertex by the ratio of x,y,z-axes. Is there a way to specify the position of the vertex by giving the pixel numbers? Then I can use integer numbers.
I know I c开发者_运维知识库an scale the view and then I can use glVertex3i.
Is there other way?
Like the example in redbook of OpenGL, they directly use integer numbers in some calls. I have to use some float number less than 1.
By using an apropriate projection
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, window_width, 0, window_height, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
# world XY coordinates now map to viewport XY
Keep in mind that immediate mode (glBegin(...); for(...){ glVertex(...); } glEnd();
) is slow and deprecated. Use Vertex Arrays and Vertex Buffer Objects instead.
For normal coordinates, trying to get a 1:1 mapping from input numbers to pixel coordinates doesn't make much sense. In particular, all three coordinates interact with your projection matrix to map from a coordinate to a pixel position on screen.
OpenGL does have some bitmap functions (e.g., glBitmap
, glDrawPixels
) that let you work directly in pixel coordinates. Without knowing what you're trying to accomplish, it's hard to guess whether that'll be useful for you.
精彩评论