一个opengl初学者的烦恼:简单的画一条直线问题
我现在画一条直线,在vc++下用MfcAppwizardJ建立了一个工程,
void CMyTestView::DrawScene()
{
glClearColor(0.5f,0.6f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1.0,1.0);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glBegin(GL_LINES);
glVertex2f(0.1f,0.1f);
glVertex2f(0.6f,0.6f);
glEnd();
}
上面的代码运行也没有错误,并且执行glClearColor(0.5f,0.6f,0.0f,1.0f); 背景颜色也变了,但执行画线操作glBegin(GL_LINES);
glVertex2f(0.1f,0.1f);
glVertex2f(0.6f,0.6f);
glEnd();
怎么这条直线不显示呀,昨天弄了一天也没找出毛病,恳求高手指教,谢谢大家了!
[解决办法]
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1, 0.0,1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
去掉你的glortho,在初始化时调用上面几句,wh是你窗口和宽高.
[解决办法]
最后要交换缓存区
用glutSwapBuffers()