资源简介
OpenGL 3D 贪吃蛇程序,适合初学者学习

代码片段和文件信息
// example003.cpp : 定义控制台应用程序的入口点。
//
/*==================================================================================*/
/* Computer Graphics Final Project: Snake */
/* Prepared By: Salim AWAD */
/*-http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=254315*/
/*==================================================================================*/
/*Include Files*/
#include “stdafx.h“
#include
#include
#include
#include
#define UP 1
#define Down 2
#define LEFT 3
#define RIGHT 4
// Status Variables
GLint lvl = 1;
GLint points = 0;
GLint size = 0;
GLbyte gameOver = true;
GLbyte EnableLight = true;
// Snake Variables
GLint bodyPos[2][100] = {{}};
GLint _x = 5;
GLint _z = 10;
GLint _oldX[2] = {};
GLint _oldZ[2] = {};
GLbyte direction = 0;
// Food Variables
GLint _bx = 0;
GLint _bz = 0;
// Screen variables
GLint _w = 800;
GLint _h = 550;
GLint _Giw = 0;
GLint _Gih = 0;
GLint _Gfw = 150;
GLint _Gfh = 150;
//Variables for the Camera Angle
static GLfloat view_rotx=45.0F ;
static GLfloat view_roty=0.0F ;
static GLfloat view_rotz=0.0F ;
static GLfloat headRotation=90.0F ;
static GLfloat zoom=-300.0F ;
// Variables to check the FPS
DWORD g_dwLastFPS = 0;
int g_nFPS = 0 g_nframes = 0;
//Configure the lightning
void initLight()
{
//Add ambient light
GLfloat ambientColor[] = {0.3f 0.4f 0.5f 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT ambientColor);
//Add positioned light
GLfloat lightColor0[] = {0.5f 0.5f 0.5f 1.0f};
GLfloat lightPos0[] = {4.0f 0.0f 8.0f 1.0f};
glLightfv(GL_LIGHT0 GL_DIFFUSE lightColor0);
glLightfv(GL_LIGHT0 GL_POSITION lightPos0);
//Add directed light
GLfloat lightColor1[] = {0.5f 0.2f 0.2f 1.0f};
//Coming from the direction (-1 0.5 0.5)
GLfloat lightPos1[] = {-1.0f 0.5f 0.5f 0.0f};
glLightfv(GL_LIGHT1 GL_DIFFUSE lightColor1);
glLightfv(GL_LIGHT1 GL_POSITION lightPos1);
}
//initialize the first configurations
void Initialize(void)
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.7f 0.9f 1.0f 1.0f); //Change the background to sky blue
if(EnableLight){
glEnable(GL_COLOR_MATERIAL); //Enable color
glEnable(GL_LIGHTING); //Enable lighting
glEnable(GL_LIGHT0); //Enable light #0
glEnable(GL_LIGHT1); //Enable light #1
glEnable(GL_NORMALIZE); //Automatically normalize normals
}
}
//Configure window resize
void resize (int w int h)
{
glViewport(0 0 w h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0 (double)w / (double)h 1 800.0);
}
void Write(char *string){//Write string on the screen
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-03-11 12:23 example003\
目录 0 2014-03-11 12:22 example003\debug\
文件 49152 2014-03-11 12:06 example003\debug\example003.exe
文件 391232 2014-03-11 12:06 example003\debug\example003.ilk
文件 412672 2014-03-11 12:06 example003\debug\example003.pdb
目录 0 2014-03-11 12:22 example003\example003\
文件 4000768 2014-03-11 12:23 example003\example003.ncb
文件 895 2014-03-10 17:13 example003\example003.sln
文件 9216 2014-03-10 17:16 example003\example003.suo
目录 0 2014-03-11 12:22 example003\example003\Debug\
文件 10086 2014-03-11 12:06 example003\example003\Debug\BuildLog.htm
文件 403 2014-03-11 12:02 example003\example003\Debug\example003.exe.em
文件 468 2014-03-11 12:02 example003\example003\Debug\example003.exe.em
文件 385 2014-03-11 12:06 example003\example003\Debug\example003.exe.intermediate.manifest
文件 46761 2014-03-11 12:06 example003\example003\Debug\example003.obj
文件 1179648 2014-03-11 12:02 example003\example003\Debug\example003.pch
文件 65 2014-03-11 12:06 example003\example003\Debug\mt.dep
文件 11805 2014-03-11 12:02 example003\example003\Debug\stdafx.obj
文件 183296 2014-03-11 12:06 example003\example003\Debug\vc80.idb
文件 118784 2014-03-11 12:06 example003\example003\Debug\vc80.pdb
文件 12540 2014-03-11 12:06 example003\example003\example003.cpp
文件 4496 2014-03-10 17:13 example003\example003\example003.vcproj
文件 1409 2014-03-11 12:06 example003\example003\example003.vcproj.zjc-PC.zjc.user
文件 968 2014-03-10 17:13 example003\example003\ReadMe.txt
文件 215 2014-03-10 17:13 example003\example003\stdafx.cpp
文件 314 2014-03-11 12:02 example003\example003\stdafx.h
- 上一篇:广工数据结构实验
- 下一篇:基于STM32F07单片机风洞程序
相关资源
- OpenGL参考手册
- The Secret Path 3D 3D魔方迷宫[源码][scra
-
Actionsc
ript 1.0实现能跟随鼠标运动的 - Qt Creator opengl实现四元数鼠标控制轨迹
- Unity3D登录界面工程
- 3DWebGIS 3DWebGIS
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 3des加解密_C 实现
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- unity3d反编译工具
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- Quest3D 2个动画相机切换实例
- OpenGL导入贴图的Texture类
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- FLAC3D数值模拟的边坡稳定性
-
UnityWebPla
yerFull - Scratch:3d飞行模拟器 .sb3
- OPENGL实现世界上最小的3D游戏
- 亲子嘉年华路演活动模型
- 基于GTP修正的R3DGM建模与可视化方法
- 通过3D打印样品发现NMR曲线的不同姿态
- 3维泊松表面重建
评论
共有 条评论