用opengl实现的正六面体贴图,每面的图形都不一样,图像文件存放在Data文件夹下。
使用vs2005及以上版本编译。
按键盘上的上、下、左、右可实现六面体旋转的方向及速度。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9620480 2010-09-22 14:49 Lesson6.ncb
文件 48640 2009-09-06 10:44 Lesson6.opt
文件 878 2010-09-22 14:45 Lesson6.sln
..A..H. 8192 2010-09-22 14:49 Lesson6.suo
文件 5552 2010-09-22 14:45 lesson6.vcproj
文件 1407 2010-09-22 14:49 lesson6.vcproj.WANZY.love.user
文件 530 2000-02-02 20:50 NeHe‘s Readme.txt
文件 786486 2008-12-08 16:25 Data1.bmp
文件 786486 2008-12-08 16:25 Data2.bmp
文件 786486 2008-12-08 16:26 Data3.bmp
文件 786486 2008-12-08 15:38 Data4.bmp
文件 786486 2008-12-08 15:34 Data5.bmp
文件 196664 2000-03-06 02:10 Data6.bmp
..A.SHR 9 2009-08-12 17:29 DataDesktop_.ini
..A.SH. 30208 2009-09-06 10:39 DataThumbs.db
文件 19825 2008-12-08 18:57 Lesson6.cpp
目录 0 2010-09-22 14:48 Data
----------- --------- ---------- ----- ----
13864815 17
/*
* This Code Was Created By Jeff Molofee 2000
* A HUGE Thanks To Fredric Echols For Cleaning Up
* And Optimizing The base Code Making It More Flexible!
* If You‘ve Found This Code Useful Please Let Me Know.
* Visit My Site At nehe.gamedev.net
*/
#include // Header File For Windows
#include // Header File For Standard Input/Output
#include // Header File For The OpenGL32 Library
#include // Header File For The GLu32 Library
#include // Header File For The Glaux Library
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
GLfloat xrot; // X Rotation ( NEW )
GLfloat yrot; // Y Rotation ( NEW )
GLfloat zrot; // Z Rotation ( NEW )
GLuint texture[6]; // Storage For One Texture ( NEW )
LRESULT CALLBACK WndProc(HWND UINT WPARAM LPARAM); // Declaration For WndProc
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename“r“); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
int i;
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage0sizeof(void *)*1); // Set The Pointer To NULL
glGenTextures(6&texture[0]);
// Load The Bitmap Check For Errors If Bitmap‘s Not Found Quit
char *Imagename[6]={“Data/1.bmp““Data/2.bmp““Data/3.bmp““Data/4.bmp““Data/5.bmp““Data/6.bmp“};
for(i=0;i<6;i++)
{
if (TextureImage[0]=LoadBMP(*(Imagename+i)))
{
Status=TRUE; // Set The Status To TRUE
// glGenTextures(1 &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D texture[i]);
glTexImage2D(GL_TEXTURE_2D 0 3 TextureImage[0]->sizeX TextureImage[0]->sizeY 0 GL_RGB GL_UNSIGNED_BYTE TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9620480 2010-09-22 14:49 Lesson6.ncb
文件 48640 2009-09-06 10:44 Lesson6.opt
文件 878 2010-09-22 14:45 Lesson6.sln
..A..H. 8192 2010-09-22 14:49 Lesson6.suo
文件 5552 2010-09-22 14:45 lesson6.vcproj
文件 1407 2010-09-22 14:49 lesson6.vcproj.WANZY.love.user
文件 530 2000-02-02 20:50 NeHe‘s Readme.txt
文件 786486 2008-12-08 16:25 Data1.bmp
文件 786486 2008-12-08 16:25 Data2.bmp
文件 786486 2008-12-08 16:26 Data3.bmp
文件 786486 2008-12-08 15:38 Data4.bmp
文件 786486 2008-12-08 15:34 Data5.bmp
文件 196664 2000-03-06 02:10 Data6.bmp
..A.SHR 9 2009-08-12 17:29 DataDesktop_.ini
..A.SH. 30208 2009-09-06 10:39 DataThumbs.db
文件 19825 2008-12-08 18:57 Lesson6.cpp
目录 0 2010-09-22 14:48 Data
----------- --------- ---------- ----- ----
13864815 17
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)