#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <string>
#include <gl/gl.h>
#include <gl/glu.h>
#include “TextureMgr.h”
#include “md2.h”
#include “CGfxOpenGL.h”
#include “ChessGame.h”
#include “timer.h”
bool exiting = false;
long windowWidth = 1024;
long windowHeight = 768;
long windowBits = 24;
bool fullscreen = false;
int mouseX, mouseY;
HDC hDC;
CGfxOpenGL *g_glRender = NULL;
CHiResTimer *g_hiResTimer = NULL;
CChessGame *g_chessGame = NULL;
void SetupPixelFormat(HDC hDC)
{
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size
۱, // version
PFD_SUPPORT_OPENGL | // OpenGL window
PFD_DRAW_TO_WINDOW | // render to window
PFD_DOUBLEBUFFER, // support double-buffering
PFD_TYPE_RGBA, // color type
۳۲, // prefered color depth
۰, ۰, ۰, ۰, ۰, ۰, // color bits (ignored)
۰, // no alpha buffer
۰, // alpha bits (ignored)
۰, // no accumulation buffer
۰, ۰, ۰, ۰, // accum bits (ignored)
۱۶, // depth buffer
۰, // no stencil buffer
۰, // no auxiliary buffers
PFD_MAIN_PLANE, // main layer
۰, // reserved
۰, ۰, ۰, // no layer, visible, damage masks
};
pixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, pixelFormat, &pfd);
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDC;
static HGLRC hRC;
int height, width;
int xPos, yPos;
double x, y, z;
char str[40] = {‘\0’};
// dispatch messages
switch (uMsg)
{
case WM_CREATE: // window creation
hDC = GetDC(hWnd);
SetupPixelFormat(hDC);
//SetupPalette();
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
break;
case WM_DESTROY: // window destroy
case WM_QUIT:
case WM_CLOSE: // windows is closing
// deselect rendering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
// send WM_QUIT to message queue
PostQuitMessage(0);
break;
case WM_SIZE:
height = HIWORD(lParam); // retrieve width and height
width = LOWORD(lParam);
g_glRender->SetupProjection(width, height);
break;
|
دیدگاهتان را بنویسید