int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL done=FALSE;
// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // Windowed Mode
}
// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE;
}
else
{
SwapBuffers(hDC);
}
if (keys[VK_F1])
{
keys[VK_F1]=FALSE;
KillGLWindow();
fullscreen=!fullscreen;
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's Solid Object Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
BOOL OpenGLWindow::CreateGLWindow()
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = &OpenGLWindow::WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = (LPCWSTR)"OpenGL"; // Set The Class Name
::TlsSetValue(s_tlsIndex, this);
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,(LPCWSTR)"Failed To Register The Window Class.", (LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
(LPCWSTR)"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Window Creation Error.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
DeleteMenu(GetSystemMenu(hWnd, false), SC_CLOSE, MF_BYCOMMAND); //Deactivate Closing by x-Button
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Create A GL Device Context.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Find A Suitable PixelFormat.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,(LPCWSTR)"Can't Set The PixelFormat.",(LPCWSTR)"ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
//.........这里部分代码省略.........
BOOL CreateGLWindow(HWND hWnd, HDC *phDC, HGLRC *phRC)
{
GLuint nPixelFormat; // Holds The Results After Searching For A Match
RECT rect;
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW // Format Must Support Window
| PFD_SUPPORT_OPENGL // Format Must Support OpenGL
| PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
0, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
0, // Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!(*phDC = GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Create A GL Device Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(nPixelFormat = ChoosePixelFormat(*phDC, &pfd)))// Did Windows Find A Matching Pixel Format?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Find A Suitable PixelFormat."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!SetPixelFormat(*phDC, nPixelFormat, &pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Set The PixelFormat."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!(*phRC = wglCreateContext(*phDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Create A GL Rendering Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (!wglMakeCurrent(*phDC, *phRC)) // Try To Activate The Rendering Context
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Can't Activate The GL Rendering Context."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
GetClientRect(hWnd, &rect);
ReSizeGLScene(rect.right, rect.bottom); // Set Up Our Perspective GL Screen
if (!InitGL()) // Initialize Our Newly Created GL Window
{
KillGLWindow(hWnd, *phDC, *phRC); // Reset The Display
MessageBox(hWnd, _T("Initialization Failed."), _T("ERROR"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
return TRUE; // Success
}
int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop
// Ask The User Which Screen Mode They Prefer
fullscreen=true; // Fullscreen Mode
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=false;
}
// Create Our OpenGL Window
if (!CreateGLWindow("Zombie City!",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
for(int i=0; i<256; ++i) {
keys[i] = 0;
}
i_tick = float(GetTickCount()); //Set i_tick to the new tick count - so the difference does not exponentially increase
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
do
{
} while (( GetTickCount() - i_tick ) < 10 );
framelength = (GetTickCount() - i_tick) * GAMESPEED; //When the frame starts, find out how many 'ticks' have occurred since the last frame
if(framelength > 10.0f) framelength = 10.0f;
leveltime += int(GetTickCount() - i_tick);
i_tick = float(GetTickCount()); //Set i_tick to the new tick count - so the difference does not exponentially increase
i_frame+=1;
if ((i_tick_2 + 1000) < GetTickCount())
{
i_frame_rate = i_frame;
i_frame=0;
i_tick_2 = float(GetTickCount());
};
update();
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("Zombie City",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
if(end) done=true;
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
//.........这里部分代码省略.........
filter+=1;
if (filter>2)
{
filter=0;
}
}
if (!keys['F'])
{
fp=FALSE;
}*/
if (keys[VK_PRIOR])//strafe up
{
posy += 0.2f;
looky += 0.2f;
}
if (keys[VK_NEXT])//strafe down
{
posy -= 0.2f;
looky -= 0.2f;
}
if (keys[VK_UP])//look up
{
myCamera.RotateCamera(0.0f,0.03f);
//looky += 0.2f;
//xspeed-=0.1f;
}
if (keys[VK_DOWN])//look down
{
myCamera.RotateCamera(0.0f,-0.03f);
//looky -= 0.2f;
//xspeed+=0.1f;
}
if (keys[VK_RIGHT])//look right
{
myCamera.RotateCamera(0.03f,0.0f);
//lookx -= 0.5f;
//yspeed+=0.1f;
}
if (keys[VK_LEFT])//look left
{
myCamera.RotateCamera(-0.03f,0.0f);
lookx += 0.5f;
//yspeed-=0.1f;
}
if (keys['W'])//forward
{
velocity += 1;
/*posz +=0.5f;
lookz +=0.5f;*/
}
if (keys['S']) //backward
{
velocity -= 1;
/*posz -=0.5f;
lookz -=0.5f;*/
}
if (keys['A'])//strafe left
{
myCamera.SlideCamera(-10.0f,0.0f);
/*posx +=0.2f;
lookx += 0.2f;*/
}
if (keys['D'])//strafe right
{
myCamera.SlideCamera(10.0f,0.0f);
/*posx -=0.2f;
lookx -= 0.2f;*/
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow(L"NeHe's Textures, Lighting & Keyboard Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow(L"NeHe's Rotation Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds the results after searching for a match
WNDCLASS wc; // Windows class structure
DWORD dwExStyle; // Window extended style
DWORD dwStyle; // Window style
RECT WindowRect; // Grabs rctangle upper left / lower right values
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)width; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)height; // Set bottom value to requested height
fullscreen = fullscreenflag; // Set the global fullscreen flag
hInstance = GetModuleHandle(NULL); // Grab an instance for our window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = "OpenGL"; // Set the class name
if (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL,"Failed to register the window class.","Error",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
//Only a windowed style
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window extended style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows style
AdjustWindowRectEx(&WindowRect,dwStyle,false,dwExStyle); // Adjust window to true requested size
// Create the window
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window
"OpenGL", // Class name
title, // Window title
dwStyle | // Defined window style
WS_CLIPSIBLINGS | // Required window style
WS_CLIPCHILDREN, // Required window style
0, 0, // Window position
WindowRect.right-WindowRect.left, // Calculate window width
WindowRect.bottom-WindowRect.top, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Dont pass anything to WM_CREATE
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Window creation error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
static PIXELFORMATDESCRIPTOR pfd = // pfd tells windows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this pixel format descriptor
1, // Version number
PFD_DRAW_TO_WINDOW | // Format must support window
PFD_SUPPORT_OPENGL | // Format must support OpenGL
PFD_DOUBLEBUFFER, // Must support double buffering
PFD_TYPE_RGBA, // Request an RGBA format
bits, // Select our color depth
0, 0, 0, 0, 0, 0, // Color bits ignored
0, // No alpha buffer
0, // Shift bit ignored
0, // No accumulation buffer
0, 0, 0, 0, // Accumulation bits ignored
16, // 16Bit Z-Buffer (Depth buffer)
0, // No stencil buffer
0, // No auxiliary buffer
PFD_MAIN_PLANE, // Main drawing layer
0, // Reserved
0, 0, 0 // Layer masks ignored
};
//We need to get the device context from the frames handle
//then maybe we can draw in the frame?
if (!(hDC = GetDC(hWnd))) // Did we get a device context?
//if (!(hDC = GetDC(Frame->)))
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't create a GL device context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) // Did windows find a matching pixel format?
{
KillGLWindow(); // Reset the display
MessageBox(NULL,"Can't find a suitable pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false; // Return false
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are we able to set the pixel format?
//.........这里部分代码省略.........
/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Full screen Mode *
* height - Height Of The GL Window Or Full screen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Full screen Mode (TRUE) Or Windowed Mode (FALSE) */
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullScreenFlag)
{
GLuint PixelFormat; // Holds the results after searching for a match
WNDCLASS wc; // Windows class structure
DWORD dwExStyle; // Window extended style
DWORD dwStyle; // Window style
RECT WindowRect; // Grabs rectangle upper left/lower right values
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)width; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)height; // Set bottom value to requested height
g_bFullscreen = fullScreenFlag; // Set the global full screen flag
hInstance = GetModuleHandle(NULL); // Grab an instance for out window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
wc.lpfnWndProc = (WNDPROC)WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = CLASSNAME; // Set the class name
if (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL, MSG_REGISTERCLASSFAILED,
ERR_ERROR, MB_OK | MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (g_bFullscreen)
{
DEVMODE dmScreenSettings; // Device mode
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); // Makes sure memory's cleared
dmScreenSettings.dmSize = sizeof(dmScreenSettings); // Size of the devmode structure
dmScreenSettings.dmPelsWidth = width; // Selected screen width
dmScreenSettings.dmPelsHeight = height; // Selected screen height
dmScreenSettings.dmBitsPerPel = bits; // Selected bits per pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
// If the mode failed, offer two options. Quit or use windowed mode.
if (MessageBox(NULL, MSG_FULLSCREENNOTSUPPORT,
ARTIST_NAME, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
{
g_bFullscreen = FALSE; // Windowed mode selected. Fullscreen = FALSE
}
else
{
// Pop up a message box letting user know the program is closing.
MessageBox(NULL, MSG_PROGRAMNOTCLOSE,
ERR_ERROR, MB_OK | MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}
if (g_bFullscreen) // Are we still in fullscreen mode?
{
dwExStyle = WS_EX_APPWINDOW; // Window extended style
dwStyle = WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide mouse pointer
}
else
{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Windows Extended style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust window to true requested size
// Create the window
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended style for the window
CLASSNAME, // Class name
title, // Window title
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, // Defined window style
0, 0, // Window position
WindowRect.right - WindowRect.left, // Calculate window width
WindowRect.bottom - WindowRect.top, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Don't pass anything to WM_CREATE
{
KillGLWindow(); // Reset the display
MessageBox(NULL, MSG_CREATEWINDOWFAILED,
ERR_ERROR, MB_OK | MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
static PIXELFORMATDESCRIPTOR pfd = // pfd tells widows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this pixel format descriptor
1, // Version number
//.........这里部分代码省略.........
//.........这里部分代码省略.........
{
translatez-=0.01f;
}
if (keys['A'] )
{
rotatey+=0.01f;
}
if (keys['D'] )
{
rotatey-=0.01f;
}
if (keys[VK_UP] )
{
rotatex+=0.025f;
}
if (keys[VK_DOWN] )
{
rotatex-=0.025f;
}
if (keys[VK_LEFT] )
{
rotatez+=0.1f;
}
if (keys[VK_RIGHT] )
{
rotatez-=0.1f;
}
if (keys[VK_F1] )
{
wireframemode=!wireframemode;
if(wireframemode)
{
WireframeMode();
Sleep(100);
}
else
{
TextureMode();
Sleep(100);
}
}
if (keys[VK_ESCAPE]) // Was ESC pressed?
{
done = true; // ESC signalled a quit
}
// Not time to quit, Update screen
if (isRClicked) // If Right Mouse Clicked, Reset All Rotations
{
Matrix3fSetIdentity(&LastRot); // Reset Rotation
Matrix3fSetIdentity(&ThisRot); // Reset Rotation
Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot); // Reset Rotation
}
if (!isDragging) // Not Dragging
{
if (isClicked) // First Click
{
isDragging = true; // Prepare For Dragging
LastRot = ThisRot; // Set Last Static Rotation To Last Dynamic One
ArcBall.click(&MousePt); // Update Start Vector And Prepare For Dragging
}
}
if (isClicked) // Still Clicked, So Still Dragging
{
Quat4fT ThisQuat;
ArcBall.drag(&MousePt, &ThisQuat); // Update End Vector And Get Rotation As Quaternion
Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat); // Convert Quaternion Into Matrix3fT
Matrix3fMulMatrix3f(&ThisRot, &LastRot); // Accumulate Last Rotation Into This One
Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot); // Set Our Final Transform's Rotation From This One
}
else // No Longer Dragging
isDragging = false;
DrawGLScene(); // Draw the scene
SwapBuffers(hDC); // Swap buffers (Double buffering)
}
}
}
// Shutdown
KillGLWindow(); // Kill the window
return (msg.wParam); // Exit the program
}
请发表评论