gpt4 book ai didi

c - GLUT 问题

转载 作者:太空宇宙 更新时间:2023-11-04 03:06:09 26 4
gpt4 key购买 nike

当我编译后尝试运行这段代码时,我得到的只是一个没有内容的窗口边框,那么错误在哪里?

注意:我用的是ubuntu和gcc编译

gcc -lglut  Simple.c -o Simple

The output

#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();
}

最佳答案

尝试在 RenderScene() 的末尾添加一个 glutSwapBuffers()

关于c - GLUT 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4914315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com