计算机图形学与三维建模实验报告
- 格式:docx
- 大小:12.82 KB
- 文档页数:11
计算机图形学实验报告
openGL的基本使用
1.项目代码:
// : 定义控制台应用程序的入口点。
#include""
#include
#include<>
#include
#include
#include
using namespace std;
//#include"" 编程宝典第8版库函数
//#include""
GLfloat x=,y=,z=;//用于平移的变量
GLfloat i=,j=,k=;//用于缩放的变量
int d=1;//用于是否判断旋转的开关
GLfloat angle=;//旋转角度的变量
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 创建透视效果视图
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective, , , ;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt, , , , , , , , ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 定义4光源,从4个方向入射,第一个是白光,其他为红绿蓝{
GLfloat sun_light_position[] = { , , , };
GLfloat sun_light_position1[] = { , , , };
GLfloat sun_light_position2[] = { , , , };
GLfloat sun_light_position3[] = { , , , };
GLfloat sun_light_ambient[] = { , , , };
GLfloat sun_light_diffuse[] = { , , , };
GLfloat sun_light_diffuse1[] = { , , , };
GLfloat sun_light_diffuse2[] = { , , , };
GLfloat sun_light_diffuse3[] = { , , , };
GLfloat sun_light_specular[] = { , , , };
glLightfv(GL_LIGHT0, GL_POSITION, sun_light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, sun_light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, sun_light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun_light_specular);
glLightfv(GL_LIGHT1, GL_POSITION, sun_light_position1);
glLightfv(GL_LIGHT1, GL_AMBIENT, sun_light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, sun_light_diffuse1);
glLightfv(GL_LIGHT1, GL_SPECULAR, sun_light_specular);
glLightfv(GL_LIGHT2, GL_POSITION, sun_light_position2);
glLightfv(GL_LIGHT2, GL_AMBIENT, sun_light_ambient);
glLightfv(GL_LIGHT2, GL_DIFFUSE, sun_light_diffuse2);
glLightfv(GL_LIGHT2, GL_SPECULAR, sun_light_specular);
glLightfv(GL_LIGHT3, GL_POSITION, sun_light_position3);
glLightfv(GL_LIGHT3, GL_AMBIENT, sun_light_ambient);
glLightfv(GL_LIGHT3, GL_DIFFUSE, sun_light_diffuse3);
glLightfv(GL_LIGHT3, GL_SPECULAR, sun_light_specular);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
//绘制坐标轴
{
glBegin(GL_LINE);
//x轴红色
glColor3f(1,0,0);
glVertex3f(10,0,0);
glVertex3f(-10,0,0);
//y轴绿色
glColor3f(0,1,0);
glVertex3f(0,10,0);
glVertex3f(0,-10,0);
//z轴蓝色
glColor3f(0,0,1);
glVertex3f(0,0,10);
glVertex3f(0,0,-10);
glEnd();
}
// 定义球体的材质并绘制
{
GLfloat ambient[] = { , , , };//环境颜色
GLfloat diffuse[] = { , , , };//散射颜色
GLfloat specular[] = { , , , };//镜面反射
GLfloat emission[] = { , , , };//发射光颜色
GLfloat hininess = ; //反射指数