资源简介
opengl通过键盘对3d图像进行颜色,光照,旋转等变化,VS2013上可运行,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化,opengl通过键盘对3d图像进行颜色,光照,旋转等变化
![](http://www.nz998.com/pic/58593.jpg)
代码片段和文件信息
// pratice.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include
#include
#include
#include
#include
#include
#include
using namespace std;
GLfloat position[] = { 1.0 1.0 5.0 0.0 };
void init(void)
{
GLfloat ambient[] = { 0.0 0.0 0.0 1.0 };
GLfloat diffuse[] = { 1.0 1.0 1.0 1.0 };
GLfloat specular[] = { 1.0 1.0 1.0 1.0 };
//光源位置
GLfloat lmodel_ambient[] = { 0.2 0.2 0.2 1.0 };
GLfloat local_view[] = { 0.0 };
glLightfv(GL_LIGHT0 GL_AMBIENT ambient);
glLightfv(GL_LIGHT0 GL_DIFFUSE diffuse);
glLightfv(GL_LIGHT0 GL_POSITION position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER local_view);
glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
}
int N = 0;
GLfloat mat[3][4] = { { 0.1 0.1 0.1 } { 0.5 0.1 0.9 } { 0.3 0.9 0.9 } };
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(4 8 0.0);
//teapot的颜色
glMaterialfv(GL_FRONT GL_DIFFUSE mat[N]);
glutSolidTeapot(3.0);
glPopMatrix();
glFlush();
}
void reshape(int w int h)
{
glViewport(0 0 (GLsizei)w (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(0.0 16.0 0.0 16.0*(GLfloat)h / (GLfloat)w
-10.0 10.0);
else
glOrtho(0.0 16.0*(GLfloat)w / (GLfloat)h 0.0 16.0
-10.0 10.0);
glMatrixMode(GL_MODELVIEW);
}
void rotation(int x)
{
glRotatef(2 0.0f 1.0f 0.0f);
glutPostRedisplay();
glutTimerFunc(100 rotation 1);
}
void keyboard(unsigned char key int x int y)
{
switch (key) {
case ‘a‘:
exit(0);
break;
case 27:
exit(0);
break;
}
if (key == 99)
{
glutPostRedisplay();
N++;
if (N > 3)
N = 0;
}
if (key == 114){
glutTimerFunc(100 rotation 1);
cout << “Unhandled key press r“ << endl;
}
}
void keyboard1(int key int x int y)
{
if (key == GLUT_KEY_RIGHT)
{
position[0] = position[0] + 0.5;
init();
glutPostRedisplay();
}
if (key == GLUT_KEY_LEFT)
{
position[0] = position[0] - 0.5;
init();
glutPostRedisplay();
}
if (key == GLUT_KEY_UP) {
position[1] = position[1] + 0.5;
init();
glutPostRedisplay();
}
if (key == GLUT_KEY_DOWN)
{
position[1] = position[1] - 0.5;
init();
glutPostRedisplay();
}
}
/*void obj::parse(const char*filename)
{
string s;
ifstream fin(“cube.obj“);
if (!fin)
return;
while (fin >> s)
{
switch (*s.c_str())
{
case‘v‘:
{
vertex v;
fin >> v.x >> v.y >> v.z;
this->vertexs.push_back(v);
}
break;
case‘f‘:
{
face f;
fin >> f.v1 >> f.v2 >> f.v3;
faces.push_back(f);
}
break;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 29264 2005-08-29 13:03 pratice\bunny_1k.obj
文件 5410 2005-08-29 13:03 pratice\bunny_200.obj
文件 172 2005-08-29 13:03 pratice\cube.obj
文件 949 2017-09-06 17:43 pratice\Debug\pratice.Build.CppClean.log
文件 2753 2017-09-10 19:44 pratice\Debug\pratice.log
文件 180209 2017-09-10 19:44 pratice\Debug\pratice.obj
文件 1638400 2017-09-06 17:43 pratice\Debug\pratice.pch
文件 1898 2017-09-10 19:44 pratice\Debug\pratice.tlog\cl.command.1.tlog
文件 18044 2017-09-10 19:44 pratice\Debug\pratice.tlog\CL.read.1.tlog
文件 1078 2017-09-10 19:44 pratice\Debug\pratice.tlog\CL.write.1.tlog
文件 2036 2017-09-10 19:44 pratice\Debug\pratice.tlog\li
文件 3880 2017-09-10 19:44 pratice\Debug\pratice.tlog\li
文件 572 2017-09-10 19:44 pratice\Debug\pratice.tlog\li
文件 168 2017-09-10 19:44 pratice\Debug\pratice.tlog\pratice.lastbuildstate
文件 11169 2017-09-06 17:43 pratice\Debug\stdafx.obj
文件 543744 2017-09-10 19:44 pratice\Debug\vc120.idb
文件 503808 2017-09-10 19:44 pratice\Debug\vc120.pdb
文件 225 2017-09-06 17:06 pratice\packages.config
文件 3760 2017-09-10 19:46 pratice\pratice.cpp
文件 5035 2017-09-10 15:08 pratice\pratice.vcxproj
文件 1474 2017-09-10 15:08 pratice\pratice.vcxproj.filters
文件 2329 2017-09-10 20:01 pratice\ReadMe.txt
文件 351 2017-09-10 15:41 pratice\readobj.h
文件 213 2017-09-06 17:01 pratice\stdafx.cpp
文件 234 2017-09-06 17:01 pratice\stdafx.h
文件 236 2017-09-06 17:01 pratice\targetver.h
目录 0 2017-09-10 19:44 pratice\Debug\pratice.tlog
目录 0 2017-09-10 19:44 pratice\Debug
目录 0 2017-09-10 20:01 pratice
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:无碳小车资料
- 下一篇:Weblogic漏洞扫描工具
相关资源
- OpenGL参考手册
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- OPENGL实现世界上最小的3D游戏
- VS2012OpenGL配置所需要的全部libdllh文件
- 基于OpenGL的仿蝗虫机器人三维动态仿
- 图形学 - OpenGL实现3种三维茶壶显示源
- opengl程序-会跳舞的骷髅
- opengl实现三维网格光顺Laplacian算法
- opengl——爆炸
- OpenGL三维地形建模
- opengl游戏编程徐明亮版(含源码)
- 用OPENGL画的一个简单的直升飞机
- opengl完美天空盒
- 3D绘图程序设计:使用Direct3D 10/9和Ope
- OpenGL绘制可运动自行车源程序.zip
- OpenGL实现飘动效果
- opengl室内场景的绘制,包括碰撞检测
评论
共有 条评论