gpt4 book ai didi

opengl - 我的 gluSphere 缺少补丁

转载 作者:行者123 更新时间:2023-12-04 18:22:37 24 4
gpt4 key购买 nike

我正在尝试使用 gluSphere 绘制一个球体。球体出现了,但无论我将其绘制为填充多边形还是线框,都缺少某些补丁。

int width=800, height=600;

void myinit(void)
{
// set up overall light data, including specular=ambient=light colors
GLfloat light_position[]={ 10.0, 10.0, -10.0, 1.0 };
GLfloat light_color[]={ 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient_color[]={ 0.0, 0.2, 0.2, 1.0 };
GLfloat mat_specular[]={ 1.0, 1.0, 1.0, 1.0 };

glClearColor( 0.0, 1.0, 1.0, 0.0 );
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular );
glLightfv(GL_LIGHT0, GL_POSITION, light_position );
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color );
glLightfv(GL_LIGHT0, GL_SPECULAR, light_color );
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color );

/* attributes */
glEnable(GL_LIGHTING); // so lighting models are used
glEnable(GL_LIGHT0); // we'll use LIGHT0
glEnable(GL_DEPTH_TEST); // allow z-buffer display
//glClearDepth(1);
}

void drawHead(){
GLUquadric *sphere=gluNewQuadric();
gluQuadricDrawStyle( sphere, GLU_FILL);
gluQuadricNormals( sphere, GLU_SMOOTH);
gluQuadricOrientation( sphere, GLU_OUTSIDE);
gluQuadricTexture( sphere, GL_TRUE);

//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glPushMatrix();
glTranslated(0,0,-5);
glRotated(30,1,1,1);
gluSphere(sphere,2.0,15,15);
glPopMatrix();
}

void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
drawHead();
glutSwapBuffers();
}

void main(int argc, char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(width,height);
glutInitWindowPosition(100,200);
glutCreateWindow("Automaton");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,1.0,0.0,20);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
myinit();
glutDisplayFunc(display);

glutMainLoop();

}

最佳答案

根据文档,"...zNear must never be set to 0."

把你的 zNear 调大一点,把你的 zFar 调大一点:

gluPerspective( 90.0, 1.0, 1.0, 200.0 );

完成:

#include <GL/glut.h>

int width=800, height=600;

void myinit(void)
{
// set up overall light data, including specular=ambient=light colors
GLfloat light_position[]={ 10.0, 10.0, -10.0, 1.0 };
GLfloat light_color[]={ 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient_color[]={ 0.0, 0.2, 0.2, 1.0 };
GLfloat mat_specular[]={ 1.0, 1.0, 1.0, 1.0 };

glClearColor( 0.0, 1.0, 1.0, 0.0 );
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular );
glLightfv(GL_LIGHT0, GL_POSITION, light_position );
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color );
glLightfv(GL_LIGHT0, GL_SPECULAR, light_color );
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color );

/* attributes */
glEnable(GL_LIGHTING); // so lighting models are used
glEnable(GL_LIGHT0); // we'll use LIGHT0
glEnable(GL_DEPTH_TEST); // allow z-buffer display
}

void drawHead()
{
GLUquadric *sphere=gluNewQuadric();
gluQuadricDrawStyle( sphere, GLU_FILL);
gluQuadricNormals( sphere, GLU_SMOOTH);
gluQuadricOrientation( sphere, GLU_OUTSIDE);
gluQuadricTexture( sphere, GL_TRUE);

glPushMatrix();
glTranslated(0,0,-5);
glRotated(30,1,1,1);
gluSphere(sphere,2.0,15,15);
glPopMatrix();
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
drawHead();
glutSwapBuffers();
}

void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(width,height);
glutInitWindowPosition(100,200);
glutCreateWindow("Automaton");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 90.0, 1.0, 1.0, 200.0 );

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
myinit();
glutDisplayFunc(display);

glutMainLoop();
}

关于opengl - 我的 gluSphere 缺少补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868215/

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