计算机图形学与三维建模实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

计算机图形学实验报告

openGL的基本使用

1.项目代码:

// 2321321.cpp : 定义控制台应用程序的入口点。

#include"stdafx.h"

#include

#include

#include

#include

#include

using namespace std;

//#include"vgl.h" opengl4.3 编程宝典第8版库函数

//#include"loadshaders.h"

GLfloat x=0.0,y=0.0,z=0.0;//用于平移的变量

GLfloat i=1.0,j=1.0,k=1.0;//用于缩放的变量

int d=1;//用于是否判断旋转的开关

GLfloat angle=0.0f;//旋转角度的变量

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// 创建透视效果视图

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(90.0f, 1.0f, 1.0f, 20.0f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// 定义4光源,从4个方向入射,第一个是白光,其他为红绿蓝{

GLfloat sun_light_position[] = { -5.0f, 5.0f, 0.0f, 1.0f };

GLfloat sun_light_position1[] = { 5.0f, 5.0f, 0.0f, 1.0f };

GLfloat sun_light_position2[] = { -5.0f, -5.0f, 0.0f, 1.0f };

GLfloat sun_light_position3[] = { 5.0f, -5.0f, 0.0f, 1.0f };

GLfloat sun_light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };

GLfloat sun_light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };

GLfloat sun_light_diffuse1[] = { 1.0f, 0.0f, 0.0f, 1.0f };

GLfloat sun_light_diffuse2[] = { 0.0f, 1.0f, 0.0f, 1.0f };

GLfloat sun_light_diffuse3[] = { 0.0f, 0.0f, 1.0f, 1.0f };

GLfloat sun_light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };

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);

相关文档
最新文档