<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->intCOpenGLDemoView::DrawGLScene()
{//Here'sWhereWeDoAllTheDrawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//ClearTheScreenAndTheDepthBuffer
glLoadIdentity();//ResetTheView
glTranslatef(1.1f*float(cos(rot/16.0f)),0.8f*float(sin(rot/20.0f)),-3.0f);
glRotatef(rot,1.0f,0.0f,0.0f);//RotateOnTheXAxis
glRotatef(rot*1.2f,0.0f,1.0f,0.0f);//RotateOnTheYAxis
glRotatef(rot*1.4f,0.0f,0.0f,1.0f);//RotateOnTheZAxis
glTranslatef(-0.35f,-0.35f,0.1f);//CenterOnX,Y,ZAxis
glPrint("N");//DrawASkullAndCrossbonesSymbol
returnTRUE;
}
intCOpenGLDemoView::LoadGLTextures()
{//加载位图并转换为纹理
intStatus=FALSE;//StatusIndicator
AUX_RGBImageRec*TextureImage[1];//CreateStorageSpaceForTheTexture
memset(TextureImage,0,sizeof(void*)*1);//SetThePointerToNULL
//LoadTheBitmap,CheckForErrors,IfBitmap'sNotFoundQuit
if(TextureImage[0]=LoadBMP("Data/Lights.bmp"))
{
Status=TRUE;//SetTheStatusToTRUE
glGenTextures(1,&texture[0]);//CreateTheTexture
glBindTexture(GL_TEXTURE_2D,texture[0]);
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
}
if(TextureImage[0])//IfTextureExists
{
if(TextureImage[0]->data)//IfTextureImageExists
{
free(TextureImage[0]->data);//FreeTheTextureImageMemory
}
free(TextureImage[0]);//FreeTheImageStructure
}
returnStatus;//ReturnTheStatus
}
GLvoidCOpenGLDemoView::BuildFont(GLvoid)
{
GLYPHMETRICSFLOATgmf[256];//AddressBufferForFontStorage
HFONTfont;//WindowsFontID
base=glGenLists(256);//StorageFor256Characters
font=CreateFont(-12,//HeightOfFont
0,//WidthOfFont
0,//AngleOfEscapement
0,//OrientationAngle
FW_BOLD,//FontWeight
FALSE,//Italic
FALSE,//Underline
FALSE,//Strikeout
SYMBOL_CHARSET,//CharacterSetIdentifier
OUT_TT_PRECIS,//OutputPrecision
CLIP_DEFAULT_PRECIS,//ClippingPrecision
ANTIALIASED_QUALITY,//OutputQuality
FF_DONTCARE|DEFAULT_PITCH,//FamilyAndPitch
"Wingdings");//FontName
HDChDC=::GetDC(this->m_hWnd);
SelectObject(hDC,font);//SelectsTheFontWeCreated
wglUseFontOutlines(hDC,//SelectTheCurrentDC
0,//StartingCharacter
255,//NumberOfDisplayListsToBuild
base,//StartingDisplayLists
0.1f,//DeviationFromTheTrueOutlines
0.2f,//FontThicknessInTheZDirection
WGL_FONT_POLYGONS,//UsePolygons,NotLines
gmf);//AddressOfBufferToRecieveData
}
GLvoidCOpenGLDemoView::glPrint(constchar*text)//CustomGL"Print"Routine
{
if(text==NULL)//IfThere'sNoText
return;//DoNothing
glPushAttrib(GL_LIST_BIT);//PushesTheDisplayListBits
glListBase(base);//SetsTheBaseCharacterto32
glCallLists(strlen(text),GL_UNSIGNED_BYTE,text);//DrawsTheDisplayListText
glPopAttrib();//PopsTheDisplayListBits//PopsTheDisplayListBits
}
{//Here'sWhereWeDoAllTheDrawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//ClearTheScreenAndTheDepthBuffer
glLoadIdentity();//ResetTheView
glTranslatef(1.1f*float(cos(rot/16.0f)),0.8f*float(sin(rot/20.0f)),-3.0f);
glRotatef(rot,1.0f,0.0f,0.0f);//RotateOnTheXAxis
glRotatef(rot*1.2f,0.0f,1.0f,0.0f);//RotateOnTheYAxis
glRotatef(rot*1.4f,0.0f,0.0f,1.0f);//RotateOnTheZAxis
glTranslatef(-0.35f,-0.35f,0.1f);//CenterOnX,Y,ZAxis
glPrint("N");//DrawASkullAndCrossbonesSymbol
returnTRUE;
}
intCOpenGLDemoView::LoadGLTextures()
{//加载位图并转换为纹理
intStatus=FALSE;//StatusIndicator
AUX_RGBImageRec*TextureImage[1];//CreateStorageSpaceForTheTexture
memset(TextureImage,0,sizeof(void*)*1);//SetThePointerToNULL
//LoadTheBitmap,CheckForErrors,IfBitmap'sNotFoundQuit
if(TextureImage[0]=LoadBMP("Data/Lights.bmp"))
{
Status=TRUE;//SetTheStatusToTRUE
glGenTextures(1,&texture[0]);//CreateTheTexture
glBindTexture(GL_TEXTURE_2D,texture[0]);
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
}
if(TextureImage[0])//IfTextureExists
{
if(TextureImage[0]->data)//IfTextureImageExists
{
free(TextureImage[0]->data);//FreeTheTextureImageMemory
}
free(TextureImage[0]);//FreeTheImageStructure
}
returnStatus;//ReturnTheStatus
}
GLvoidCOpenGLDemoView::BuildFont(GLvoid)
{
GLYPHMETRICSFLOATgmf[256];//AddressBufferForFontStorage
HFONTfont;//WindowsFontID
base=glGenLists(256);//StorageFor256Characters
font=CreateFont(-12,//HeightOfFont
0,//WidthOfFont
0,//AngleOfEscapement
0,//OrientationAngle
FW_BOLD,//FontWeight
FALSE,//Italic
FALSE,//Underline
FALSE,//Strikeout
SYMBOL_CHARSET,//CharacterSetIdentifier
OUT_TT_PRECIS,//OutputPrecision
CLIP_DEFAULT_PRECIS,//ClippingPrecision
ANTIALIASED_QUALITY,//OutputQuality
FF_DONTCARE|DEFAULT_PITCH,//FamilyAndPitch
"Wingdings");//FontName
HDChDC=::GetDC(this->m_hWnd);
SelectObject(hDC,font);//SelectsTheFontWeCreated
wglUseFontOutlines(hDC,//SelectTheCurrentDC
0,//StartingCharacter
255,//NumberOfDisplayListsToBuild
base,//StartingDisplayLists
0.1f,//DeviationFromTheTrueOutlines
0.2f,//FontThicknessInTheZDirection
WGL_FONT_POLYGONS,//UsePolygons,NotLines
gmf);//AddressOfBufferToRecieveData
}
GLvoidCOpenGLDemoView::glPrint(constchar*text)//CustomGL"Print"Routine
{
if(text==NULL)//IfThere'sNoText
return;//DoNothing
glPushAttrib(GL_LIST_BIT);//PushesTheDisplayListBits
glListBase(base);//SetsTheBaseCharacterto32
glCallLists(strlen(text),GL_UNSIGNED_BYTE,text);//DrawsTheDisplayListText
glPopAttrib();//PopsTheDisplayListBits//PopsTheDisplayListBits
}
LoadGLTextures中的几行代码将为我们绘制在屏幕上的任何物体自动生成纹理坐标。GL_S和GL_T是纹理坐标。默认状态下,glTexGen被设置为提取物体此刻在屏幕上的x坐标和y坐标,并把它们转换为顶点坐标。你会发现到物体在z平面没有纹理,只显示一些斑纹。正面和反面都被赋予了纹理,这些都是由glTexGen函数产生的。(X(GL_S)用于从左到右映射纹理, Y(GL_T)用于从上到下映射纹理。 <?xml:namespace prefix = o />
GL_TEXTURE_GEN_MODE允许我们选择我们想在S和T纹理坐标上使用的纹理映射模式。你有3种选择:
GL_EYE_LINEAR - 纹理会固定在屏幕上。它永远不会移动。物体将被赋予处于它通过的地区的那一块纹理。
GL_OBJECT_LINEAR - 这种就是我们使用的模式。纹理被固定于在屏幕上运动的物体上。
GL_SPHERE_MAP - 每个人都喜欢。创建一种有金属质感的物体。