OpenGL glRectf() 不显示
Posted
技术标签:
【中文标题】OpenGL glRectf() 不显示【英文标题】:OpenGL glRectf() not displaying 【发布时间】:2015-11-02 00:10:17 【问题描述】:glRectf() 没有显示在我的窗口中:
#include <GL/gl.h>
#include <GL/glut.h>
void renderScene()
glClearColor(0.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glRectf(225.0f,150.0f,150.0f,100.0f);
glFlush();
int main(int argc, char*argv[])
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(450, 350);
glutCreateWindow("My first OpenGL Program...took forever");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
【问题讨论】:
【参考方案1】:(225.0f,150.0f) 与恒等平截头体相去甚远。
提供一些适当的变换矩阵,这样你的矩形就不会被剪裁:
#include <GL/glut.h>
void renderScene()
glClearColor(0.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -300, 300, -300, 300, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glColor3f(1.0f,0.0f,0.0f);
glRectf(225.0f,150.0f,150.0f,100.0f);
glFlush();
int main(int argc, char*argv[])
glutInit( &argc, argv );
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(450, 350);
glutCreateWindow("My first OpenGL Program...took forever");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
【讨论】:
谢谢,明天放学回来试试以上是关于OpenGL glRectf() 不显示的主要内容,如果未能解决你的问题,请参考以下文章