原文链接:TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
这个系列专注于使用
C++OpenGLwindows平台上开发2D游戏,项目目标是在系列结束后能开发出一个类似俄罗斯方块的游戏。本系列分为3篇文章:

第一部分:涉及win32消息循环,窗口创建和OpenGL的搭建,并且你将会学习如何绘制一些简单的图形。

第二部分:涉及资源处理和简单动画的显示

第三部分:将前面的内容包含进来,并且讨论游戏逻辑。

项目设置

作者做了两项设置:

1)LinkeràInput中,在” Addition Dependencies”中加入opengl32.lib”

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

2)禁掉UNICODE“c/c++”à Preprocessor”,Preprocessor Definitions中将"Inherit from parent or project defaults"不选中。

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

消息循环

Windows系统为每个应用程序创建一个消息队列,当指定应用程序的窗口上发生一个事件时,系统会把消息推入到这个队列中。你的应用程序应当检索并处理这些消息。这就是所谓的消息循环,是win32应用程序的核心。

一个典型的消息循环如下:

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1MSGMessage;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1Message.message
=(~WM_QUIT);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//LoopuntilaWM_QUITmessageisreceived
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
while(Message.message!=WM_QUIT)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(PeekMessage(&Message,NULL,0,0,PM_REMOVE))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Ifamessagewaswaitinginthemessagequeue,processit
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
TranslateMessage(&Message);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DispatchMessage(
&Message);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
else
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{//空闲时
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Doprocessingstuffhere【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

TranslateMessage函数的目的是为了将虚键消息(WM_KEYDOWNWM_KEYUP)为字符消息(WM_CHAR.最后DispatchMessage会将消息定向到正确的窗口处理程序。

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1//Theapplicationclass,whichsimplywrapsthemessagequeueandprocess
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//thecommandline.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
classCApplication
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
public:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CApplication()
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{}
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CApplication(HINSTANCEhInstance);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
~CApplication();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Parsesthecommandlinetoseeiftheapplication
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//shouldbeinfullscreenmode.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
voidParseCmdLine(LPSTRlpCmdLine);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Createsthemainwindowandstartthemessageloop.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
voidRun();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
voidSetHInst(HINSTANCEhInstance);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
private:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1HINSTANCEm_hInstance;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Specifiesiftheapplicationhastobestartedinfullscreen
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//mode.Thisoptionissuppliedthroughthecommandline
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//("-fullscreen"option).
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
boolm_bFullScreen;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}
;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

ParseCmdLine函数功能非常直观:仅仅简单地检查命令行中是否有参数"-fullscreen",如果有,则设置m_bFullScreentrue,表示窗口模式为全屏模式。

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCApplication::Run()
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Createthemainwindowfirst
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
CMainWindowmainWindow(800,600,m_bFullScreen);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1MSGMessage;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1Message.message
=~WM_QUIT;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DWORDdwNextDeadLine
=GetTickCount()+30;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DWORDdwSleep
=30;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
boolbUpdate=false;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//LoopuntilaWM_QUITmessageisreceived
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
while(Message.message!=WM_QUIT)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Waituntilamessagecomesinoruntilthetimeoutexpires.The
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//timeoutisrecalculatedsothatthisfunctionwillreturnat
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//leastevery30msec.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
DWORDdwResult=MsgWaitForMultipleObjectsEx(0,NULL,dwSleep,QS_ALLEVENTS,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(dwResult!=WAIT_TIMEOUT)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Ifthefunctionreturnedwithnotimeout,itmeansthata
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//messagehasbeenreceived,soprocessit.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(PeekMessage(&Message,NULL,0,0,PM_REMOVE))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Ifamessagewaswaitinginthemessagequeue,processit
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
TranslateMessage(&Message);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DispatchMessage(
&Message);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Ifthecurrenttimeisclose(orpast)tothe
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//deadline,theapplicationshouldbeprocessed.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(GetTickCount()>=dwNextDeadLine-1)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1bUpdate
=true;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
else
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Onatimeout,theapplicationshouldbeprocessed.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
bUpdate=true;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Checkiftheapplicationshouldbeprocessed
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(bUpdate)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DWORDdwCurrentTime
=GetTickCount();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Updatethemainwindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
mainWindow.Update(dwCurrentTime);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Drawthemainwindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
mainWindow.Draw();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwNextDeadLine
=dwNextDeadLine+30;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwSleep
=30;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
else
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwSleep
=dwNextDeadLine-GetCurrentTime();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

函数第一行创建主窗口。和常见的消息循环不同,由于在2D游戏中并不需要很快地刷新屏幕,以固定地速率(这里是30毫秒)刷新,对于绘制动画和其他处理已经足够了。

作者在这里使用的技巧就是出于这个目的,他使用了MsgWaitForMultipleObjectsEx函数来等待任何事件的发生,再判断是30毫秒的时限已到,还是有事件要处理,若是后者,则先处理事件,在处理完后,若此时也已经接近30毫秒的时限的话,就重绘界面,若是超时发生了,则说明30毫秒时限已到,需要去刷新界面了。若这两种情况都没有的话,这个函数不会消耗 CPU周期,线程只是被挂起,不参与调度。

主窗口

创建窗口

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CMainWindow::CMainWindow(intiWidth,intiHeight,boolbFullScreen)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1:m_hWindow(NULL),m_hDeviceContext(NULL),m_hGLContext(NULL),
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1m_bFullScreen(bFullScreen)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1RegisterWindowClass();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1RECTWindowRect;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1WindowRect.top
=WindowRect.left=0;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1WindowRect.right
=iWidth;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1WindowRect.bottom
=iHeight;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//WindowExtendedStyle
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
DWORDdwExStyle=0;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//WindowsStyle
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
DWORDdwStyle=0;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(m_bFullScreen)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1DEVMODEdmScreenSettings;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1memset(
&dmScreenSettings,0,sizeof(dmScreenSettings));
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dmScreenSettings.dmSize
=sizeof(dmScreenSettings);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dmScreenSettings.dmPelsWidth
=iWidth;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dmScreenSettings.dmPelsHeight
=iHeight;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dmScreenSettings.dmBitsPerPel
=32;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dmScreenSettings.dmFields
=DM_PELSWIDTH|DM_PELSHEIGHT|DM_BITSPERPEL;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Changethedisplaysettingstofullscreen.Onerror,throw
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//anexception.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
!=DISP_CHANGE_SUCCESSFUL)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletoswithtofullscreenmode");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwExStyle
=WS_EX_APPWINDOW;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwStyle
=WS_POPUP;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Infullscreenmode,wehidethecursor.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
ShowCursor(FALSE);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
else
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwExStyle
=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1dwStyle
=WS_OVERLAPPEDWINDOW;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Adjustthewindowtothetruerequestedsize
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
AdjustWindowRectEx(&WindowRect,dwStyle,FALSE,dwExStyle);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Nowcreatethemainwindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
m_hWindow=CreateWindowEx(dwExStyle,TEXT(WINDOW_CLASSNAME),
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1TEXT(
"Tutorial1"),
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1WS_CLIPSIBLINGS
|WS_CLIPCHILDREN|dwStyle,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
0,0,WindowRect.right-WindowRect.left,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1WindowRect.bottom
-WindowRect.top,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1NULL,NULL,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1GetModuleHandle(NULL),
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
this);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(m_hWindow==NULL)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Cannotcreatethemainwindow");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CreateContext();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1InitGL();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1ShowWindow(m_hWindow,SW_SHOW);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//CallOnSizemanuallybecauseinfullscreenmodeitwillbe
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//calledonlywhenthewindowiscreated(whichistooearly
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//becauseOpenGLisnotinitializedyet).
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
OnSize(iWidth,iHeight);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

在构造函数中,检查完是否需要进入全屏模式后,通过调用ChangeDisplaySettings来切换到全屏模式,然后调用AdjustWindowRectEx来调整矩形的大小,但这个函数在全屏模式下没什么作用,最后CreateContextInitGLOpenGL进行初始化。

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1LRESULTCMainWindow::OnEvent(HWNDHandle,UINTMessage,WPARAMwParam,LPARAMlParam)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(Message==WM_CREATE)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Getthecreationparameters.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
CREATESTRUCT*pCreateStruct=reinterpret_cast<CREATESTRUCT*>(lParam);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Setasthe"userdata"parameterofthewindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
SetWindowLongPtr(Handle,GWLP_USERDATA,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1reinterpret_cast
<long>(pCreateStruct->lpCreateParams));
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//GettheCMainWindowinstancecorrespondingtothewindowhandle
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
CMainWindow*pWindow=reinterpret_cast<CMainWindow*>
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1(GetWindowLongPtr(Handle,GWLP_USERDATA));
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(pWindow)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1pWindow
->ProcessEvent(Message,wParam,lParam);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
returnDefWindowProc(Handle,Message,wParam,lParam);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

由于OnEvent函数是静态的,因此就没法访问非静态成员,为了解决这个问题,在调用CreateWindowEx创建窗口时最后一个参数传的是this指针。传给窗口处理过程的第一个消息是WM_CREATE,当接收到这个消息时,wParam参数中包含一个CREATESTRUCT指针,它里面包含了额外的数据,在这里是指向CMainWindow的指针。但遗憾的是,不是每个消息都有这个结构,所以要保存起来供后面使用。因此调用SetWindowLongPtr,它的目的是为一个特定的窗口保存一些用户数据(GWLP_USERDATA)。在这里,作者保存了到类实例的指针。当接收到其他消息时,我们只是简单地通过GetWindowLongPtr来取回这个指针,然后访问非静态函数ProcessEvent,而这个函数负责具体的消息处理。

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCMainWindow::ProcessEvent(UINTMessage,WPARAMwParam,LPARAMlParam)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
switch(Message)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Quitwhenweclosethemainwindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
caseWM_CLOSE:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1PostQuitMessage(
0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
break;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
caseWM_SIZE:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1OnSize(LOWORD(lParam),HIWORD(lParam));
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
break;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
caseWM_KEYDOWN:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
break;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
caseWM_KEYUP:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
break;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

异常处理

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1classCException:publicstd::exception
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
public:
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
constchar*what()const【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{returnm_strMessage.c_str();}
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CException(
conststd::string&strMessage=""):m_strMessage(strMessage)【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{}
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
virtual~CException()【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{}
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1std::
stringm_strMessage;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}
;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

使用的实例:

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1CApplicationtheApp;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
intWINAPIWinMain(HINSTANCEInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,INT)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
try
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Createtheapplicationclass,
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//parsethecommandlineand
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//starttheapp.
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
theApp.SetHInst(Instance);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1theApp.ParseCmdLine(lpCmdLine);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1theApp.Run();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
catch(CException&e)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1MessageBox(NULL,e.what(),
"Error",MB_OK|MB_ICONEXCLAMATION);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
return0;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

初始化OpenGL
CreateContext用来初始化绘制上下文,使得OpenGL基本元素可以在窗口上绘制:

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCMainWindow::CreateContext()
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Describesthepixelformatofthedrawingsurface
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
PIXELFORMATDESCRIPTORpfd;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1memset(
&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1pfd.nSize
=sizeof(PIXELFORMATDESCRIPTOR);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1pfd.nVersion
=1;//VersionNumber
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
pfd.dwFlags=PFD_DRAW_TO_WINDOW|//Drawstoawindow
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
PFD_SUPPORT_OPENGL|//TheformatmustsupportOpenGL
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
PFD_DOUBLEBUFFER;//Supportfordoublebuffering
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
pfd.iPixelType=PFD_TYPE_RGBA;//UsesanRGBApixelformat
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
pfd.cColorBits=32;//32bitscolors
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(!(m_hDeviceContext=GetDC(m_hWindow)))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletocreaterenderingcontext");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
intPixelFormat;
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//DoWindowsfindamatchingpixelformat?
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(!(PixelFormat=ChoosePixelFormat(m_hDeviceContext,&pfd)))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletocreaterenderingcontext");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Setthenewpixelformat
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(!SetPixelFormat(m_hDeviceContext,PixelFormat,&pfd))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletocreaterenderingcontext");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//CreatetheOpenGLrenderingcontext
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(!(m_hGLContext=wglCreateContext(m_hDeviceContext)))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletocreaterenderingcontext");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Activatetherenderingcontext
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
if(!wglMakeCurrent(m_hDeviceContext,m_hGLContext))
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
throwCException("Unabletocreaterenderingcontext");
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

函数的第一部分填充PIXELFORMATDESCRIPTOR结构体:缓冲区用来绘制到窗口上,支持OpenGL,使用双缓存(为了避免闪烁)。然后调用ChoosePixelFormat来检查像素格式是否支持,这个函数返回一个像素格式索引(若没有找到匹配的,则返回0)。一旦存在这样的像素格式索引,则通过SetPixelFormat来设置新像素格式。然后调用wglCreateContext创建OpenGL绘制上下文,最后,调用wglMakeCurrent,这指明线程接下来的OpenGL调用会绘制在这个设备上下文上。

InitGL函数很简单:

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCMainWindow::InitGL()
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Enable2Dtexturing
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glEnable(GL_TEXTURE_2D);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Chooseasmoothshadingmodel
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glShadeModel(GL_SMOOTH);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Settheclearcolortoblack
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glClearColor(0.0,0.0,0.0,0.0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

再看OnSize函数

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCMainWindow::OnSize(GLsizeiwidth,GLsizeiheight)
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//SetsthesizeoftheOpenGLviewport
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glViewport(0,0,width,height);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Selecttheprojectionstackandapply
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//anorthographicprojection
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glMatrixMode(GL_PROJECTION);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glLoadIdentity();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glOrtho(
0.0,width,height,0.0,-1.0,1.0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glMatrixMode(GL_MODELVIEW);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

正交投影

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

透视投影


【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
绘制简单图形

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1voidCMainWindow::Draw()
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1{
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Clearthebuffer
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glClear(GL_COLOR_BUFFER_BIT);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
//Heregoesthedrawingcode
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
glBegin(GL_QUADS);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
1.0,0.0,0.0);glVertex3i(50,200,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
0.0,1.0,0.0);glVertex3i(250,200,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
0.0,0.0,1.0);glVertex3i(250,350,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
1.0,1.0,1.0);glVertex3i(50,350,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glEnd();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glBegin(GL_TRIANGLES);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
1.0,0.0,0.0);glVertex3i(400,350,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
0.0,1.0,0.0);glVertex3i(500,200,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glColor3f(
0.0,0.0,1.0);glVertex3i(600,350,0);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1glEnd();
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1SwapBuffers(m_hDeviceContext);
【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1}

【译】TetroGL: An OpenGL Game Tutorial in C++ for Win32 Platforms - Part 1

相关文章: