#include "core_win32opengl.h" #include #pragma comment(lib,"kernel32") #pragma comment(lib,"gdi32") #pragma comment(lib,"user32") #pragma comment(lib,"opengl32") #pragma comment(lib,"glu32") #define IDI_MAINICON 101 static WNDCLASS wincl; static int wincount=0; void CoreOpenGL::SetupPixelFormat() { PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR),1, PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, PFD_TYPE_RGBA,colorsize, 0,0,0,0,0,0,0,0,0,0,0,0,0, depthsize,0, 0,PFD_MAIN_PLANE,0,0,0,0 }; int pfmt=ChoosePixelFormat(device,&pfd); SetPixelFormat(device,pfmt,&pfd); } LRESULT APIENTRY WindowProcGL(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) { CoreOpenGL *thiscore=(CoreOpenGL *)GetWindowLong(hwnd,GWL_USERDATA); if ((thiscore==NULL)&&(msg!=WM_CREATE)) return DefWindowProc(hwnd,msg,wp,lp); RAVEN_KEY_CODE ratkey; RAVEN_SYS_KEY vkey; int btnnum=0; switch (msg) { case WM_CREATE: { HINSTANCE instance=(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE); thiscore=(CoreOpenGL *)(((LPCREATESTRUCT)lp)->lpCreateParams); SetWindowLong(hwnd,GWL_USERDATA,(LONG)thiscore); thiscore->hwnd=hwnd; thiscore->BindGLContext(); ShowWindow(hwnd,SW_SHOW); return 0; } break; case WM_QUIT: case WM_CLOSE: thiscore->isappterm=true; return 0; case WM_SIZE: thiscore->height=HIWORD(lp); thiscore->width=LOWORD(lp); thiscore->isresized=true; ReleaseDC(thiscore->hwnd,thiscore->device); thiscore->device=GetDC(thiscore->hwnd); return 0; case WM_ERASEBKGND: case WM_ACTIVATEAPP: return 0; case WM_KEYDOWN: vkey=wp; ratkey=RAVEN_key_map_get_code(thiscore->keymap,vkey); if (ratkey) thiscore->keys[ratkey]=true; else thiscore->keys[vkey]=true; return 0; case WM_KEYUP: vkey=wp; ratkey=RAVEN_key_map_get_code(thiscore->keymap,vkey); if (ratkey) thiscore->keys[ratkey]=false; else thiscore->keys[vkey]=false; return 0; case WM_RBUTTONDOWN: btnnum++; /* Right mouse button pressed */ case WM_MBUTTONDOWN: btnnum++; /* Middle mouse button pressed */ case WM_LBUTTONDOWN: btnnum++; /* Left mouse button pressed */ thiscore->buttons[btnnum]=true; return 0; case WM_RBUTTONUP: btnnum++; /* Right mouse button released */ case WM_MBUTTONUP: btnnum++; /* Middle mouse button released */ case WM_LBUTTONUP: btnnum++; /* Left mouse button released */ thiscore->buttons[btnnum]=false; return 0; case WM_MOUSEMOVE: thiscore->mousex=(double)LOWORD(lp)/(double)thiscore->width; thiscore->mousey=(double)HIWORD(lp)/(double)thiscore->height; return 0; case WM_SYSCOMMAND: /* System call made. */ if (wp==SC_SCREENSAVE||wp==SC_MONITORPOWER) return 0; break; default: break; } return DefWindowProc(hwnd,msg,wp,lp); } CoreOpenGL::CoreOpenGL(char *title,unsigned int width,unsigned int height,int colorsize,int depthsize,int flags): Core(title,width,height,colorsize,depthsize,flags) { instance=GetModuleHandle(NULL); char path[5000]; if (GetModuleFileName(NULL,path,sizeof(path))) { char *slash=strrchr(path,'\\'); if (slash) *slash='\0'; _chdir(path); } } CoreOpenGL::~CoreOpenGL() {} bool CoreOpenGL::Start() { if (!keymap) { cerr<<"Keymap failed to initialize!"<