// Standard OpenGL Init Stuff BOOL CMFCTessView::InitOpenGL() { //Get a DC for the Client Area m_pDC = new CClientDC(this); //Failure to Get DC if( m_pDC == NULL ) return FALSE; if( !SetupPixelFormat() ) return FALSE; //Create Rendering Context m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() ); //Failure to Create Rendering Context if( m_hRC == 0 ) return FALSE; //Make the RC Current if( ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC ) == FALSE ) return FALSE; // Usual OpenGL stuff glClearColor( 1.0f, 1.0f, 1.0f, 0.0f ); glClearDepth(1.0f); glEnable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_2D ); glLineWidth( 2.0f ); glPointSize( 3.0f ); return TRUE; }
bool CLineComputeView::InitializeOpenGL(CDC * pDC) { m_pDC = pDC; //设置像素格式 if (SetupPixelFormat() == FALSE) return 0; //创建并设置RC if (CreateViewGLContext(m_pDC->GetSafeHdc()) == FALSE) { return FALSE; } /*if(!LoadGLTextures()) return false;*/ glClearColor(1.0f, 1.0f, 1.0f, 0.0f); glEnable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); //gl_float glClearDepth(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); //glEnable(GL_POINT_SMOOTH); //glEnable(GL_LINE_SMOOTH); //glEnable(GL_POLYGON_SMOOTH); //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); BuildTowerList();//建立塔的显示列表 return TRUE; }
bool CCEGLView::initGL() { m_hDC = GetDC(m_hWnd); SetupPixelFormat(m_hDC); //SetupPalette(); m_hRC = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, m_hRC); GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); return false; } if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { CCLog("Ready for GLSL\n"); } else { CCLog("Not totally ready :( \n"); } if (glewIsSupported("GL_VERSION_2_0")) { CCLog("Ready for OpenGL 2.0\n"); } else { CCLog("OpenGL 2.0 not supported\n"); } return true; }
void director::create_dc() { m_hDC = GetDC((HWND)m_wgl->m_window->m_hWnd); SetupPixelFormat(m_hDC); m_hRC = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, m_hRC); }
CCGLDevice(HWND hWnd): _hWnd(hWnd) { HDC hDC = GetDC(hWnd); SetupPixelFormat(hDC); _hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, _hRC); }
void CShowModelPanel::Init(void) { // init the DC and RC m_pDC = ::GetDC(m_hWnd); SetupPixelFormat(); m_pGLRC = wglCreateContext(m_pDC); wglMakeCurrent(m_pDC, m_pGLRC); // set the parameters for rendering s_pGluQuadricObj = gluNewQuadric(); gluQuadricNormals(s_pGluQuadricObj, GLU_SMOOTH); //smooth normals gluQuadricTexture(s_pGluQuadricObj, GL_TRUE); // using texture // init the viewpoint m_gGlobalCam.Init(); GetPanelSize(m_nWidth, m_nHeight); m_gGlobalCam.SetAspect(double(m_nWidth)/double(m_nHeight)); // init the flags m_bLButtonDown = false; m_bRButtonDown = false; m_bIsInit = true; // init the gr pointer m_pModel = NULL; m_gProjector.SetTSize(cv::Size(320, 240)); }
int main(void) { // print user instructions cout << " Hit the F1 key to Toggle between Fullscreen and windowed mode" << endl; cout << " Hit ESC to quit" << endl; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) // try to initialize SDL video module { cerr << "Failed initializing SDL Video : " << SDL_GetError() << endl; // report error if it fails return 1; // we use this instead of Quit because SDL isn't yet initialized } // Set up the format for the pixels of the OpenGL drawing surface SetupPixelFormat(); // Create our window, we pass caption for the window, the width, height and video flags required CreateMyWindow("www.GameTutorials.com - Camera Mouse Rotation", SCREEN_WIDTH, SCREEN_HEIGHT, VideoFlags); // Initializes our OpenGL drawing surface Init(); // Run our message loop MainLoop(); // quit main returning success return 0; }
bool APIENTRY InitHardware (bool allowsoftware, bool nostencil, int multisample, PrintTextFunc pf) #endif { #ifndef unix m_Window=Window; m_hDC = GetDC(Window); #endif if (!SetupPixelFormat(allowsoftware, nostencil, multisample, pf)) { pf ("R_OPENGL: Reverting to software mode...\n"); return false; } #ifndef unix m_hRC = wglCreateContext(m_hDC); if (m_hRC == NULL) { pf ("R_OPENGL: Couldn't create render context. Reverting to software mode...\n"); return false; } wglMakeCurrent(m_hDC, m_hRC); #endif return true; }
bool CCEGLView::initGL() { if ( !m_bIsEditor ) m_hDC = GetDC(m_hWnd); m_nPixelFormat = SetupPixelFormat(m_hDC); //SetupPalette(); m_hRC = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, m_hRC); // check OpenGL version at first const GLubyte* glVersion = glGetString(GL_VERSION); CCLOG("OpenGL version = %s", glVersion); if ( atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; sprintf(strComplain, "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.", glVersion); CCMessageBox(strComplain, "OpenGL version too old"); return false; } GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { CCMessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error"); return false; } if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { CCLog("Ready for GLSL"); } else { CCLog("Not totally ready :("); } if (glewIsSupported("GL_VERSION_2_0")) { CCLog("Ready for OpenGL 2.0"); } else { CCLog("OpenGL 2.0 not supported"); } if(glew_dynamic_binding() == false) { CCMessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error"); return false; } // Enable point size by default on windows. glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); return true; }
static bool APIENTRY InitHardware (bool allowsoftware, bool nostencil, int multisample) { if (!SetupPixelFormat(allowsoftware, nostencil, multisample)) { Printf ("R_OPENGL: Reverting to software mode...\n"); return false; } return true; }
int CHapticViewerView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; SetupPixelFormat(); wglMakeCurrent(NULL,NULL); return 0; }
int CGLView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 여기에 특수화된 작성 코드를 추가합니다. SetupPixelFormat(::GetDC(m_hWnd)); Init(); return 0; }
// Initialize OpenGL graphics void InitGraphics() { hDC = GetDC(hWnd); SetupPixelFormat(); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); glClearColor(0, 0, 0, 0.5); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); }
// Initialize OpenGL graphics void OpenGlInit::OnCreate(HDC _hDC) { hDC = _hDC; SetupPixelFormat(); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); glClearColor(0, 0, 0, 0.5); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); }
VOID CRender::CreateRenderContext(HWND hWnd) { HGLRC hrc = NULL; PAINTSTRUCT ps; // Get a handle to the device context m_hdc = BeginPaint(hWnd, &ps); // Setup pixel format for the device context SetupPixelFormat(m_hdc); // Create a rendering context associated to the device context hrc = wglCreateContext(m_hdc); // Make the rendering context current wglMakeCurrent(m_hdc, hrc); }
BOOL GLDevice::initialize(HWND hWnd) { GLASSERT(_hDC == NULL); _hDC = GetDC(hWnd); SetupPixelFormat(_hDC); _hGL = wglCreateContext(_hDC); wglMakeCurrent(_hDC, _hGL); GLenum flag = glewInit(); GLASSERT(flag == GLEW_OK); _hWnd = hWnd; return TRUE; }
BOOL CCY457OpenGLView::InitializeOpenGL() { //Get a DC for the Client Area m_pDC = new CClientDC(this); //Failure to Get DC if(m_pDC == NULL) { MessageBox("Error Obtaining DC"); return FALSE; } //Failure to set the pixel format if(!SetupPixelFormat()) { return FALSE; } //Create Rendering Context m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ()); //Failure to Create Rendering Context if(m_hRC == 0) { MessageBox("Error Creating RC"); return FALSE; } //Make the RC Current if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE) { MessageBox("Error making RC Current"); return FALSE; } //Specify Black as the clear color ::glClearColor(0.0f,0.0f,0.0f,0.0f); //Specify the back of the buffer as clear depth ::glClearDepth(1.0f); //Enable Depth Testing ::glEnable(GL_DEPTH_TEST); //¼ÓÔØÎÆÀí LoadGLTextures(); return TRUE; }
int COpenGLView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 m_pDC = new CClientDC(this); // 程序创建时,生成RC [8/20/2010 foryond] SetupPixelFormat(m_pDC); this->m_hRC = wglCreateContext(m_pDC->GetSafeHdc()); wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); InitOpenGL(); //初始化函数 return 0; }
HGLRC CDrawableWidget::InitOglStuff() { /*if(!m_bOglInitialized) {*/ // TRACE("Initialized OGL stuff\n"); // m_ghDC = GetDC(); if (!SetupPixelFormat()) { // return; // PostQuitMessage (0); } HGLRC ghRC = wglCreateContext(SafeGrabDC()->GetSafeHdc()); if(ghRC != NULL) { m_bOglInitialized = true; } else { DWORD nCurrError = GetLastError(); LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nCurrError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); TRACE("CreateContext failed %d (\"%s\")\n", nCurrError, lpMsgBuf); } wglMakeCurrent(SafeGrabDC()->GetSafeHdc(), ghRC); GetClientRect(&m_rect); // TRACE("%d %d -- %d %d\n", m_rect.right, m_rect.top, m_rect.left, m_rect.bottom); initializeGL(m_rect.right, m_rect.bottom, TRUE, m_lfNear, m_lfFar); m_lfAspect = m_rect.right/(double)m_rect.bottom; if(m_bRayPickerValid) { SetRayPickerVals(m_rayPicker); } return ghRC; }
bool CCEGLView::initGL() { m_hDC = GetDC(m_hWnd); SetupPixelFormat(m_hDC); //SetupPalette(); m_hRC = wglCreateContext(m_hDC); wglMakeCurrent(m_hDC, m_hRC); // check OpenGL version at first const GLubyte* glVersion = glGetString(GL_VERSION); CCLOG("OpenGL version = %s", glVersion); if ( atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; sprintf(strComplain, "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", glVersion); CCMessageBox(strComplain, "OpenGL version tooooooooooold"); } GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); return false; } if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) { CCLog("Ready for GLSL"); } else { CCLog("Not totally ready :("); } if (glewIsSupported("GL_VERSION_2_0")) { CCLog("Ready for OpenGL 2.0"); } else { CCLog("OpenGL 2.0 not supported"); } return true; }
void GameWindow::InitOpenGL() { GetClientRect(m_hwnd, &m_rDimensions); m_hdc = GetDC(m_hwnd); if (!SetupPixelFormat()) PostQuitMessage (0); m_hrc = wglCreateContext(m_hdc); wglMakeCurrent(m_hdc, m_hrc); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); SizeOpenGLScreen(m_rDimensions.right, m_rDimensions.bottom); }
void OGLWindow::createContexts(HWND hWnd, bool StencilBufferEnabled) { hWND_ = hWnd; hDC_ = GetDC(hWND_); SetupPixelFormat(hDC_, StencilBufferEnabled); setupPalette(); // create rendering context and make it current if(! (hRC_ = wglCreateContext(hDC_))) throw CantInitialize (); if(! wglMakeCurrent(hDC_, hRC_)) throw CantInitialize (); OnCreate(); }
/* ================ rvGEWorkspace::Attach Attaches the workspace to the given window. This is usually done after the window is created and the file has been loaded. ================ */ bool rvGEWorkspace::Attach ( HWND wnd ) { assert ( wnd ); mWnd = wnd; // Initialize the pixel format for this window SetupPixelFormat ( ); // Jam the workspace pointer into the userdata window long so // we can retrieve the workspace from the window later SetWindowLong ( mWnd, GWL_USERDATA, (LONG) this ); UpdateTitle ( ); return true; }
BOOL COpenGLView::InitializeOpenGL() { // Can we put this in the constructor? m_pDC = new CClientDC(this); if ( NULL == m_pDC ) // failure to get DC { SetError(1); return FALSE; } if (!SetupPixelFormat()) { return FALSE; } //n = ::GetPixelFormat(m_pDC->GetSafeHdc()); //::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd); // CreateRGBPalette(); if ( 0 == (m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() ) ) ) { SetError(4); return FALSE; } if ( FALSE == ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC ) ) { SetError(5); return FALSE; } // specify black as clear color ::glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); // specify the back of the buffer as clear depth ::glClearDepth( 1.0f ); // enable depth testing ::glEnable( GL_DEPTH_TEST ); return TRUE; }
static bool APIENTRY InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample) { m_Window=Window; m_hDC = GetDC(Window); if (!SetupPixelFormat(m_hDC, allowsoftware, nostencil, multisample)) { Printf ("R_OPENGL: Reverting to software mode...\n"); return false; } m_hRC = 0; if (wglCreateContextAttribsARB != NULL) { int ctxAttribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, gl_debug? WGL_CONTEXT_DEBUG_BIT_ARB : 0, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0 }; m_hRC = wglCreateContextAttribsARB(m_hDC, 0, ctxAttribs); } if (m_hRC == 0) { m_hRC = wglCreateContext(m_hDC); } if (m_hRC == NULL) { Printf ("R_OPENGL: Couldn't create render context. Reverting to software mode...\n"); return false; } wglMakeCurrent(m_hDC, m_hRC); return true; }
BOOL COpenGLView::InitializeOpenGL(CDC* pDC) { m_pDC=pDC; SetupPixelFormat(); //生成绘制描述表 m_hRC = ::wglCreateContext(m_pDC->GetSafeHdc()); //置当前绘制描述表 ::wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); //gl Settings ::glShadeModel(GL_SMOOTH); ::glClearColor(0.0F, 0.0F, 0.0F, 1.0F); //::glClearColor(1.0F, 1.0F, 1.0F, 1.0F); ::glClearDepth(1.0F); //glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glDisable(GL_DITHER); GLfloat ambientLight[] = { 0.1f, 0.1f, 0.1f, 1.0f}; GLfloat diffuseLight[] = { 0.05f, 0.05f, 0.05f, 1.0f}; GLfloat lightPos[] = { 0.0f, 200.0f, 200.0f, 1.0f}; glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat no_mat[] = { 0.5, 0.5, 0.8, 1.0 }; glMaterialfv(GL_FRONT, GL_FRONT_AND_BACK, no_mat); Model = GL3DS_initialize_dc10(); Axis = GL3DS_initialize_axis(); return TRUE; }
static void make_window(const char* title) { RECT WindowRect = {0,0,0,0}; int width, height; DWORD dwExStyle; DWORD dwStyle; if (fullscreen) { HDC screenDC=GetDC(NULL); WindowRect.left = WindowRect.top = 0; WindowRect.right=GetDeviceCaps(screenDC, HORZRES); WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES); ReleaseDC(NULL, screenDC); dwExStyle=WS_EX_TOPMOST; dwStyle=WS_POPUP; while(ShowCursor(false) >= 0); } else { // Version 5 screensaver logic kills all MODE_WINDOW graphics before starting one // in fullscreen mode, then restarts the ones it killed when screensaver stops. // To be compatible with V5, we remember and restore the MODE_WINDOW dimensions. FILE *f = boinc_fopen("gfx_info", "r"); if (f) { // ToDo: change this to XML parsing fscanf(f, "%d %d %d %d\n", &rect.left, &rect.top, &rect.right, &rect.bottom); fclose(f); } WindowRect = rect; dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; while(ShowCursor(true) < 0); } char window_title[256]; if (title) { strcpy(window_title, title); } else { APP_INIT_DATA aid; boinc_get_init_data(aid); if (!strlen(aid.app_name)) strcpy(aid.app_name, "BOINC Application"); get_window_title(window_title, 256); } //fprintf(stderr, "Setting window title to '%s'.\n", window_title); hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title, dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top, WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL ); if (!SetForegroundWindow(hWnd)) { fprintf(stderr, "%s ERROR: Unable to set foreground window (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } if (!GetCursorPos(&mousePos)) { fprintf(stderr, "%s ERROR: Unable to get mouse cursor position (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } hDC = GetDC(hWnd); if (!hDC) { fprintf(stderr, "%s ERROR: Couldn't get a device context for the window (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } SetupPixelFormat(hDC); hRC = wglCreateContext(hDC); if (!hRC) { fprintf(stderr, "%s ERROR: Unable to create OpenGL context (0x%x).\n", boinc_msg_prefix(), GetLastError() ); ReleaseDC(hWnd, hDC); return; } if(!wglMakeCurrent(hDC, hRC)) { fprintf(stderr, "%s ERROR: Unable to make OpenGL context current (0x%x).\n", boinc_msg_prefix(), GetLastError() ); ReleaseDC(hWnd, hDC); wglDeleteContext(hRC); return; } // use client area for resize when not fullscreen if (current_graphics_mode != MODE_FULLSCREEN) { GetClientRect(hWnd, &WindowRect); } width = WindowRect.right-WindowRect.left; height = WindowRect.bottom-WindowRect.top; ShowWindow(hWnd, SW_SHOW); SetFocus(hWnd); app_graphics_init(); app_graphics_resize(width, height); window_ready=true; }
LRESULT WindowsEventLoop::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int zDelta=0; switch(uMsg) { case WM_CREATE: { m_hdc = GetDC(hWnd); SetupPixelFormat(); int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0}; HGLRC tmpContext = wglCreateContext(m_hdc); wglMakeCurrent(m_hdc, tmpContext); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB"); if (!wglCreateContextAttribsARB) { //m_logger->Print(CLogger::Failure,"OpenGL 3.0 is not supported, falling back to GL 2.1"); m_hglrc = tmpContext; } else { m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribs); wglDeleteContext(tmpContext); } wglMakeCurrent(m_hdc, m_hglrc); m_isRunning = true; } break; case WM_DESTROY: case WM_CLOSE: wglMakeCurrent(m_hdc, NULL); wglDeleteContext(m_hglrc); m_isRunning = false; PostQuitMessage(0); return 0; break; case WM_SIZE: { m_height = HIWORD(lParam); m_width = LOWORD(lParam); m_pActivityHandler->onDeactivate(); Render::SetScreenSize(m_width,m_height); m_pActivityHandler->onActivate(); } break; case WM_KEYDOWN: Global::pContext->pInputService->GetKeyboard()->HandleKeyDown(Global::pContext->pInputService->GetKeyboard()->TranslateCode(wParam)); break; case WM_KEYUP: Global::pContext->pInputService->GetKeyboard()->HandleKeyUp(Global::pContext->pInputService->GetKeyboard()->TranslateCode(wParam)); break; case WM_MOUSEWHEEL: zDelta = GET_WHEEL_DELTA_WPARAM(wParam); //m_input->m_currMouse->Wheel+=zDelta; break; case WM_KILLFOCUS: m_enabled=true; break; case WM_SETFOCUS: m_enabled=false; break; default: break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HDC hDC; static HGLRC hRC; int height, width; // 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); break; case WM_ACTIVATEAPP: // activate app break; case WM_PAINT: // paint PAINTSTRUCT ps; BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: // left mouse button break; case WM_RBUTTONDOWN: // right mouse button break; case WM_MOUSEMOVE: // mouse movement break; case WM_LBUTTONUP: // left button release break; case WM_RBUTTONUP: // right button release break; case WM_KEYUP: break; case WM_KEYDOWN: int fwKeys; LPARAM keyData; fwKeys = (int)wParam; // virtual-key code keyData = lParam; // key data switch (fwKeys) { case VK_ESCAPE: PostQuitMessage(0); break; default: break; } break; default: break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
bool_t CC_CALL GLRenderContext::init(HWND _hWnd, uint32_t _width, uint32_t _height, uint32_t _bpp) { DEVMODE dm; LONG res; hWnd = _hWnd; if(fullScreenMode) { /* Device Mode */ memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); // use default values from current setting EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); dm.dmPelsWidth = _width; dm.dmPelsHeight = _height; dm.dmBitsPerPel = _bpp; dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); if (res != DISP_CHANGE_SUCCESSFUL) { // try again without forcing display frequency dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } if(res != DISP_CHANGE_SUCCESSFUL) { fullScreenMode = FALSE; } switch(res) { case DISP_CHANGE_SUCCESSFUL: break; case DISP_CHANGE_RESTART: CC_ERROR_LOG(_T("Switch to fullscreen: The computer must be restarted in order for the graphics mode to work.")); break; case DISP_CHANGE_BADFLAGS: CC_ERROR_LOG(_T("Switch to fullscreen: An invalid set of flags was passed in.")); break; case DISP_CHANGE_BADPARAM: CC_ERROR_LOG(_T("Switch to fullscreen: An invalid parameter was passed in. This can include an invalid flag or combination of flags.")); break; case DISP_CHANGE_FAILED: CC_ERROR_LOG(_T("Switch to fullscreen: The display driver failed the specified graphics mode.")); break; case DISP_CHANGE_BADMODE: CC_ERROR_LOG(_T("Switch to fullscreen: The graphics mode is not supported.")); break; default: CC_ERROR_LOG(_T("An unknown error occured while changing to fullscreen.")); break; } } /* Did We Get A Device Context? */ if (!(hDC = GetDC(hWnd))) { MessageBox(NULL,_T("Can't Create A GL Device Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(SetupPixelFormat(hWnd, hDC, _bpp, depthBuffer, stencilBuffer) == FALSE) { return FALSE; } /* Are We Able To Get A Rendering Context? */ if (!(hRC = wglCreateContext(hDC))) { MessageBox(NULL,_T("Can't Create A GL Rendering Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!change(NULL)) { wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); return FALSE; } return TRUE; }