View Full Version : Line vertex positions are not correct
06-21-2010, 08:25 AM
Hi, if i render a line with the following code:
i get an line at position (51, 11) and (51, 50).
Can anyone explain me this behavior?
I tried to substract the half line width but the result isn't correct, too.
glVertex2d(50 - 0.5, 10 - 0.5);
glVertex2d(50 - 0.5, 50 - 0.5);
I get the positions (50, 10) and (50, 49). Whats wrong with this?
06-21-2010, 10:44 AM
In general the values you pass to glVertex2d (note: the 'd' suffix here is to indicate you pass 'double' values instead of floats, not that you are drawing in window coordinates) are in object space coordinates. The location that gets drawn on your screen depends on the current modelview and projection matrices as well as on your viewport setup.
How do you set up modelview, projection and viewport?
06-21-2010, 11:40 AM
The code for resizing looks like this:
void Window::ReSizeGLScene(int iWidth, int iHeight)
m_iWidth = iWidth;
m_iHeight = iHeight;
glViewport(0, 0, (GLsizei)iWidth,(GLsizei)iHeight);
gluPerspective(45.0f, (GLdouble)iWidth / (GLdouble)iHeight, 0.1, 100.0);
Switching to the "2D-Mode" is done with this code:
glOrtho(0, m_iWidth, m_iHeight, 0, 0.0, 100.0);
Using glVertex2i or glVertex2d makes no difference.
06-21-2010, 08:46 PM
You can adjust the ortho border values to align the edges of the viewport to specific numerical values, but also understand that rendering is a binary thing. If you're pixel center is out be epsilon it will not hit the pixel on a polygon edge if exactly aligned, for lines the fill rules are naturally different and it should touch the pixel.
This 'correct' way to align this is to adjust the ortho values.
06-23-2010, 07:11 AM
I found this
glTranslated(0.5, 0.5, 0.0);
which works fine, because the center of a line now is located at pixel positions. Certainly I found out that for example
draws two lines with an width from 50. But the last one has an width from 51. Thats confusing.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.