GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


Why fails that window creation? by SUNSTAR
1
 
bool uglCreateWindow(int iWidth, 
                     int iHeight, 
                     int iColorBits, 
                     int iDepthBits, 
                     int iStencilBits, 
                     bool bFullScreen,
                     const char* sTitle)
{
  GLuint iPixelFormat;

  WNDCLASS wc;

  DWORD dwExStyle;
  DWORD dwStyle;

  RECT WindowRect;
  WindowRect.left   = (long)0;
  WindowRect.right  = (long)iWidth;
  WindowRect.top    = (long)0;
  WindowRect.bottom = (long)iHeight;

  bFullscreen=bFullScreen;

  hInstance        = GetModuleHandle(NULL);
  wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc.lpfnWndProc   = (WNDPROC) uglWndProc;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.hInstance     = hInstance;
  wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = NULL;
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = "UltimateGL3-Engine";

  if (!RegisterClass(&wc))
  {
    return false;
  }

  if (bFullscreen)
  {
    DEVMODE dmScreenSettings;
    memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
    dmScreenSettings.dmSize=sizeof(dmScreenSettings);
    dmScreenSettings.dmPelsWidth= iWidth;
    dmScreenSettings.dmPelsHeight= iHeight;
    dmScreenSettings.dmBitsPerPel= iColorBits;
    dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

    if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
    {
      return false;
    }
  }

  if (bFullscreen)
  {
    dwExStyle=WS_EX_APPWINDOW;
    dwStyle=WS_POPUP;
    ShowCursor(false);
  } else {
    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    dwStyle=WS_OVERLAPPEDWINDOW;
  }

  AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);

  static PIXELFORMATDESCRIPTOR pfd=
  {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    iColorBits,
    0, 0, 0, 0, 0, 0,
    0,
    0,
    0,
    0, 0, 0, 0,
    iDepthBits,
    iStencilBits,
    0,
    PFD_MAIN_PLANE,
    0,
    0, 0, 0
  };

  if (!(hWnd=CreateWindowEx(dwExStyle,
                            "UltimateGL3-Engine",
                            sTitle,
                            WS_CLIPSIBLINGS |
                            WS_CLIPCHILDREN |
                            dwStyle,
                            0, 0,
                            WindowRect.right-WindowRect.left,
                            WindowRect.bottom-WindowRect.top,
                            NULL,
                            NULL,
                            hInstance,
                            NULL)) ||
      !(hDC=GetDC(hWnd)) ||
      !(iPixelFormat=ChoosePixelFormat(hDC,&pfd)) ||
      !SetPixelFormat(hDC,iPixelFormat,&pfd) ||
      !(hRC=wglCreateContext(hDC)) ||
      !wglMakeCurrent(hDC,hRC))
  {
    DWORD err=GetLastError();
    uglDestroyWindow();
    return false;
  }
...