以下是我的代碼和運行結果截圖,圖片中是有一個Sphere和一個Teapot組成,
想知道如何將圖片中兩個物體分開展示#include <GL/GLUT.h>
#include <math.h>
GLfloat light_diffuse[] = { 1.0, 0.0, 0.5, 1.0 }; /* Red diffuse light. */
GLfloat light_position[] = { 1.0, 0.0, 1.0, 0.0 }; /* Infinite light location. */
GLfloat v[8][3]; /* Will be filled in with X,Y,Z vertexes. */
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere(1,100,100);
glutSolidTeapot(1);
glutSwapBuffers();
}
void
init(void)
{
/* Enable a single OpenGL light. */
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
/* Use depth buffering for hidden surface elimination. */
glEnable(GL_DEPTH_TEST);
/* Setup the view of the cube. */
glMatrixMode(GL_PROJECTION);
gluPerspective( /* field of view in degree */ 40.0,
/* aspect ratio */ 1.0,
/* Z near */ 1.0, /* Z far */ 10.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 2.0, 8.0, /* eye is at (0,0,8) */
0.0, 0.0, 0.0, /* center is at (0,0,0) */
0.0, 1.0, 0.); /* up is in positive Y direction */
/* Adjust cube position to be asthetic angle. */
glTranslatef(0.0, 0.0, -1.0);
glRotatef(45, 1.0, 0.3, 1.0);
glRotatef(0, 0.0, 0.0, 1.0);
}
int
main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("111");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/54112.html
標籤:圖象工具使用
