|
|
发表于 2004-11-29 13:06:00
|
显示全部楼层
Re:还是OpenGL模拟2D的问题
改成gluOrtho2D试试?与投影正交那一个环节有关,那个环节我也很弱,但是我手上有个例子,我用了很久没发现这样问题
void setOrthographicProjection() {
// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, w, 0, h);
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -h, 0);
glMatrixMode(GL_MODELVIEW);
}
void resetPerspectiveProjection() {
// set the current matrix to GL_PROJECTION
glMatrixMode(GL_PROJECTION);
// restore previous settings
glPopMatrix();
// get back to GL_MODELVIEW matrix
glMatrixMode(GL_MODELVIEW);
}
在redraw中
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
glColor3f(1.0f,0.5f,0.0f);
glBegin(GL_LINES);
glVertex2f(0.5*w-7, 0.5*h);
glVertex2f(0.5*w+7, 0.5*h);
glVertex2f(0.5*w, 0.5*h+7);
glVertex2f(0.5*w, 0.5*h-7);
glEnd();
glPopMatrix();
resetPerspectiveProjection(); |
|