资源简介
用OPenGL编写的模拟太阳、地球、月球的旋转。并有光照和纹理。
代码片段和文件信息
#include “windows.h“
#include “stdio.h“
#include “stdlib.h“
#include “math.h“
#include “gl/glut.h“
#include “Load.h“
typedef struct{
int width;
int height;
unsigned int texID;
unsigned char *data;
}texture;
float angle = 0.0f;
float R = 0.0;
texture *sun;
texture *earth;
texture *moon;
texture *background;
unsigned char *LoadBmpFile(char *filenameBITMAPINFOHEADER *bmpInfoheader)
{
FILE *file;
BITMAPFILEHEADER bmpFileHeader;
unsigned char *image;
unsigned int imageIdx = 0;
unsigned char tempRGB;
file = fopen(filename“r“);
if (file == NULL)
{
return NULL;
}
fread(&bmpFileHeadersizeof(BITMAPFILEHEADER)1file);
if (bmpFileHeader.bfType != BITMAP_ID)
{
fclose(file);
return NULL;
}
fread(bmpInfoheadersizeof(BITMAPINFOHEADER)1file);
fseek(filebmpFileHeader.bfOffBitsSEEK_SET);
image = (unsigned char*)malloc(bmpInfoheader->biSizeImage);
if (! image)
{
free(image);
fclose(file);
return NULL;
}
fread(image1bmpInfoheader->biSizeImagefile);
if (image == NULL)
{
fclose(file);
return NULL;
}
for (imageIdx = 0;imageIdx < bmpInfoheader->biSizeImage;imageIdx += 3)
{
tempRGB = image[imageIdx];
image[imageIdx] = image[imageIdx + 2];
image[imageIdx + 2] = tempRGB;
}
fclose(file);
return image;
}
texture *LoadTexFile(char *filename){
BITMAPINFOHEADER texInfo;
texture *thisTexture;
thisTexture = (texture*)malloc(sizeof(texture));
if (thisTexture == NULL)
{
return NULL;
}
thisTexture->data = LoadBmpFile(filename&texInfo);
if (thisTexture->data == NULL)
{
free(thisTexture);
return NULL;
}
thisTexture->width = texInfo.biWidth;
thisTexture->height = texInfo.biHeight;
glGenTextures(1&thisTexture->texID);
return thisTexture;
}
BOOL LoadAllTextures(){
sun = LoadTexFile(“sun.bmp“);
if (sun == NULL)
{
return FALSE;
}
glBindTexture(GL_TEXTURE_2Dsun->texID);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_SGL_REPEAT);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_TGL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2DGL_RGBsun->widthsun->heightGL_RGBGL_UNSIGNED_BYTEsun->data);
earth = LoadTexFile(“earth.bmp“);
if (earth == NULL)
{
return FALSE;
}
glBindTexture(GL_TEXTURE_2Dearth->texID);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_SGL_REPEAT);
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_TGL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2DGL_RGBearth->widthearth->heightGL_RGBGL_UNSIGNED_BYTEearth->data);
moon = LoadTexFile(“moon.bmp“);
if (moon == NULL)
{
return FALSE;
}
glBindTexture(GL_TEXTURE_2Dmoon->texID);
glTexParameteri(GL_TEXTURE_2DGL_TEXT
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4303 2012-04-11 22:45 1_1\1_1.dsp
文件 531 2012-04-03 09:43 1_1\1_1.dsw
文件 50176 2012-04-28 10:06 1_1\1_1.ncb
文件 48640 2012-04-28 10:06 1_1\1_1.opt
文件 240 2012-04-28 10:05 1_1\1_1.plg
文件 168897 2012-04-16 21:17 1_1\2007918105831730_2.jpg
文件 8053 2012-04-16 12:23 1_1\a.cpp
文件 1228856 2012-04-16 21:19 1_1\background.bmp
文件 2016256 2012-04-16 12:23 1_1\Debug\1_1.bsc
文件 192616 2012-04-16 12:23 1_1\Debug\1_1.exe
文件 280984 2012-04-16 12:23 1_1\Debug\1_1.ilk
文件 4688320 2012-04-11 22:40 1_1\Debug\1_1.pch
文件 508928 2012-04-16 12:23 1_1\Debug\1_1.pdb
文件 32438 2012-04-16 12:23 1_1\Debug\a.obj
文件 0 2012-04-16 12:23 1_1\Debug\a.sbr
文件 148480 2012-04-28 10:05 1_1\Debug\vc60.idb
文件 77824 2012-04-16 12:23 1_1\Debug\vc60.pdb
文件 345656 2012-04-12 14:57 1_1\earth.bmp
文件 1425 2012-04-10 19:15 1_1\Load.h
文件 43256 2012-03-29 22:39 1_1\moon.bmp
文件 172856 2012-03-29 22:39 1_1\sun.bmp
目录 0 2012-04-16 12:23 1_1\Debug
目录 0 2012-04-28 10:06 1_1
----------- --------- ---------- ----- ----
10018735 23
- 上一篇:ROSE HA8.5 32位、64位均可用
- 下一篇:SevenBall.zip
评论
共有 条评论