資源簡介
關于OPENGL制作的,飄動的旗幟,有詳細的源代碼,可直接運行

代碼片段和文件信息
#define?WIN32_LEAN_AND_MEAN //?trim?the?excess?fat?from?Windows
/*******************************************************************
* Program:?Chapter?8?Texture?Example?2:?The?Waving?Flag?Example
* OpenGL?Game?Programming
* Author:?Kevin?Hawkins
* Description:?Displays?a?“waving“?American?flag.?The?flag?waves
* based?on?the?sin()?function.
********************************************************************/
//////?Defines
#define?BITMAP_ID?0x4D42 //?the?universal?bitmap?ID
//////?Includes
#include? //?standard?Windows?app?include
#include?
#include?
#include?
#include? //?standard?OpenGL?include
#include? //?OpenGL?utilties
//////?Global?Variables
HDC?g_HDC; //?global?device?context
bool?fullScreen?=?false; //?true?=?fullscreen;?false?=?windowed
bool?keyPressed[256]; //?holds?true?for?keys?that?are?pressed
//////?Texture?Information
BITMAPINFOHEADER bitmapInfoHeader; //?bitmap?info?header
unsigned?char* bitmapData; //?the?texture?data
unsigned?int texture; //?the?texture?object
//////?Flag?Data
float?flagPoints[36][20][3]; //?flag?is?36x20?(in?points)
float?wrapValue; //?used?to?wrap?point?data
//?InitializeFlag()
//?desc:?initializes?the?waving?texture?mapped?flag‘s?data?by?calculating
//???????a?sin?wave?across?the?flag.
void?InitializeFlag()
{
int?xIdx; //?counter?index?for?x-plane
int?yIdx; //?counter?index?for?y-plane
//?loop?through?all?of?the?flag?points?and?calculate?the?sin?wave
//?for?the?z-coordinate.?x-?and?y-?coordinates?equal?to?counter?indices
for?(xIdx?=?0;?xIdx?36;?xIdx++)
{
for?(yIdx?=?0;?yIdx?20;?yIdx++)
{
flagPoints[xIdx][yIdx][0]?=?(float)xIdx;
flagPoints[xIdx][yIdx][1]?=?(float)yIdx;
flagPoints[xIdx][yIdx][2]?=?float(sin((((float)xIdx*20.0f)/360.0f)*3.14159f*2.0f));?
}
}
}
//?DrawFlag()
//?desc:?draws?the?waving?texture?mapped?flag
void?DrawFlag()
{
int?xIdx; //?counter?index?for?x-direction
int?yIdx; //?counter?index?for?y-direction
float?texLeft; //?left?texture?coordinate?for?quads
float?texBottom; //?bottom?texture?coordinate?for?quads
float?texTop; //?top?texture?coordinate?for?quads
float?texRight; //?right?texture?coordinate?for?quads
glPushMatrix();
glBindTexture(GL_TEXTURE_2D?texture); //?bind?our?texture
glBegin(GL_QUADS); //?draw?flag?using?quads
//?loop?through?the?flag‘s?points?minus?the?last?2?in?each?direction
//?since?we?only?use?them?to?draw?the?last?GL_QUAD?in?each?direction
for?(xIdx?=?0;?xIdx?36;?xIdx++) //?x-direction
{
for?(yIdx?=?0;?yIdx?18;?yIdx++) //?y-direction
{
//?calculate?texture?coordinates?for?current?quad
texLeft?=?float(xIdx)?/?35.0f; //?left?texture?coordinate
texBottom?=?float(yIdx)?/?18.0f; //?bottom?texture?coordinate
texRight?=?float(xIdx+1)?/?35.0f; //?right?texture?coordinate
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????15000??2001-03-08?02:47??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\main.cpp
?????文件???????4072??2001-01-04?20:23??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\textureex2.dsp
?????文件????????543??2001-01-01?23:41??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\textureex2.dsw
?????文件??????36864??2001-04-10?02:15??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\textureex2.exe
?????文件??????24630??2001-01-02?01:03??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\usflag.bmp
?????文件????3443712??2009-06-16?11:09??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\textureex2.ncb
?????文件???????3072??2009-06-16?11:09??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))\textureex2.suo
?????目錄??????????0??2009-06-19?10:16??飄動的美國旗幟(openGL游戲程序設計(美國K.霍金))
-----------?---------??----------?-----??----
??????????????3527893????????????????????8
評論
共有 條評論