OpenGL入门笔记(十二)

成员变量区:
GLuint
base;
GLfloatcnt1;
GLfloatcnt2;

成员函数区:
GLvoidCOpenGLDemoView::glPrint(
constchar*fmt,)//CustomGL"Print"Routine
{
chartext[256];//HoldsOurString
va_listap;//PointerToListOfArguments

if(fmt==NULL)//IfThere'sNoText
return;//DoNothing

va_start(ap,fmt);
//ParsesTheStringForVariables
vsprintf(text,fmt,ap);//AndConvertsSymbolsToActualNumbers
va_end(ap);//ResultsAreStoredInText

glPushAttrib(GL_LIST_BIT);
//PushesTheDisplayListBits
glListBase(base);//SetsTheBaseCharacterto32
glCallLists(strlen(text),GL_UNSIGNED_BYTE,text);//DrawsTheDisplayListText
glPopAttrib();//PopsTheDisplayListBits
}


GLvoidCOpenGLDemoView::BuildFont(GLvoid)
{
HFONTfont;
//WindowsFontID
HFONToldfont;//UsedForGoodHouseKeeping

base=glGenLists(96);//StorageFor96Characters

font
=CreateFont(-24,//HeightOfFont
0,//WidthOfFont
0,//AngleOfEscapement
0,//OrientationAngle
FW_BOLD,//FontWeight
FALSE,//Italic
FALSE,//Underline
FALSE,//Strikeout
ANSI_CHARSET,//CharacterSetIdentifier
OUT_TT_PRECIS,//OutputPrecision
CLIP_DEFAULT_PRECIS,//ClippingPrecision
ANTIALIASED_QUALITY,//OutputQuality
FF_DONTCARE|DEFAULT_PITCH,//FamilyAndPitch
"CourierNew");//FontName
HDChDC=::GetDC(this->m_hWnd);
oldfont
=(HFONT)SelectObject(hDC,font);//SelectsTheFontWeWant
wglUseFontBitmaps(hDC,0,255,base);//Builds96CharactersStartingAtCharacter32
SelectObject(hDC,oldfont);//SelectsTheFontWeWant
DeleteObject(font);//DeleteTheFont
}

GLvoidCOpenGLDemoView::KillFont(GLvoid)
{
glDeleteLists(
base,96);
}

GLvoidCOpenGLDemoView::KillFont(GLvoid)
{
glDeleteLists(
base,96);
}


intCOpenGLDemoView::DrawGLScene()
{//Here'sWhereWeDoAllTheDrawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//ClearScreenAndDepthBuffer
glLoadIdentity();//ResetTheCurrentModelviewMatrix
glTranslatef(0.0f,0.0f,-1.0f);//MoveOneUnitIntoTheScreen
//PulsingColorsBasedOnTextPosition
glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
//PositionTheTextOnTheScreen
glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)),0.32f*float(sin(cnt2)));
glPrint(
"ActiveOpenGLText-%7.2f",cnt1);//PrintGLTextToTheScreen
cnt1+=0.051f;//IncreaseTheFirstCounter
cnt2+=0.005f;//IncreaseTheFirstCounter
returnTRUE;//EverythingWentOK
//EverythingWentOK
}



200782402.jpg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值