version 1.4 | | version 1.5 |
---|
| | |
extern HDC hDC; | | extern HDC hDC; |
extern HWND g_hWnd; | | extern HWND g_hWnd; |
| | |
| | extern int ogl_voodoohack; |
| | |
| | |
| | static int GLPREF_width,GLPREF_height; |
| | static int GLSTATE_width,GLSTATE_height; |
| | static bool GLPREF_windowed; |
| | //static HWND GLPREF_gamewindow; |
| | #define GLPREF_gamewindow g_hWnd |
| | //static HDC GLPREF_windowdc; |
| | #define GLPREF_windowdc hDC |
| | |
| | static HGLRC GL_ResourceContext=NULL; |
| | //static WORD Saved_gamma_values[256*3]; |
| | bool OpenGL_Initialize(void); |
| | void OpenGL_Shutdown(void); |
| | |
| | |
| | //void ogl_init_texture_list_internal(void){ |
| | void ogl_do_fullscreen_internal(void){ |
| | if (GLPREF_windowed==ogl_fullscreen){ |
| | ogl_smash_texture_list_internal(); |
| | OpenGL_Shutdown(); |
| | OpenGL_Initialize(); |
| | } |
| | } |
| | |
void ogl_swap_buffers_internal(void){ | | void ogl_swap_buffers_internal(void){ |
SwapBuffers( hDC ); | | SwapBuffers( hDC ); |
// glXSwapBuffers(dpy,win); | | // glXSwapBuffers(dpy,win); |
} | | } |
int ogl_init_window(int x, int y){ | | int ogl_init_window(int x, int y){ |
SetWindowPos(g_hWnd,0,0,0,x+20,y+50,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 | | if (x<=320){ |
OGL_VIEWPORT(0,0,x,y); | | x*=2; |
| | y*=2; |
| | } |
| | GLPREF_width=x; |
| | GLPREF_height=y; |
if (gl_initialized){ | | if (gl_initialized){ |
| | if (!ogl_fullscreen && GLPREF_windowed){ |
| | // 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 |
| | 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_smash_texture_list_internal(); |
| | OpenGL_Shutdown(); |
| | OpenGL_Initialize(); |
| | } |
// XResizeWindow(dpy,win,x,y); | | // XResizeWindow(dpy,win,x,y); |
}else { | | }else { |
/* | | /* |
| | |
| | |
glXMakeCurrent(dpy,win,glxcontext); | | glXMakeCurrent(dpy,win,glxcontext); |
*/ | | */ |
| | OpenGL_Initialize(); |
| | 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 |
| | } |
gl_initialized=1; | | gl_initialized=1; |
} | | } |
return 0; | | return 0; |
} | | } |
void ogl_destroy_window(void){ | | void ogl_destroy_window(void){ |
if (gl_initialized){ | | if (gl_initialized){ |
| | OpenGL_Shutdown(); |
/* glXDestroyContext(dpy,glxcontext); | | /* glXDestroyContext(dpy,glxcontext); |
XDestroyWindow(dpy,win); | | XDestroyWindow(dpy,win); |
XFreeColormap(dpy,swa.colormap);*/ | | XFreeColormap(dpy,swa.colormap);*/ |
| | |
return; | | return; |
} | | } |
void ogl_init(void){ | | 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 |
| | |
/* dpy=XOpenDisplay(0); | | /* dpy=XOpenDisplay(0); |
if(!dpy) | | if(!dpy) |
Error("no display\n"); | | Error("no display\n"); |
| | |
Error("no glx\n"); | | Error("no glx\n"); |
else if (!(visinfo = glXChooseVisual(dpy,DefaultScreen(dpy),attribs))) | | else if (!(visinfo = glXChooseVisual(dpy,DefaultScreen(dpy),attribs))) |
Error("no visual\n");*/ | | Error("no visual\n");*/ |
| | |
} | | } |
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);*/ | | /* XCloseDisplay(dpy);*/ |
| | } |
| | |
| | //windows opengl fullscreen changing - curtousy (sp) of Jeff Slutter |
| | |
| | /* |
| | |
| | Windows Full Screen Setup |
| | |
| | =========================================================================== |
| | */ |
| | |
| | |
| | // Entering this function, the following values must be valid |
| | // GLPREF_width,GLPREF_height: preferred width and height |
| | // GLPREF_windowed: do we want windowed or full screen mode |
| | // GLPREF_gamewindow: handle to the window created for OpenGL |
| | // On exit from this function (if returned true) the following values will be set |
| | // GLSTATE_width,GLSTATE_height: real width and height of screen |
| | // GLPREF_windowdc: device context of the window |
| | // GL_ResourceContext: OpenGL resource context |
| | // Saved_gamma_values: Initial gamma values |
| | bool OpenGL_Initialize(void) |
| | { |
| | int width,height; |
| | int pf; |
| | PIXELFORMATDESCRIPTOR pfd, pfd_copy; |
| | |
| | GLPREF_windowed=!ogl_fullscreen; |
| | |
| | if(!GLPREF_windowed) |
| | { |
| | // First set our display mode |
| | // Create direct draw surface |
| | DEVMODE devmode; |
| | int retval; |
| | |
| | devmode.dmSize=sizeof(devmode); |
| | devmode.dmBitsPerPel=16; |
| | devmode.dmPelsWidth=GLPREF_width; |
| | devmode.dmPelsHeight=GLPREF_height; |
| | devmode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
| | |
| | retval=ChangeDisplaySettings(&devmode,0); |
| | |
| | if (retval!=DISP_CHANGE_SUCCESSFUL) |
| | { |
| | // we couldn't switch to the desired screen mode |
| | // fall back to 640x480 |
| | retval=-1; |
| | devmode.dmBitsPerPel=16; |
| | devmode.dmPelsWidth=640; |
| | devmode.dmPelsHeight=480; |
| | devmode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
| | |
| | retval=ChangeDisplaySettings(&devmode,0); |
| | if (retval!=DISP_CHANGE_SUCCESSFUL) |
| | { |
| | // we couldn't even switch to 640x480, we're out of here |
| | // restore screen mode to default |
| | ChangeDisplaySettings(NULL,0); |
| | goto OpenGLError; |
| | }else |
| | { |
| | // successful, change our global settings to reflect what |
| | // mode we are at |
| | GLPREF_width=640; |
| | GLPREF_height=480; |
| | } |
| | }else |
| | { |
| | // success at changing the video mode |
| | } |
| | } |
| | |
| | GLPREF_windowdc = GetDC(GLPREF_gamewindow); |
| | |
| | if(GLPREF_windowed) |
| | { |
| | // we want windowed mode, figure out how big the window is |
| | RECT rect; |
| | GetWindowRect(GLPREF_gamewindow,&rect); |
| | width=abs(rect.right-rect.left); |
| | height=abs(rect.bottom-rect.top); |
| | }else |
| | { |
| | RECT rect; |
| | // full screen mode, we want the window to be on top of everything |
| | SetWindowPos(GLPREF_gamewindow,HWND_TOPMOST,0,0,GLPREF_width,GLPREF_height,SWP_FRAMECHANGED); |
| | width=GLPREF_width; |
| | height=GLPREF_height; |
| | GetWindowRect(GLPREF_gamewindow,&rect); |
| | } |
| | |
| | GLSTATE_width = width; |
| | GLSTATE_height = height; |
| | |
| | // Now we finally setup OpenGL |
| | // If OpenGL is to be dynamically loaded, do this now (if the DLL isn't already |
| | // loaded) |
| | // remove the following error when you figure out what you want to do |
| | // it's put here to make sure you notice this |
| | #ifdef OGL_RUNTIME_LOAD |
| | ogl_init_load_library(); |
| | #endif |
| | |
| | // Setup our pixel format |
| | |
| | memset(&pfd,0,sizeof(pfd)); |
| | pfd.nSize = sizeof(pfd); |
| | pfd.nVersion = 1; |
| | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; |
| | // pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED; |
| | pfd.iPixelType = PFD_TYPE_RGBA; |
| | |
| | // Find the user's "best match" PFD |
| | pf = ChoosePixelFormat(GLPREF_windowdc,&pfd); |
| | if(pf == 0) |
| | { |
| | // no pixel format closely matches |
| | goto OpenGLError; |
| | } |
| | |
| | // Set the new PFD |
| | if(SetPixelFormat(GLPREF_windowdc,pf,&pfd)==FALSE) |
| | { |
| | // unable to set the pixel format |
| | goto OpenGLError; |
| | } |
| | |
| | // Now retrieve the PFD, we need to check some things |
| | if(DescribePixelFormat(GLPREF_windowdc,pf,sizeof(PIXELFORMATDESCRIPTOR),&pfd_copy)==0) |
| | { |
| | // unable to get the PFD |
| | goto OpenGLError; |
| | } |
| | |
| | // Make sure we are hardware accelerated |
| | /* if((pfd_copy.dwFlags&PFD_GENERIC_ACCELERATED)==0&&(pfd_copy.dwFlags&PFD_GENERIC_FORMAT)!=0) |
| | { |
| | // we are not hardware accelerated! |
| | goto OpenGLError; |
| | }*/ |
| | |
| | // Finally, create our OpenGL context and make it current |
| | GL_ResourceContext = wglCreateContext(GLPREF_windowdc); |
| | if(GL_ResourceContext==NULL) |
| | { |
| | // we couldn't create a context! |
| | goto OpenGLError; |
| | } |
| | |
| | // Make the context current |
| | wglMakeCurrent(GLPREF_windowdc,GL_ResourceContext); |
| | |
| | |
| | return true; |
| | |
| | OpenGLError: |
| | // Shutdown OpenGL |
| | OpenGL_Shutdown(); |
| | return false; |
| | } |
| | |
| | void OpenGL_Shutdown(void) |
| | { |
| | // Do any needed OpenGL shutdown here |
| | |
| | |
| | // Now do Window specific shutdown |
| | if(wglMakeCurrent)//check to make sure the function is valid (dyanmic loaded OpenGL) |
| | wglMakeCurrent(NULL, NULL); |
| | |
| | if(wglDeleteContext)//check to make sure the function is valid (dyanmic loaded OpenGL) |
| | wglDeleteContext(GL_ResourceContext); |
| | |
| | // Restore back to user screen settings |
| | if(!GLPREF_windowed) |
| | ChangeDisplaySettings(NULL,0); |
| | |
| | |
| | ReleaseDC(GLPREF_gamewindow,GLPREF_windowdc); |
} | | } |