Windows XP And OpenGL...

Started by
1 comment, last by The Great Sephiroth 20 years, 7 months ago
Got a seriour problem with my program in Windows XP. Apparently it doesn''t want to go fullscreen. It will change the desktop resolution to 800x600 which it should do, but then the window is simply stretched to the max extents of the monitor, covering up the task-bar. I can click and drag the window out of the way though, which makes no sense. Below is the window creation source. Maybe one of you can either spot what the heck is wrong, or tell me that XP just sucks, which I already know.

bool CreateGLWindow()
  {
  GLuint PixelFormat;
  PIXELFORMATDESCRIPTOR pfd;
  DEVMODE dmScreenSettings;

  memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
  dmScreenSettings.dmSize = sizeof(DEVMODE);
  dmScreenSettings.dmPelsWidth = Config.Width;
  dmScreenSettings.dmPelsHeight = Config.Height;
  dmScreenSettings.dmBitsPerPel = Config.Bits;
  dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

  if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    {
    MessageBox(NULL, "Cannot set fullscreen mode.", "Startup Video Error", MB_OK | MB_ICONSTOP);
    ErrorLog("OpenGL.cpp: Could not set fullscreen mode.");
    return false;
    }

  if((WinData.Handle = CreateWindowEx(WS_EX_TOPMOST, WIN_CLASS_NAME, WIN_TITLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, Config.Width, Config.Height, NULL, NULL, WinData.Instance, NULL)) == NULL)
    {
    ErrorLog("OpenGL.cpp: Could not create the primary window.");
    return false;
    }

  memset(&pfd, 0, sizeof(pfd));
  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  pfd.nVersion = 1;
  pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  pfd.iPixelType = PFD_TYPE_RGBA;
  pfd.cColorBits = Config.Bits;
  pfd.cDepthBits = Config.Depth;
  pfd.iLayerType = PFD_MAIN_PLANE;

  if((WinData.DeviceContext = GetDC(WinData.Handle)) == NULL)
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: Could not get a device context.");
    return false;
    }

  if((PixelFormat = ChoosePixelFormat(WinData.DeviceContext, &pfd)) == NULL)
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: Can''t find a suitable pixel format.");
    return false;
    }

  if(!SetPixelFormat(WinData.DeviceContext, PixelFormat, &pfd))
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: Can''t set the pixel format.");
    return false;
    }

  if((WinData.RenderContext = wglCreateContext(WinData.DeviceContext)) == NULL)
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: Can''t create a GL rendering context.");
    return false;
    }

  if(!wglMakeCurrent(WinData.DeviceContext, WinData.RenderContext))
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: Can''t activate the GL rendering context.");
    return false;
    }

  ShowWindow(WinData.Handle, SW_SHOW);
  SetForegroundWindow(WinData.Handle);
  SetFocus(WinData.Handle);
  ResizeGLScreen(Config.Width, Config.Height);

  if(!InitGL())
    {
    KillGLWindow();
    ErrorLog("OpenGL.cpp: OpenGL initialization failed.");
    return false;
    }

  MainLog("Primary window created.");
  return true;
  }
And just in case you need it, here''s the "InitGL()" and "ResizeGLScreen()" functions.

bool InitGL()
  {
  if(!LoadTextures())
    return false;

  glEnable(GL_CULL_FACE);
  glCullFace(GL_BACK);
  glFrontFace(GL_CCW);
  glEnable(GL_TEXTURE_2D);
  glShadeModel(GL_SMOOTH);
  glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
  glClearDepth(1.0f);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  return true;
  }

void ResizeGLScreen(short int Width, short int Height)
  {
  if(Height == 0)
    Height = 1;

  glViewport(0, 0, Width, Height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.05f, 4096.0f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  return;
  }
Ignore the line referencing "LoadTextures()" because it isn''t being used just yet. Am I missing something, or is XP just being crappy to me? -The Great Sephiroth
-The Great Sephiroth
Advertisement
the ex-style should be WS_EX_APPWINDOW and style should be WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS
hth
Thanks, that fixed it. I had ALWAYS (for over a year now, going on two) done it the way I posted originally before, and it had ALWAYS worked. Guess XP just won''t allow any slack at all, where 98SE and the others were. It''s better that I know now though. Thanks again.

-The Great Sephiroth
-The Great Sephiroth

This topic is closed to new replies.

Advertisement