]>
Commit | Line | Data |
---|---|---|
dc3065a5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/glcmn.cpp | |
3 | // Purpose: wxGLCanvasBase implementation | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2007-04-09 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org> | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | // for compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #if wxUSE_GLCANVAS | |
27 | ||
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/log.h" | |
30 | #endif // WX_PRECOMP | |
31 | ||
32 | #include "wx/glcanvas.h" | |
33 | ||
34 | // DLL options compatibility check: | |
35 | #include "wx/build.h" | |
36 | WX_CHECK_BUILD_OPTIONS("wxGL") | |
37 | ||
38 | IMPLEMENT_CLASS(wxGLApp, wxApp) | |
39 | ||
40 | // ============================================================================ | |
41 | // implementation | |
42 | // ============================================================================ | |
43 | ||
15b239c0 VZ |
44 | wxGLCanvasBase::wxGLCanvasBase() |
45 | { | |
46 | #if WXWIN_COMPATIBILITY_2_8 | |
47 | m_glContext = NULL; | |
48 | #endif | |
49 | ||
50 | // we always paint background entirely ourselves so prevent wx from erasing | |
51 | // it to avoid flicker | |
52 | SetBackgroundStyle(wxBG_STYLE_CUSTOM); | |
53 | } | |
54 | ||
5ec69e96 | 55 | bool wxGLCanvasBase::SetCurrent(const wxGLContext& context) const |
dc3065a5 VZ |
56 | { |
57 | // although on MSW it works even if the window is still hidden, it doesn't | |
58 | // work in other ports (notably X11-based ones) and documentation mentions | |
59 | // that SetCurrent() can only be called for a shown window, so check for it | |
60 | wxASSERT_MSG( IsShownOnScreen(), _T("can't make hidden GL canvas current") ); | |
61 | ||
5ec69e96 | 62 | return context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this)); |
dc3065a5 VZ |
63 | } |
64 | ||
35f1f4f7 | 65 | bool wxGLCanvasBase::SetColour(const wxString& colour) |
dc3065a5 VZ |
66 | { |
67 | wxColour col = wxTheColourDatabase->Find(colour); | |
68 | if ( !col.Ok() ) | |
69 | return false; | |
70 | ||
71 | GLboolean isRGBA; | |
72 | glGetBooleanv(GL_RGBA_MODE, &isRGBA); | |
73 | if ( isRGBA ) | |
74 | { | |
75 | glColor3f(col.Red() / 256., col.Green() / 256., col.Blue() / 256.); | |
76 | } | |
77 | else // indexed colour | |
78 | { | |
79 | GLint pix = GetColourIndex(col); | |
80 | if ( pix == -1 ) | |
81 | { | |
82 | wxLogError(_("Failed to allocate colour for OpenGL")); | |
83 | return false; | |
84 | } | |
85 | ||
86 | glIndexi(pix); | |
87 | } | |
88 | ||
89 | return true; | |
90 | } | |
91 | ||
92 | wxGLCanvasBase::~wxGLCanvasBase() | |
93 | { | |
94 | #if WXWIN_COMPATIBILITY_2_8 | |
95 | delete m_glContext; | |
96 | #endif // WXWIN_COMPATIBILITY_2_8 | |
97 | } | |
98 | ||
99 | #if WXWIN_COMPATIBILITY_2_8 | |
100 | ||
101 | wxGLContext *wxGLCanvasBase::GetContext() const | |
102 | { | |
103 | return m_glContext; | |
104 | } | |
105 | ||
106 | void wxGLCanvasBase::SetCurrent() | |
107 | { | |
108 | if ( m_glContext ) | |
109 | SetCurrent(*m_glContext); | |
110 | } | |
111 | ||
112 | void wxGLCanvasBase::OnSize(wxSizeEvent& WXUNUSED(event)) | |
113 | { | |
114 | } | |
115 | ||
116 | #endif // WXWIN_COMPATIBILITY_2_8 | |
117 | ||
118 | #endif // wxUSE_GLCANVAS | |
119 |