changeset 10880:ba9557e864c0

vo_gl2 port to win32 patch by Tristan Seligmann <mithrandi-mplayer-dev-eng at mithrandi.za.net>
author faust3
date Fri, 19 Sep 2003 14:33:51 +0000
parents 27f8546f53c4
children 6c3555f4c5c3
files configure libvo/video_out.c libvo/vo_gl2.c libvo/w32_common.c libvo/w32_common.h
diffstat 5 files changed, 484 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Wed Sep 17 09:42:25 2003 +0000
+++ b/configure	Fri Sep 19 14:33:51 2003 +0000
@@ -2940,7 +2940,7 @@
 echocheck "OpenGL"
 cygwin && _gl=no
 #Note: this test is run even with --enable-gl since we autodetect $_ld_gl
-if test "$_x11" = yes && test "$_gl" != no ; then
+if (test "$_x11" = yes || mingw32) && test "$_gl" != no ; then
   cat > $TMPC << EOF
 #include <GL/gl.h>
 int main(void) { return 0; }
@@ -2952,16 +2952,26 @@
   elif cc_check $_inc_x11 $_ld_x11 -lGL -lm $_ld_pthread ; then
     _gl=yes
     _ld_gl="-lGL $_ld_pthread"
+  elif cc_check -lopengl32 ; then
+    _gl=yes
+    _gl_win32=yes
+    _ld_gl="-lopengl32 -lgdi32"
   fi
 else
   _gl=no
 fi
 if test "$_gl" = yes ; then
   _def_gl='#define HAVE_GL 1'
-  _vosrc="$_vosrc vo_gl.c vo_gl2.c"
+  if test "$_gl_win32" = yes ; then
+    _def_gl_win32='#define GL_WIN32 1' 
+    _vosrc="$_vosrc vo_gl2.c w32_common.c"
+  else
+    _vosrc="$_vosrc vo_gl.c vo_gl2.c"
+  fi
   _vomodules="opengl $_vomodules"
 else
   _def_gl='#undef HAVE_GL'
+  _def_gl_win32='#undef GL_WIN32'
   _novomodules="opengl $_novomodules"
 fi
 echores "$_gl"
@@ -6100,6 +6110,7 @@
 $_def_vm
 $_def_xinerama
 $_def_gl
+$_def_gl_win32
 $_def_dga
 $_def_dga2
 $_def_sdl
--- a/libvo/video_out.c	Wed Sep 17 09:42:25 2003 +0000
+++ b/libvo/video_out.c	Fri Sep 19 14:33:51 2003 +0000
@@ -144,7 +144,9 @@
         &video_out_xover,
 #endif
 #ifdef HAVE_GL
-        &video_out_gl,
+	#ifndef GL_WIN32
+	        &video_out_gl,
+	#endif
         &video_out_gl2,
 #endif
 #ifdef HAVE_DGA
--- a/libvo/vo_gl2.c	Wed Sep 17 09:42:25 2003 +0000
+++ b/libvo/vo_gl2.c	Fri Sep 19 14:33:51 2003 +0000
@@ -15,15 +15,22 @@
 #include "video_out_internal.h"
 #include "sub.h"
 
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-//#include <X11/keysym.h>
-#include <GL/glx.h>
+#include <GL/gl.h>
+#ifdef GL_WIN32
+    #include <windows.h>
+    #include <GL/glext.h>
+#else
+    #include <X11/Xlib.h>
+    #include <X11/Xutil.h>
+    #include <GL/glx.h>
+#endif
 #include <errno.h>
 
-#include <GL/gl.h>
-
-#include "x11_common.h"
+#ifdef GL_WIN32
+    #include "w32_common.h"
+#else
+    #include "x11_common.h"
+#endif
 #include "aspect.h"
 
 #define NDEBUG
@@ -55,7 +62,9 @@
 
 //static int texture_id=1;
 
-static GLXContext wsGLXContext;
+#ifndef GL_WIN32
+    static GLXContext wsGLXContext;
+#endif
 
 static uint32_t image_width;
 static uint32_t image_height;
@@ -80,7 +89,6 @@
 static char *   gl_bitmap_type_s;
 static int      gl_alignment;
 static int      isGL12 = GL_FALSE;
-static int      isFullscreen = GL_FALSE;
 
 static int      gl_bilinear=1;
 static int      gl_antialias=0;
@@ -556,7 +564,7 @@
 
 static void resize(int x,int y){
   printf("[gl2] Resize: %dx%d\n",x,y);
-  if( isFullscreen )
+  if( vo_fs )
 	  glViewport( (vo_screenwidth-x)/2, (vo_screenheight-y)/2, x, y);
   else 
 	  glViewport( 0, 0, x, y );
@@ -588,6 +596,42 @@
 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
 }
 
+#ifdef GL_WIN32
+
+static int config_w32(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
+    PIXELFORMATDESCRIPTOR pfd;
+    int pf;
+
+    o_dwidth = d_width;
+    o_dheight = d_height;
+    vo_fs = flags & VOFLAG_FULLSCREEN;
+    vo_vm = flags & VOFLAG_MODESWITCHING;
+    
+    vo_dwidth = d_width;
+    vo_dheight = d_height;
+
+    destroyRenderingContext();
+    if (!createRenderingContext())
+	return -1;
+
+    if (vo_fs)
+	aspect(&d_width, &d_height, A_ZOOM);
+
+    pf = GetPixelFormat(vo_hdc);
+    if (!DescribePixelFormat(vo_hdc, pf, sizeof pfd, &pfd)) {
+	r_sz = g_sz = b_sz = a_sz = 0;
+    } else {
+	r_sz = pfd.cRedBits;
+	g_sz = pfd.cGreenBits;
+	b_sz = pfd.cBlueBits;
+	a_sz = pfd.cAlphaBits;
+    }
+
+    return 0;
+}
+
+#else
+
 static int choose_glx_visual(Display *dpy, int scr, XVisualInfo *res_vi)
 {
 	XVisualInfo template, *vi_list;
@@ -632,37 +676,14 @@
 	return (best_weight < 1000000) ? 0 : -1;
 }
 
-/* connect to server, create and map window,
- * allocate colors and (shared) memory
- */
-static uint32_t 
-config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
-{
-//	int screen;
-	unsigned int fg, bg;
+static uint32_t config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
 	XSizeHints hint;
 	XVisualInfo *vinfo, vinfo_buf;
 	XEvent xev;
 
-//	XGCValues xgcv;
-
-        const unsigned char * glVersion;
-
-	image_height = height;
-	image_width = width;
-	image_format = format;
-
-	int_pause = 0;
-  
-	aspect_save_orig(width,height);
-	aspect_save_prescale(d_width,d_height);
-	aspect_save_screenres(vo_screenwidth,vo_screenheight);
-
-	aspect(&d_width,&d_height,A_NOZOOM);
-
         if( flags&0x01 )
         {
-	        isFullscreen = GL_TRUE;
+	        vo_fs = VO_TRUE;
                 aspect(&d_width,&d_height,A_ZOOM);
 		hint.x = 0;
 		hint.y = 0;
@@ -670,6 +691,7 @@
 		hint.height = vo_screenheight;
 		hint.flags = PPosition | PSize;
         } else {
+		vo_fs = VO_FALSE;
 		hint.x = 0;
 		hint.y = 0;
 		hint.width = d_width;
@@ -677,11 +699,6 @@
 		hint.flags = PPosition | PSize;
         }
 
-	/* Get some colors */
-
-	bg = WhitePixel(mDisplay, mScreen);
-	fg = BlackPixel(mDisplay, mScreen);
-
 	/* Make the window */
 
 //	XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
@@ -742,6 +759,101 @@
 		 | ButtonPressMask | ButtonReleaseMask | ExposureMask
         );
 
+  if(glXGetConfig(mDisplay,vinfo,GLX_RED_SIZE, &r_sz)!=0) 
+	  r_sz=0;
+  if(glXGetConfig(mDisplay,vinfo,GLX_GREEN_SIZE, &g_sz)!=0) 
+	  g_sz=0;
+  if(glXGetConfig(mDisplay,vinfo,GLX_BLUE_SIZE, &b_sz)!=0) 
+	  b_sz=0;
+  if(glXGetConfig(mDisplay,vinfo,GLX_ALPHA_SIZE, &a_sz)!=0) 
+	  a_sz=0;
+
+        return 0;
+}
+
+#endif
+
+static int initGl(uint32_t d_width, uint32_t d_height)
+{
+  ImageDataLocal=malloc(image_width*image_height*image_bytes);
+  memset(ImageDataLocal,128,image_width*image_height*image_bytes);
+
+  ImageData=ImageDataLocal;
+
+  texture_width=image_width;
+  texture_height=image_height;
+    
+  if (initTextures() < 0)
+    return -1;
+
+  glDisable(GL_BLEND); 
+  glDisable(GL_DEPTH_TEST);
+  glDepthMask(GL_FALSE);
+  glDisable(GL_CULL_FACE);
+
+  glPixelStorei (GL_UNPACK_ROW_LENGTH, memory_x_len);
+
+  /**
+   * may give a little speed up for a kinda burst read ..
+   */
+  if( (image_width*image_bpp)%8 == 0 )
+  	gl_alignment=8;
+  else if( (image_width*image_bpp)%4 == 0 )
+  	gl_alignment=4;
+  else if( (image_width*image_bpp)%2 == 0 )
+  	gl_alignment=2;
+  else
+  	gl_alignment=1;
+
+  glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment); 
+
+  glEnable (GL_TEXTURE_2D);
+
+  gl_set_antialias(0);
+  gl_set_bilinear(1);
+  
+  drawTextureDisplay ();
+
+  printf("[gl2] Using image_bpp=%d, image_bytes=%d, isBGR=%d, \n\tgl_bitmap_format=%s, gl_bitmap_type=%s, \n\tgl_alignment=%d, rgb_size=%d (%d,%d,%d), a_sz=%d, \n\tgl_internal_format=%s\n",
+  	image_bpp, image_bytes, image_mode==MODE_BGR, 
+        gl_bitmap_format_s, gl_bitmap_type_s, gl_alignment,
+	rgb_sz, r_sz, g_sz, b_sz, a_sz, gl_internal_format_s);
+
+  resize(vo_dwidth, vo_dheight);
+
+  glClearColor( 0.0f,0.0f,0.0f,0.0f );
+  glClear( GL_COLOR_BUFFER_BIT );
+
+  return 0;
+}
+
+/* connect to server, create and map window,
+ * allocate colors and (shared) memory
+ */
+static uint32_t 
+config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
+{
+        const unsigned char * glVersion;
+
+	image_height = height;
+	image_width = width;
+	image_format = format;
+
+	int_pause = 0;
+  
+	aspect_save_orig(width,height);
+	aspect_save_prescale(d_width,d_height);
+	aspect_save_screenres(vo_screenwidth,vo_screenheight);
+
+	aspect(&d_width,&d_height,A_NOZOOM);
+
+#ifdef GL_WIN32
+	if (config_w32(width, height, d_width, d_height, flags, title, format) == -1)
+#else
+	if (config_glx(width, height, d_width, d_height, flags, title, format) == -1)
+#endif
+	    return -1;
+	
   glVersion = glGetString(GL_VERSION);
 
   printf("[gl2] OpenGL Driver Information:\n");
@@ -758,20 +870,11 @@
 
   if(isGL12)
   {
-	printf("[gl2] You have an OpenGL >= 1.2 capable drivers, GOOD (16bpp and BGR is ok !)\n");
+	printf("[gl2] You have OpenGL >= 1.2 capable drivers, GOOD (16bpp and BGR is ok!)\n");
   } else {
-	printf("[gl2] You have an OpenGL < 1.2 drivers, BAD (16bpp and BGR may be damaged  !)\n");
+	printf("[gl2] You have OpenGL < 1.2 drivers, BAD (16bpp and BGR may be damaged!)\n");
   }
 
-  if(glXGetConfig(mDisplay,vinfo,GLX_RED_SIZE, &r_sz)!=0) 
-	  r_sz=0;
-  if(glXGetConfig(mDisplay,vinfo,GLX_GREEN_SIZE, &g_sz)!=0) 
-	  g_sz=0;
-  if(glXGetConfig(mDisplay,vinfo,GLX_BLUE_SIZE, &b_sz)!=0) 
-	  b_sz=0;
-  if(glXGetConfig(mDisplay,vinfo,GLX_ALPHA_SIZE, &a_sz)!=0) 
-	  b_sz=0;
-
   rgb_sz=r_sz+g_sz+b_sz;
   if(rgb_sz<=0) rgb_sz=24;
 
@@ -887,55 +990,11 @@
 			break;
   }
 
-  ImageDataLocal=malloc(image_width*image_height*image_bytes);
-  memset(ImageDataLocal,128,image_width*image_height*image_bytes);
-
-  ImageData=ImageDataLocal;
-
-  texture_width=image_width;
-  texture_height=image_height;
-  if (initTextures() < 0)
-    return -1;
-
-  glDisable(GL_BLEND); 
-  glDisable(GL_DEPTH_TEST);
-  glDepthMask(GL_FALSE);
-  glDisable(GL_CULL_FACE);
-
-  glPixelStorei (GL_UNPACK_ROW_LENGTH, memory_x_len);
-
-  /**
-   * may give a little speed up for a kinda burst read ..
-   */
-  if( (image_width*image_bpp)%8 == 0 )
-  	gl_alignment=8;
-  else if( (image_width*image_bpp)%4 == 0 )
-  	gl_alignment=4;
-  else if( (image_width*image_bpp)%2 == 0 )
-  	gl_alignment=2;
-  else
-  	gl_alignment=1;
-
-  glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment); 
-
-  glEnable (GL_TEXTURE_2D);
-
-  gl_set_antialias(0);
-  gl_set_bilinear(1);
-  
-  drawTextureDisplay ();
-
-  printf("[gl2] Using image_bpp=%d, image_bytes=%d, isBGR=%d, \n\tgl_bitmap_format=%s, gl_bitmap_type=%s, \n\tgl_alignment=%d, rgb_size=%d (%d,%d,%d), a_sz=%d, \n\tgl_internal_format=%s\n",
-  	image_bpp, image_bytes, image_mode==MODE_BGR, 
-        gl_bitmap_format_s, gl_bitmap_type_s, gl_alignment,
-	rgb_sz, r_sz, g_sz, b_sz, a_sz, gl_internal_format_s);
-
-  resize(d_width,d_height);
-
-  glClearColor( 0.0f,0.0f,0.0f,0.0f );
-  glClear( GL_COLOR_BUFFER_BIT );
-
-      saver_off(mDisplay);  // turning off screen saver
+  if (initGl(d_width, d_height) == -1)
+      return -1;
+#ifndef GL_WIN32
+      saver_off(mDisplay);
+#endif
 
 	return 0;
 }
@@ -955,6 +1014,16 @@
 	return 1;
 }
 
+#ifdef GL_WIN32
+
+static void check_events(void) {
+    int e=vo_w32_check_events();
+    if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight);
+    if(e&VO_EVENT_EXPOSE && int_pause) flip_page();
+}
+
+#else
+
 static void check_events(void)
 {
 	 XEvent         Event;
@@ -986,6 +1055,8 @@
          if(e&VO_EVENT_EXPOSE && int_pause) flip_page();
 }
 
+#endif
+
 static void draw_osd(void)
 { vo_draw_text(image_width,image_height,draw_alpha_fnc); }
 
@@ -997,7 +1068,11 @@
 
 //  glFlush();
   glFinish();
+#ifdef GL_WIN32
+  SwapBuffers(vo_hdc);
+#else
   glXSwapBuffers( mDisplay,vo_window );
+#endif
 }
 
 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
@@ -1060,8 +1135,11 @@
 uninit(void)
 {
   if ( !vo_config_count ) return;
-  saver_on(mDisplay); // screen saver back on
+#ifdef GL_WIN32
+  vo_w32_uninit();
+#else
   vo_x11_uninit();
+#endif
 }
 
 static uint32_t preinit(const char *arg)
@@ -1083,8 +1161,14 @@
   case VOCTRL_QUERY_FORMAT:
     return query_format(*((uint32_t*)data));
   case VOCTRL_FULLSCREEN:
+#ifdef GL_WIN32
+    vo_w32_fullscreen();
+    initGl(vo_dwidth, vo_dheight);
+#else
     vo_x11_fullscreen();
+#endif 
     return VO_TRUE;
+#ifndef GL_WIN32
   case VOCTRL_SET_EQUALIZER:
     {
       va_list ap;
@@ -1105,6 +1189,7 @@
       va_end(ap);
       return vo_x11_get_equalizer(data, value);
     }
+#endif
   }
   return VO_NOTIMPL;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/w32_common.c	Fri Sep 19 14:33:51 2003 +0000
@@ -0,0 +1,267 @@
+#include <limits.h>
+#include <windows.h>
+
+#include "../osdep/keycodes.h"
+#include "../input/input.h"
+#include "../mp_msg.h"
+#include "video_out.h"
+#include "aspect.h"
+#include "w32_common.h"
+
+extern void mplayer_put_key(int code);
+
+static const char* classname = "MPlayer - Media player for Win32";
+int vo_vm = 0;
+HDC vo_hdc = 0;
+
+uint32_t o_dwidth;
+uint32_t o_dheight;
+
+static HINSTANCE hInstance;
+static HWND vo_hwnd = 0;
+static HGLRC wglContext = 0;
+static int cursor = 1;
+
+static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+    switch (message) {
+	case WM_DESTROY:
+	    mp_input_queue_cmd(mp_input_parse_cmd("quit"));
+	    break;
+        case WM_SYSCOMMAND:
+	    switch (wParam) {
+		case SC_SCREENSAVE:
+		case SC_MONITORPOWER:
+    		    mp_msg(MSGT_VO, MSGL_V, "vo: win32: killing screensaver\n");
+		    break;
+		default:
+		    return DefWindowProc(hWnd, message, wParam, lParam);
+	    }
+	    break;
+        case WM_KEYDOWN:
+	    switch (wParam) {
+		case VK_LEFT:    mplayer_put_key(KEY_LEFT);      break;
+		case VK_UP:      mplayer_put_key(KEY_UP);        break;
+		case VK_RIGHT:   mplayer_put_key(KEY_RIGHT);     break;
+		case VK_DOWN:    mplayer_put_key(KEY_DOWN);      break;
+		case VK_TAB:     mplayer_put_key(KEY_TAB);       break;
+		case VK_CONTROL: mplayer_put_key(KEY_CTRL);      break;
+		case VK_DELETE:  mplayer_put_key(KEY_DELETE);    break;
+		case VK_INSERT:  mplayer_put_key(KEY_INSERT);    break;
+		case VK_HOME:    mplayer_put_key(KEY_HOME);      break;
+		case VK_END:     mplayer_put_key(KEY_END);       break;
+		case VK_PRIOR:   mplayer_put_key(KEY_PAGE_UP);   break;
+		case VK_NEXT:    mplayer_put_key(KEY_PAGE_DOWN); break;
+		case VK_ESCAPE:  mplayer_put_key(KEY_ESC);       break;
+	    }
+	    break;
+        case WM_CHAR:
+	    mplayer_put_key(wParam);
+	    break;
+	case WM_LBUTTONDOWN:
+	    if (!vo_fs) {
+		ReleaseCapture();
+		SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
+		return 0;
+	    }
+	    break;
+    }
+    
+    return DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+int vo_w32_check_events(void) {
+    MSG msg;
+    int r = 0;
+    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
+	TranslateMessage(&msg);
+	DispatchMessage(&msg);
+	switch (msg.message) {
+	    case WM_ACTIVATE:
+		r |= VO_EVENT_EXPOSE;
+		break;
+	}
+    }
+    
+    return r;
+}
+
+static void changeMode(void) {
+    DEVMODE dm;
+    dm.dmSize = sizeof dm;
+    dm.dmDriverExtra = 0;
+
+    dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+    dm.dmBitsPerPel = vo_depthonscreen;
+    dm.dmPelsWidth = vo_screenwidth;
+    dm.dmPelsHeight = vo_screenheight;
+
+    if (vo_vm) {
+	int bestMode = -1;
+	int bestScore = INT_MAX;
+	int i;
+	for (i = 0; EnumDisplaySettings(0, i, &dm); ++i) {
+	    if (dm.dmBitsPerPel != vo_depthonscreen) continue;
+	    if (dm.dmPelsWidth < o_dwidth) continue;
+	    if (dm.dmPelsHeight < o_dheight) continue;
+	    int score = (dm.dmPelsWidth - o_dwidth) * (dm.dmPelsHeight - o_dheight);
+
+	    if (score < bestScore) {
+		bestScore = score;
+		bestMode = i;
+	    }
+	}
+
+	if (bestMode != -1)
+	    EnumDisplaySettings(0, bestMode, &dm);
+    }
+
+    vo_screenwidth = dm.dmPelsWidth;
+    vo_screenheight = dm.dmPelsHeight;
+    aspect_save_screenres(vo_screenwidth, vo_screenheight);
+    if (vo_fs)
+	aspect(&vo_dwidth, &vo_dheight, A_ZOOM);
+
+    ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
+}
+
+static void resetMode(void) {
+    ChangeDisplaySettings(0, 0);
+
+    DEVMODE dm;
+    dm.dmSize = sizeof dm;
+    dm.dmDriverExtra = 0;
+    dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+    if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm)) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to enumerate display settings!\n");
+	return;
+    }
+
+    vo_screenwidth = dm.dmPelsWidth;
+    vo_screenheight = dm.dmPelsHeight;
+    vo_depthonscreen = dm.dmBitsPerPel;
+    aspect_save_screenres(vo_screenwidth, vo_screenheight);
+
+    vo_dwidth = o_dwidth;
+    vo_dheight = o_dheight;
+}
+
+int createRenderingContext(void) {
+    if (wglContext) return 1;
+
+    if (vo_fs) {
+	changeMode();
+	SetWindowPos(vo_hwnd, HWND_TOPMOST, 0, 0, vo_screenwidth, vo_screenheight, SWP_SHOWWINDOW);
+	if (cursor) {
+	    ShowCursor(0);
+	    cursor = 0;
+	}
+    } else {
+	resetMode();
+	SetWindowPos(vo_hwnd, HWND_NOTOPMOST, (vo_screenwidth - vo_dwidth) / 2, (vo_screenheight - vo_dheight) / 2, vo_dwidth, vo_dheight, SWP_SHOWWINDOW);
+	if (!cursor) {
+	    ShowCursor(1);
+	    cursor = 1;
+	}
+    }
+
+    PIXELFORMATDESCRIPTOR pfd;
+    memset(&pfd, 0, sizeof pfd);
+    pfd.nSize = sizeof pfd;
+    pfd.nVersion = 1;
+    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+    pfd.iPixelType = PFD_TYPE_RGBA;
+    pfd.cColorBits = 24;
+    pfd.iLayerType = PFD_MAIN_PLANE;
+    int pf = ChoosePixelFormat(vo_hdc, &pfd);
+    if (!pf) {
+    	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to select a valid pixel format!\n");
+	return 0;
+    }
+
+    SetPixelFormat(vo_hdc, pf, &pfd);
+    
+    wglContext = wglCreateContext(vo_hdc);
+    if (!wglContext) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create wgl rendering context!\n");
+	return 0;
+    }
+
+    if (!wglMakeCurrent(vo_hdc, wglContext)) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to make wgl rendering context current!\n");
+	return 0;
+    }	
+
+    mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen);
+
+    return 1;
+}
+
+void destroyRenderingContext(void) {
+    if (wglContext) {
+	wglMakeCurrent(0, 0);
+	wglDeleteContext(wglContext);
+	wglContext = 0;
+	resetMode();
+    }
+}
+
+int vo_init(void) {
+    HICON 	mplayerIcon = 0;
+    char 	exedir[MAX_PATH];
+    DEVMODE	dm;
+
+    if (vo_hwnd)
+	return 1;
+
+    hInstance = GetModuleHandle(0);
+    
+    if (GetModuleFileName(0, exedir, MAX_PATH))
+	mplayerIcon = ExtractIcon(hInstance, exedir, 0);
+    if (!mplayerIcon)
+	mplayerIcon = LoadIcon(0, IDI_APPLICATION);
+
+    WNDCLASSEX wcex = { sizeof wcex, CS_OWNDC, WndProc, 0, 0, hInstance, mplayerIcon, LoadCursor(0, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), 0, classname, mplayerIcon };
+
+    if (!RegisterClassEx(&wcex)) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to register window class!\n");
+	return 0;
+    }
+
+    vo_hwnd = CreateWindowEx(0, classname, classname, WS_POPUP, CW_USEDEFAULT, 0, 100, 100, 0, 0, hInstance, 0);
+    if (!vo_hwnd) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create window!\n");
+	return 0;
+    }
+
+    vo_hdc = GetDC(vo_hwnd);
+
+    dm.dmSize = sizeof dm;
+    dm.dmDriverExtra = 0;
+    dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+    if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm)) {
+	mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to enumerate display settings!\n");
+	return 0;
+    }
+    vo_screenwidth = dm.dmPelsWidth;
+    vo_screenheight = dm.dmPelsHeight;
+    vo_depthonscreen = dm.dmBitsPerPel;
+
+    return 1;
+}
+
+void vo_w32_fullscreen(void) {
+    vo_fs = !vo_fs;
+
+    destroyRenderingContext();
+    createRenderingContext();
+}
+
+void vo_w32_uninit() {
+    mp_msg(MSGT_VO, MSGL_V, "vo: win32: uninit\n");
+    resetMode();
+    ShowCursor(1);
+    vo_depthonscreen = 0;
+    destroyRenderingContext();
+    DestroyWindow(vo_hwnd);
+    vo_hwnd = 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/w32_common.h	Fri Sep 19 14:33:51 2003 +0000
@@ -0,0 +1,15 @@
+extern int vo_depthonscreen;
+extern int vo_screenwidth;
+extern int vo_screenheight;
+extern uint32_t o_dwidth;
+extern uint32_t o_dheight;
+extern HDC vo_hdc;
+extern int vo_fs;
+extern int vo_vm;
+
+extern int vo_init(void);
+extern void vo_w32_uninit(void);
+extern void vo_w32_fullscreen(void);
+extern int vo_w32_check_events(void);
+extern int createRenderingContext(void);
+extern void destroyRenderingContext(void);