问题GLUT [英] Problem with GLUT
本文介绍了问题GLUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试编译后运行该code,我只拿到了没有内容的窗口边框,所以在哪里错误?
注:我使用Ubuntu和gcc编译
GCC -lglut Simple.c -o简单
的#include< GL / glut.h> //头文件过剩图书馆
#包括LT&; GL / gl.h> //头文件OpenGL库
#包括LT&; GL / glu.h> //头文件的GLU库无效SetupRC(无效);
无效RenderScene(无效);
无效ChangeSize(GLsizei W,GLsizei H);//调用来绘制场景
无效RenderScene(无效)
{
//清除当前结算颜色窗口
glClear(GL_COLOR_BUFFER_BIT); //设置颜色为这些值
// R G B
glColor3f(56.0f,19.0f,68.0f); //绘制与当前颜色填充矩形
glRectf(-25.0f,50.0f,50.0f,-25.0f); //嵌入式绘图命令
glFlush();
}INT主(INT ARGC,CHAR *的argv [])
{
glutInit(安培; ARGC,ARGV);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(400,200);
glutInitWindowSize(640468);
glutCreateWindow(简单);
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize); SetupRC();
glutMainLoop(); 返回0;
}//设置渲染状态
无效SetupRC(无效)
{
glClearColor(0.0,2.0F,1.0F,0.0);
}//处理窗口大小调整
无效ChangeSize(GLsizei W,GLsizei高)
{
GLfloat的aspectRatio; // $ P零$ pvent鸿沟
如果(H == 0)
H = 1; //设置视口窗口尺寸
glViewport(0,0,W,H); //重置坐标系
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //建立裁剪量(左,右,底,顶,近,远)
的aspectRatio =(GLfloat)W /(GLfloat)H;
如果(W&所述= H){
glOrtho(-100.0,100.0,-100 /的aspectRatio,100.0 /的aspectRatio,1.0,-1.0);
}
其他
glOrtho(-100.0 *的aspectRatio,100.0 *的aspectRatio,-100.0,100.0,1.0,-1.0); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
解决方案
尝试添加 glutSwapBuffers()
到年底RenderScene()
。
When i try to run this code after compiling it, i got only a window border without content, so where is the error?
Note: i am using ubuntu and gcc for compiling
gcc -lglut Simple.c -o Simple
#include <GL/glut.h> // Header File For The GLUT Library
#include <GL/gl.h> // Header File For The OpenGL Library
#include <GL/glu.h> // Header File For The GLu Library
void SetupRC(void);
void RenderScene(void);
void ChangeSize(GLsizei w, GLsizei h);
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// set the color to these values
// R G B
glColor3f(56.0f, 19.0f,68.0f);
// Draw a filled rectangle with current color
glRectf(-25.0f, 50.0f, 50.0f, -25.0f);
// Flush drawing commands
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(400,200);
glutInitWindowSize(640,468);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 2.0f, 1.0f, 0.0f);
}
// Handling window resizing
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
// Prevent divide by zero
if (h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Establish clipping volume (left, right, bottom, top, near, far)
aspectRatio = (GLfloat) w / (GLfloat) h;
if (w <= h) {
glOrtho(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
}
else
glOrtho(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
解决方案
Try adding a glutSwapBuffers()
to the end of RenderScene()
.
这篇关于问题GLUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文