From a308135449c51cbf067c128c9b61354ca7f899c9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 28 Sep 2001 14:01:34 +0000 Subject: [PATCH] applied (slightly modified) wxGLApp patch for MSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/glcanvas.h | 21 +++++++ include/wx/gtk/glcanvas.h | 28 --------- include/wx/gtk1/glcanvas.h | 28 --------- include/wx/msw/glcanvas.h | 8 +-- src/msw/glcanvas.cpp | 113 +++++++++++++++++++++++++++---------- 5 files changed, 104 insertions(+), 94 deletions(-) diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h index 6b21c50604..0a6c729122 100644 --- a/include/wx/glcanvas.h +++ b/include/wx/glcanvas.h @@ -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__) @@ -15,5 +19,22 @@ #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_ diff --git a/include/wx/gtk/glcanvas.h b/include/wx/gtk/glcanvas.h index 3eec4ab6ad..ae7de3acc6 100644 --- a/include/wx/gtk/glcanvas.h +++ b/include/wx/gtk/glcanvas.h @@ -16,10 +16,6 @@ #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_ diff --git a/include/wx/gtk1/glcanvas.h b/include/wx/gtk1/glcanvas.h index 3eec4ab6ad..ae7de3acc6 100644 --- a/include/wx/gtk1/glcanvas.h +++ b/include/wx/gtk1/glcanvas.h @@ -16,10 +16,6 @@ #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_ diff --git a/include/wx/msw/glcanvas.h b/include/wx/msw/glcanvas.h index 534528d559..df45b5e816 100644 --- a/include/wx/msw/glcanvas.h +++ b/include/wx/msw/glcanvas.h @@ -16,10 +16,6 @@ #ifndef _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_ -#include - -#if wxUSE_GLCANVAS - #include #include @@ -128,11 +124,9 @@ protected: wxPalette m_palette; WXHDC m_hDC; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; -#endif - // wxUSE_GLCANVAS #endif // _WX_GLCANVAS_H_ diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index 360e36c876..6439927730 100644 --- a/src/msw/glcanvas.cpp +++ b/src/msw/glcanvas.cpp @@ -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 -- 2.45.2