PDA

View Full Version : Lines slightly shifting around after resize



Jorufo
05-31-2007, 03:22 PM
I'm currently displaying parallel lines on the screen, and whenever I resize, the lines shift just a little bit. They move a little closer together or a little farther apart each time I resize. Further, the way they shift is never constant, i.e. the lines don't always/only move farther away each time, nor closer together. Does this have to do with a limitation on the precision that opengl can display things? I am not playing with any projections as this is in 2D.

ZbuffeR
05-31-2007, 03:45 PM
Does this have to do with a limitation on the precision that opengl can display things?No. Probably your code or the way you use the API is not efficient.
Do you have screenshots, more details, or even some code ?

Jorufo
05-31-2007, 04:27 PM
sure, it is code as simple as this
glNewList(displayListID, GL_COMPILE_AND_EXECUTE);

glDisable(GL_POINT_SMOOTH);
glDisable(GL_LINE_SMOOTH);

glColor3f(0,0,0);


glBegin(GL_LINES);

//Now draw the measures lines
glVertex2f(xPos,yPos);
glVertex2f(xPos + width, yPos);

glVertex2f(xPos, yPos - containingStaff->getSpacing());
glVertex2f(xPos + width, yPos - containingStaff->getSpacing());

glVertex2f(xPos,yPos - (2*containingStaff->getSpacing()));
glVertex2f(xPos + width, yPos - (2*containingStaff->getSpacing()));

glVertex2f(xPos,yPos - (3*containingStaff->getSpacing()));
glVertex2f(xPos + width, yPos - (3*containingStaff->getSpacing()));

glVertex2f(xPos,yPos - (4*containingStaff->getSpacing()));
glVertex2f(xPos + width, yPos - (4*containingStaff->getSpacing()));

glEnd();


glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);

glEndList();

later the display list is called to show the lines. The resize function is as follows:

void ChangeSize(int w, int h)
{

// Prevent a divide by zero
if(h == 0)
{
h = 1;
}

// Set Viewport to window dimensions
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();


gluOrtho2D(-800.0f, 800.0f, -800.0f, 800.0f);

// Modelview matrix reset
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}