]> git.saurik.com Git - wxWidgets.git/commitdiff
applied (slightly modified) wxGLApp patch for MSW
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Sep 2001 14:01:34 +0000 (14:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Sep 2001 14:01:34 +0000 (14:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/glcanvas.h
include/wx/gtk/glcanvas.h
include/wx/gtk1/glcanvas.h
include/wx/msw/glcanvas.h
src/msw/glcanvas.cpp

index 6b21c5060413b289d821b3c3241ebda46b010e5d..0a6c7291229f2815bae0e22a3f9ad49f144100cb 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef _WX_GLCANVAS_H_BASE_
 #define _WX_GLCANVAS_H_BASE_
 
+#include "wx/defs.h"
+
+#if wxUSE_GLCANVAS
+
 #if defined(__WXMSW__)
 #include "wx/msw/glcanvas.h"
 #elif defined(__WXMOTIF__)
 #include "wx/stubs/glcanvas.h"
 #endif
 
+class WXDLLEXPORT wxGLApp : public wxApp
+{
+public:
+    wxGLApp() : wxApp() { }
+    virtual ~wxGLApp();
+
+    // use this in the constructor of the user-derived wxGLApp class to
+    // determine if an OpenGL rendering context with these attributes
+    // is available - returns TRUE if so, FALSE if not.
+    bool InitGLVisual(int *attribList);
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxGLApp)
+};
+
+#endif
+    // wxUSE_GLCANVAS
 #endif
     // _WX_GLCANVAS_H_BASE_
index 3eec4ab6ada4fd4d674ac632d2b2ffcc60d0800a..ae7de3acc6da1d226d80943666db39d1fb820b5a 100644 (file)
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/defs.h"
-
-#if wxUSE_GLCANVAS
-
 #include "wx/scrolwin.h"
 #include "wx/app.h"
 
@@ -178,30 +174,6 @@ private:
     DECLARE_CLASS(wxGLCanvas)
 };
 
-
-//---------------------------------------------------------------------------
-// wxGLApp
-//---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxGLApp: public wxApp
-{
-public:
-    wxGLApp() : wxApp() { }
-    ~wxGLApp();
-    
-    // use this in the constructor of the user-derived wxGLApp class to select
-    // an appropriate X visual for GL. Returns TRUE if an appropriate visual
-    // is found - and sets m_glVisualInfo; FALSE otherwise.
-    bool InitGLVisual(int *attribList);
-    
-private:
-    DECLARE_DYNAMIC_CLASS(wxGLApp)
-};
-
-
-#endif
-    // wxUSE_GLCANVAS
-
 #endif
     // _WX_GLCANVAS_H_
 
index 3eec4ab6ada4fd4d674ac632d2b2ffcc60d0800a..ae7de3acc6da1d226d80943666db39d1fb820b5a 100644 (file)
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/defs.h"
-
-#if wxUSE_GLCANVAS
-
 #include "wx/scrolwin.h"
 #include "wx/app.h"
 
@@ -178,30 +174,6 @@ private:
     DECLARE_CLASS(wxGLCanvas)
 };
 
-
-//---------------------------------------------------------------------------
-// wxGLApp
-//---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxGLApp: public wxApp
-{
-public:
-    wxGLApp() : wxApp() { }
-    ~wxGLApp();
-    
-    // use this in the constructor of the user-derived wxGLApp class to select
-    // an appropriate X visual for GL. Returns TRUE if an appropriate visual
-    // is found - and sets m_glVisualInfo; FALSE otherwise.
-    bool InitGLVisual(int *attribList);
-    
-private:
-    DECLARE_DYNAMIC_CLASS(wxGLApp)
-};
-
-
-#endif
-    // wxUSE_GLCANVAS
-
 #endif
     // _WX_GLCANVAS_H_
 
index 534528d5593ee66b69b6c46ca9256339d653c1a9..df45b5e8163c9e2e4b2d3adbc4a6cd807a64bf87 100644 (file)
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include <wx/setup.h>
-
-#if wxUSE_GLCANVAS
-
 #include <wx/palette.h>
 #include <wx/scrolwin.h>
 
@@ -128,11 +124,9 @@ protected:
     wxPalette      m_palette;
     WXHDC          m_hDC;
 
-DECLARE_EVENT_TABLE()
+    DECLARE_EVENT_TABLE()
 };
 
-#endif
-    // wxUSE_GLCANVAS
 #endif
     // _WX_GLCANVAS_H_
 
index 360e36c8765312d1975efd2480b94aab43c9f9ba..64399277301854daa6c7d55a313cbc1c3c5c835f 100644 (file)
@@ -334,30 +334,8 @@ bool wxGLCanvas::Create(wxWindow *parent, wxWindowID id,
   return TRUE;
 }
 
-void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC)
+static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList)
 {
-  int pixelFormat;
-  PIXELFORMATDESCRIPTOR pfd = {
-               sizeof(PIXELFORMATDESCRIPTOR),  /* size */
-               1,                              /* version */
-               PFD_SUPPORT_OPENGL |
-               PFD_DRAW_TO_WINDOW |
-               PFD_DOUBLEBUFFER,               /* support double-buffering */
-               PFD_TYPE_RGBA,                  /* color type */
-               16,                             /* prefered color depth */
-               0, 0, 0, 0, 0, 0,               /* color bits (ignored) */
-               0,                              /* no alpha buffer */
-               0,                              /* alpha bits (ignored) */
-               0,                              /* no accumulation buffer */
-               0, 0, 0, 0,                     /* accum bits (ignored) */
-               16,                             /* depth buffer */
-               0,                              /* no stencil buffer */
-               0,                              /* no auxiliary buffers */
-               PFD_MAIN_PLANE,                 /* main layer */
-               0,                              /* reserved */
-               0, 0, 0,                        /* no layer, visible, damage masks */
-       };
-
   if (attribList) {
     pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
     pfd.iPixelType = PFD_TYPE_COLORINDEX;
@@ -430,17 +408,42 @@ void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC)
       }
     }
   }
+}
+
+void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC)
+{
+  int pixelFormat;
+  PIXELFORMATDESCRIPTOR pfd = {
+               sizeof(PIXELFORMATDESCRIPTOR),  /* size */
+               1,                              /* version */
+               PFD_SUPPORT_OPENGL |
+               PFD_DRAW_TO_WINDOW |
+               PFD_DOUBLEBUFFER,               /* support double-buffering */
+               PFD_TYPE_RGBA,                  /* color type */
+               16,                             /* prefered color depth */
+               0, 0, 0, 0, 0, 0,               /* color bits (ignored) */
+               0,                              /* no alpha buffer */
+               0,                              /* alpha bits (ignored) */
+               0,                              /* no accumulation buffer */
+               0, 0, 0, 0,                     /* accum bits (ignored) */
+               16,                             /* depth buffer */
+               0,                              /* no stencil buffer */
+               0,                              /* no auxiliary buffers */
+               PFD_MAIN_PLANE,                 /* main layer */
+               0,                              /* reserved */
+               0, 0, 0,                        /* no layer, visible, damage masks */
+       };
+
+  AdjustPFDForAttributes(pfd, attribList);
+
   pixelFormat = ChoosePixelFormat((HDC) m_hDC, &pfd);
   if (pixelFormat == 0) {
-    MessageBox(WindowFromDC((HDC) m_hDC), wxT("ChoosePixelFormat failed."), wxT("Error"),
-               MB_ICONERROR | MB_OK);
-    exit(1);
+    wxLogWarning(_("ChoosePixelFormat failed."));
   }
-
-  if (SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) != TRUE) {
-    MessageBox(WindowFromDC((HDC) m_hDC), wxT("SetPixelFormat failed."), wxT("Error"),
-               MB_ICONERROR | MB_OK);
-    exit(1);
+  else {
+    if (SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) != TRUE) {
+      wxLogWarning(_("SetPixelFormat failed."));
+    }
   }
 }
 
@@ -713,5 +716,53 @@ void glAddSwapHintRectWin(GLint x, GLint y, GLsizei width, GLsizei height)
 {
 }
 
+
+//---------------------------------------------------------------------------
+// wxGLApp
+//---------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxGLApp, wxApp)
+
+bool wxGLApp::InitGLVisual(int *attribList)
+{
+  int pixelFormat;
+  PIXELFORMATDESCRIPTOR pfd = {
+               sizeof(PIXELFORMATDESCRIPTOR),  /* size */
+               1,                              /* version */
+               PFD_SUPPORT_OPENGL |
+               PFD_DRAW_TO_WINDOW |
+               PFD_DOUBLEBUFFER,               /* support double-buffering */
+               PFD_TYPE_RGBA,                  /* color type */
+               16,                             /* prefered color depth */
+               0, 0, 0, 0, 0, 0,               /* color bits (ignored) */
+               0,                              /* no alpha buffer */
+               0,                              /* alpha bits (ignored) */
+               0,                              /* no accumulation buffer */
+               0, 0, 0, 0,                     /* accum bits (ignored) */
+               16,                             /* depth buffer */
+               0,                              /* no stencil buffer */
+               0,                              /* no auxiliary buffers */
+               PFD_MAIN_PLANE,                 /* main layer */
+               0,                              /* reserved */
+               0, 0, 0,                        /* no layer, visible, damage masks */
+       };
+
+  AdjustPFDForAttributes(pfd, attribList);
+
+  // use DC for whole (root) screen, since no windows have yet been created
+  pixelFormat = ChoosePixelFormat((HDC) ::GetDC(NULL), &pfd);
+
+  if (pixelFormat == 0) {
+    wxLogError(_("Failed to initialize OpenGL"));
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+wxGLApp::~wxGLApp()
+{
+}
+
 #endif
     // wxUSE_GLCANVAS