gpt4 book ai didi

c - GLUT不会画画

转载 作者:太空宇宙 更新时间:2023-11-04 04:54:23 24 4
gpt4 key购买 nike

当我尝试绘制环面时,没有任何显示,但代码在我 friend 的 PC 上运行完美。我在绘制立方体或其他简单形状时没有问题。我忘记了什么或者可能是什么问题?

代码:

#include <GL/glut.h>
#include <stdio.h>


GLint width = 600;
GLint height = 600;

GLdouble eyex = 3.0, eyey = 0.0, eyez = 5.0;
GLdouble atx = 0.0, aty = 0.0, atz = 0.0;
GLdouble vupx = 0.0, vupy = 1.0, vupz = 0.0;

GLdouble fovy = 120.0, aspect = 1.0, Znear = 1.0, Zfar = 10.0;

GLfloat position[] = {10.0, 0.0, 1.5, 10.0 };


static void display(void)
{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5,0.1,1.1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyex, eyey, eyez, atx, aty, atz, vupx, vupy, vupz);
glColor3f(1.0,0.0,0.0);


glutSolidTorus(1.0,2.0,100,100);
glFlush();

}


void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_FLAT);
}


void reshape(int winw, int winh) {
glViewport(0,0,winw,winh); //Otvor
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy, aspect, Znear, Zfar);

}

static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
exit(0);
break;
}
}

void mouse(int button, int state, int x, int y)
{

if (button == GLUT_LEFT_BUTTON)
{
glPushMatrix();
glRotatef(60,0.0,5.0,0.0);;

glLightfv(GL_LIGHT0,GL_POSITION,position);
glPopMatrix();
glFlush();
}
}


int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(width,height);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutCreateWindow("Light");
init();

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glLightfv(GL_LIGHT0,GL_POSITION,position);


glutKeyboardFunc(key);
glutMainLoop();

//return EXIT_SUCCESS;
//return exit_success;
}

最佳答案

请求深度缓冲区:

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);

并确保清除它:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

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