Difference for arch/ogl/wgl.c from version 1.5 to 1.6


version 1.5 version 1.6
Line 1
 
Line 1
 //opengl platform specific functions for WGL - added by Peter Hawkins  //opengl platform specific functions for WGL - added by Peter Hawkins
   //fullscreen example code donated by Jeff Slutter
   //everything merged together and cleaned up by Matt Mueller (with some win32 help from Nirvana)
 #include <windows.h>  #include <windows.h>
   #include <mmsystem.h>
 #include "ogl_init.h"  #include "ogl_init.h"
 #include "vers_id.h"  #include "vers_id.h"
 #include "error.h"  #include "error.h"
   #include "key.h"
   #include "joy.h"
   #include "mouse.h"
 /*#include "event.h"*/  /*#include "event.h"*/
   
 extern HDC hDC;  
 extern HWND g_hWnd;  
   
 extern int ogl_voodoohack;  HINSTANCE hInst;
   HWND g_hWnd=NULL;
   
   extern int Inferno_verbose;
   
   static int mouse_hidden=0;
   
   
   //extern unsigned int key_wparam, key_lparam, key_msg;
   void keyboard_handler();
   extern int WMKey_Handler_Ready;
   
   HDC hDC;
   HGLRC hRC;
   
 static int GLPREF_width,GLPREF_height;  static int GLPREF_width,GLPREF_height;
 static int GLSTATE_width,GLSTATE_height;  static int GLSTATE_width,GLSTATE_height;
Line 25
 
Line 41
 void OpenGL_Shutdown(void);  void OpenGL_Shutdown(void);
   
   
 //void ogl_init_texture_list_internal(void){  void PumpMessages(void)
 void ogl_do_fullscreen_internal(void){  {
  if (GLPREF_windowed==ogl_fullscreen){    MSG msg;
  ogl_smash_texture_list_internal();  
  OpenGL_Shutdown();    while (PeekMessage(&msg,NULL,0,0,PM_REMOVE|PM_NOYIELD))
  OpenGL_Initialize();    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }   }
 }  }
   static void finiObjects()
   {
   // ogl_close();
   //   if(mouse_hidden){
   //    ShowCursor(TRUE);
   // mouse_hidden=0;
   //   }
   
 void ogl_swap_buffers_internal(void){   //  DisableOpenGL( g_hWnd, hDC, hRC );
  SwapBuffers( hDC );  
 //        glXSwapBuffers(dpy,win);  
 }  }
 int ogl_init_window(int x, int y){  
  if (x<=320){  
  x*=2;  long PASCAL DescentWndProc(HWND hWnd,UINT message,
  y*=2;      WPARAM wParam,LPARAM lParam )
   {
     switch(message)
     {
   
      case WM_KEYDOWN:
      case WM_KEYUP:
    if (WMKey_Handler_Ready) {
   //      key_wparam=wParam; key_lparam=lParam; key_msg=message;
      keyboard_handler();
  }   }
  GLPREF_width=x;   break;
  GLPREF_height=y;     case WM_MOUSEMOVE:
  if (gl_initialized){     case WM_LBUTTONDOWN:
  if (!ogl_fullscreen && GLPREF_windowed){     case WM_LBUTTONUP:
 // SetWindowPos(g_hWnd,0,0,0,x+10,y+30,0);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM     case WM_RBUTTONDOWN:
  SetWindowPos(g_hWnd,0,0,0,x,y,0);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM     case WM_RBUTTONUP:
  }else{     case WM_NCMOUSEMOVE:
  ogl_smash_texture_list_internal();     case WM_NCLBUTTONDOWN:
  OpenGL_Shutdown();     case WM_NCLBUTTONUP:
  OpenGL_Initialize();     case WM_NCRBUTTONDOWN:
      case WM_NCRBUTTONUP:
    break;
      case WM_PALETTECHANGED:
      case WM_PALETTEISCHANGING:
      return 0;
      case WM_ACTIVATEAPP:
   //     Win32_Key_Hook(wParam);
   // DPH: This doesn't work... no idea why not...
    break;
      case WM_DESTROY:
            finiObjects();
    PostQuitMessage(0);
    break;
     }
     return DefWindowProc(hWnd,message,wParam,lParam);
  }   }
  //                XResizeWindow(dpy,win,x,y);  
  }else {  
  /*  
     glxcontext=glXCreateContext(dpy,visinfo,0,GL_TRUE);  
  // ogl_destroy_window();//destroy current window before making a new one  
   
  //create colormap  
  swa.colormap=XCreateColormap(dpy,RootWindow(dpy,visinfo->screen),visinfo->visual,AllocNone);  
  //create window  
  swa.border_pixel=0;  
  swa.event_mask=ExposureMask | StructureNotifyMask | KeyPressMask;  
  // swa.event_mask=ExposureMask | StructureNotifyMask;  
  win = XCreateWindow(dpy,RootWindow(dpy,visinfo->screen),0,0,x,y,0,visinfo->depth,InputOutput,visinfo->visual,CWBorderPixel|CWColormap|CWEventMask,&swa);  
  // XStoreName(dpy,win,DESCENT_VERSION " " D1X_DATE);  
  XStoreName(dpy,win,"agry");  
  XMapWindow(dpy,win);  
   
  glXMakeCurrent(dpy,win,glxcontext);  
  */  void ogl_swap_buffers_internal(void){
  OpenGL_Initialize();   SwapBuffers( hDC );
  if (GLPREF_windowed){  
  SetWindowPos(g_hWnd,0,0,0,x,y,0);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM  
  }   }
   
   int get_win_x_bs(void){
   // return GetSystemMetrics(SM_CXBORDER)*2
    return GetSystemMetrics(SM_CXFIXEDFRAME)*2;
   }
   int get_win_y_bs(void){
   // return GetSystemMetrics(SM_CYBORDER)*2+GetSystemMetrics(SM_CYCAPTION);
    return GetSystemMetrics(SM_CXFIXEDFRAME)*2+GetSystemMetrics(SM_CYCAPTION);
   }
   
   void win32_create_window(int x,int y)
   {
    WNDCLASS wcDescentClass;
    int flags;
   
    wcDescentClass.lpszClassName = "WinD1X";
    wcDescentClass.hInstance     = hInst;
    wcDescentClass.lpfnWndProc   = DescentWndProc;
    wcDescentClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wcDescentClass.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
    wcDescentClass.lpszMenuName  = NULL;
    wcDescentClass.hbrBackground = NULL;
    wcDescentClass.style         = CS_OWNDC;
    wcDescentClass.cbClsExtra    = 0;
    wcDescentClass.cbWndExtra    = 0;
   
    // Register the class
    RegisterClass(&wcDescentClass);
    if (ogl_fullscreen)
    flags=WS_POPUP | WS_SYSMENU;
    else
    flags=WS_OVERLAPPED | WS_BORDER;
   
    if (!ogl_fullscreen){
    x+=get_win_x_bs();y+=get_win_y_bs();
    }
    g_hWnd = CreateWindowEx(0,
    "WinD1X",
    "Descent",
    flags,
    0, 0,
    x,y,
   // GetSystemMetrics(SM_CXSCREEN),
   // GetSystemMetrics(SM_CYSCREEN),
    NULL,
    NULL,
    hInst,
    NULL
       );
   
   // if (!g_hWnd) return; // CRAP!
    if (!g_hWnd) Error("no window?\n");
    ShowWindow(g_hWnd,SW_SHOWNORMAL);
    UpdateWindow(g_hWnd);
   
    if (ogl_fullscreen){
           ShowCursor(FALSE);
           mouse_hidden = 1;
    }
   
    key_init();
    mouse_init(0);
    joy_init(JOYSTICKID1);
   // printf("arch_init successfully completed\n");
   
    OpenGL_Initialize();
   
  gl_initialized=1;   gl_initialized=1;
  }   }
  return 0;  void win32_destroy_window(void){
    if (mouse_hidden){
    ShowCursor(TRUE);
    mouse_hidden = 0;
    }
    if (g_hWnd){
    key_close();
    mouse_close();
    joy_close();
    DestroyWindow(g_hWnd);
    }
 }  }
 void ogl_destroy_window(void){  void ogl_destroy_window(void){
  if (gl_initialized){   if (gl_initialized){
    ogl_smash_texture_list_internal();
  OpenGL_Shutdown();   OpenGL_Shutdown();
 /*                glXDestroyContext(dpy,glxcontext);   win32_destroy_window();
  XDestroyWindow(dpy,win);  
                 XFreeColormap(dpy,swa.colormap);*/  
  gl_initialized=0;   gl_initialized=0;
  }   }
  return;   return;
 }  }
 void ogl_init(void){  
  // Save our gamma values because we'll probably be changing them,  
  // this way we can restore them on exit  
   
 // GetDeviceGammaRamp(GLPREF_windowdc,(LPVOID)Saved_gamma_values);//no  void ogl_do_fullscreen_internal(void){
    if (GLPREF_windowed==ogl_fullscreen){
    ogl_destroy_window();
    win32_create_window(GLPREF_width,GLPREF_height);
    }
   }
   
  /*        dpy=XOpenDisplay(0);  
  if(!dpy)  
  Error("no display\n");  
  else if (glXQueryExtension(dpy,&glx_erbase,&glx_evbase)==False)  
  Error("no glx\n");  
  else if (!(visinfo = glXChooseVisual(dpy,DefaultScreen(dpy),attribs)))  
                 Error("no visual\n");*/  
   
   int ogl_init_window(int x, int y){
   /* if (x<=320){
    x*=2;
    y*=2;
    }*/
    GLPREF_width=x;
    GLPREF_height=y;
    if (gl_initialized){
    if (!ogl_fullscreen && GLPREF_windowed){
    SetWindowPos(g_hWnd,0,0,0,x+get_win_x_bs(),y+get_win_y_bs(),SWP_NOMOVE);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM
   // SetWindowPos(g_hWnd,0,0,0,x,y,0);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM
    }else{
    ogl_destroy_window();
    win32_create_window(x,y);
    }
    }else {
    win32_create_window(x,y);
   /* if (GLPREF_windowed){
    SetWindowPos(g_hWnd,0,0,0,x,y,0);//the width/height seem to include borders/title/etc.. this isn't an exact value, but I didn't feel like testing enough to find the true values. -MPM
    }*/
    }
    return 0;
   }
   void ogl_init(void){
 }  }
 void ogl_close(void){  void ogl_close(void){
  ogl_destroy_window();   ogl_destroy_window();
    
  // Restore gamma values  
   
 // SetDeviceGammaRamp(GLPREF_windowdc,(LPVOID)Saved_gamma_values);//no.  
   
  /*        XCloseDisplay(dpy);*/  
 }  }
   
 //windows opengl fullscreen changing - curtousy (sp) of Jeff Slutter  
   //windows opengl fullscreen changing - courtesy of Jeff Slutter
   
 /*  /*
   
Line 268
 
Line 388
  // Make the context current   // Make the context current
  wglMakeCurrent(GLPREF_windowdc,GL_ResourceContext);   wglMakeCurrent(GLPREF_windowdc,GL_ResourceContext);
   
    // Save our gamma values because we'll probably be changing them,
    // this way we can restore them on exit
   
   // GetDeviceGammaRamp(GLPREF_windowdc,(LPVOID)Saved_gamma_values);
   
  return true;   return true;
   
 OpenGLError:  OpenGLError:
  // Shutdown OpenGL   // Shutdown OpenGL
  OpenGL_Shutdown();   OpenGL_Shutdown();
    Error("opengl init error\n");
  return false;   return false;
 }  }
   
Line 293
 
Line 418
  if(!GLPREF_windowed)   if(!GLPREF_windowed)
  ChangeDisplaySettings(NULL,0);   ChangeDisplaySettings(NULL,0);
   
    // Restore gamma values
   
   // SetDeviceGammaRamp(GLPREF_windowdc,(LPVOID)Saved_gamma_values);
    
  ReleaseDC(GLPREF_gamewindow,GLPREF_windowdc);   ReleaseDC(GLPREF_gamewindow,GLPREF_windowdc);
 }  }

Legend:
line(s) removed in v.1.5 
line(s) changed
 line(s) added in v.1.6