Advertisement
Guest User

Untitled

a guest
Jun 19th, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. bool WindowWin::Init(uint32 a_Width, uint32 a_Height)
  2. {
  3.     m_Width = a_Width;
  4.     m_Height = a_Height;
  5.  
  6.     m_Dim.x = (float)m_Width;
  7.     m_Dim.y = (float)m_Height;
  8.  
  9.     WNDCLASS temp = {
  10.         CS_HREDRAW | CS_VREDRAW | CS_OWNDC, // defines the class style
  11.         Win32Messages,                      // pointer to the message handler function
  12.         0,                                  // extra bytes following the window class structure
  13.         0,                                  // extra bytes following the window instance
  14.         m_Instance,                         // instance handle             
  15.         LoadIcon(NULL, IDI_APPLICATION),    // icon handle
  16.         LoadCursor(NULL, IDC_ARROW),        // cursor
  17.         NULL,                               // background brush
  18.         NULL,                               // menu name
  19.         "TmplQ"                             // window title
  20.     };
  21.     if (!RegisterClass(&temp)) { return false; }
  22.  
  23.     // Bram fixed my stuff
  24.     // Now with centered window!
  25.  
  26.     // Determine window position and dimensions
  27.     const int x = GetSystemMetrics(SM_CXSCREEN) / 2 - m_Width / 2;
  28.     const int y = GetSystemMetrics(SM_CYSCREEN) / 2 - m_Height / 2;
  29.  
  30.     m_Pos.x = (float)x;
  31.     m_Pos.y = (float)y;
  32.  
  33.     m_Center.x = (float)(m_Width / 2);
  34.     m_Center.y = (float)(m_Height / 2);
  35.  
  36.     const DWORD style = WS_OVERLAPPEDWINDOW;
  37.     const DWORD ext_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
  38.     RECT dim = {
  39.         0, 0,
  40.         m_Width, m_Height
  41.     };
  42.     AdjustWindowRect(&dim, style, FALSE);
  43.    
  44.     const int w = dim.right - dim.left;
  45.     const int h = dim.bottom - dim.top;
  46.  
  47.     m_Window = CreateWindowEx (
  48.         ext_style,
  49.         "TmplQ",                        // window class
  50.         "TmplQ",                        // window title
  51.         style,                          // visibility settings
  52.         x, y,
  53.         w, h,
  54.         NULL,
  55.         NULL,
  56.         temp.hInstance,
  57.         NULL
  58.     );
  59.     if (!m_Window) { return false; }
  60.  
  61.     if (!(m_WindowContext = GetDC(m_Window))) { return false; }
  62.  
  63.     LOG("Context: %x", m_WindowContext);
  64.  
  65.     PIXELFORMATDESCRIPTOR pfd = {
  66.         sizeof(PIXELFORMATDESCRIPTOR),                                  // size
  67.         1,                                                              // version
  68.         PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,     // flags
  69.         PFD_TYPE_RGBA,                                                  // pixel type
  70.         32,                                                             // color bits
  71.         0, 0, 0, 0, 0, 0, 0, 0,                                         // color rgba
  72.         0, 0, 0, 0, 0,                                                  // accum bits, rgba
  73.         24,                                                             // depth bits
  74.         0,                                                              // stencil bits
  75.         0,                                                              // aux buffers
  76.         PFD_MAIN_PLANE,                                                 // layer type
  77.         0,                                                              // reserved
  78.         0, 0, 0                                                         // layer, visible, damage
  79.     };
  80.  
  81.     unsigned int format;
  82.     if (!(format = ChoosePixelFormat(m_WindowContext, &pfd))) { return false; }
  83.  
  84.     if (!SetPixelFormat(m_WindowContext, format, &pfd)) { return false; }
  85.  
  86.     HGLRC hrc;
  87.     if (!(hrc = wglCreateContext(m_WindowContext))) { return false; }
  88.  
  89.     if (!wglMakeCurrent(m_WindowContext, hrc)) { return false; }
  90.  
  91.     GLenum status = glewInit();
  92.     if (status != GLEW_OK)
  93.     {
  94.         char error[256];
  95.         sprintf(error, "%s", glewGetErrorString(status));
  96.         MessageBoxA(NULL, error, "GLEW error", MB_OK | MB_ICONEXCLAMATION);
  97.         return false;
  98.     }
  99.  
  100.     ShowWindow(m_Window, 1);
  101.     UpdateWindow(m_Window);
  102.  
  103.     wglSwapIntervalEXT(0);
  104.  
  105.     s_WindowWin = this;
  106.  
  107.     return true;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement