]> git.saurik.com Git - wxWidgets.git/blame - src/common/glcmn.cpp
fixing the shrinking embedded controls
[wxWidgets.git] / src / common / glcmn.cpp
CommitLineData
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"
36WX_CHECK_BUILD_OPTIONS("wxGL")
37
38IMPLEMENT_CLASS(wxGLApp, wxApp)
39
40// ============================================================================
41// implementation
42// ============================================================================
43
44void wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
45{
46 // although on MSW it works even if the window is still hidden, it doesn't
47 // work in other ports (notably X11-based ones) and documentation mentions
48 // that SetCurrent() can only be called for a shown window, so check for it
49 wxASSERT_MSG( IsShownOnScreen(), _T("can't make hidden GL canvas current") );
50
51 context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this));
52}
53
54bool wxGLCanvasBase::SetColour(const wxChar *colour)
55{
56 wxColour col = wxTheColourDatabase->Find(colour);
57 if ( !col.Ok() )
58 return false;
59
60 GLboolean isRGBA;
61 glGetBooleanv(GL_RGBA_MODE, &isRGBA);
62 if ( isRGBA )
63 {
64 glColor3f(col.Red() / 256., col.Green() / 256., col.Blue() / 256.);
65 }
66 else // indexed colour
67 {
68 GLint pix = GetColourIndex(col);
69 if ( pix == -1 )
70 {
71 wxLogError(_("Failed to allocate colour for OpenGL"));
72 return false;
73 }
74
75 glIndexi(pix);
76 }
77
78 return true;
79}
80
81wxGLCanvasBase::~wxGLCanvasBase()
82{
83#if WXWIN_COMPATIBILITY_2_8
84 delete m_glContext;
85#endif // WXWIN_COMPATIBILITY_2_8
86}
87
88#if WXWIN_COMPATIBILITY_2_8
89
90wxGLContext *wxGLCanvasBase::GetContext() const
91{
92 return m_glContext;
93}
94
95void wxGLCanvasBase::SetCurrent()
96{
97 if ( m_glContext )
98 SetCurrent(*m_glContext);
99}
100
101void wxGLCanvasBase::OnSize(wxSizeEvent& WXUNUSED(event))
102{
103}
104
105#endif // WXWIN_COMPATIBILITY_2_8
106
107#endif // wxUSE_GLCANVAS
108