]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/glcanvas.h
Include winundefs.h
[wxWidgets.git] / include / wx / gtk1 / glcanvas.h
CommitLineData
8b089c5e 1/////////////////////////////////////////////////////////////////////////////
8ef94bfc 2// Name: wx/gtk1/glcanvas.h
77ffb593 3// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
8b089c5e
JS
4// Author: Robert Roebling
5// Modified by:
6// Created: 17/8/98
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
65571936 9// Licence: wxWindows licence
8b089c5e
JS
10/////////////////////////////////////////////////////////////////////////////
11
db4c39a9
VZ
12#ifndef _WX_GLCANVAS_H_
13#define _WX_GLCANVAS_H_
14
a6f5aa49
VZ
15#include "wx/scrolwin.h"
16#include "wx/app.h"
8b089c5e
JS
17
18extern "C" {
a6f5aa49
VZ
19#include <GL/gl.h>
20#include <GL/glx.h>
21#include <GL/glu.h>
8b089c5e
JS
22}
23
8b089c5e
JS
24//---------------------------------------------------------------------------
25// classes
26//---------------------------------------------------------------------------
27
28class WXDLLEXPORT wxGLContext;
29class WXDLLEXPORT wxGLCanvas;
30
31//---------------------------------------------------------------------------
32// wxGLContext
33//---------------------------------------------------------------------------
34
35
36class WXDLLEXPORT wxGLContext: public wxObject
37{
38public:
39 wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
2b5f62a0
VZ
40 wxGLContext(
41 bool WXUNUSED(isRGB), wxWindow *win,
8b089c5e
JS
42 const wxPalette& WXUNUSED(palette),
43 const wxGLContext *other /* for sharing display lists */
44 );
d3c7fc99 45 virtual ~wxGLContext();
8b089c5e
JS
46
47 void SetCurrent();
2b5f62a0 48 void SetColour(const wxChar *colour);
8b089c5e
JS
49 void SwapBuffers();
50
51 void SetupPixelFormat();
52 void SetupPalette(const wxPalette& palette);
53 wxPalette CreateDefaultPalette();
54
55 inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
56 inline wxWindow* GetWindow() const { return m_window; }
57 inline GtkWidget* GetWidget() const { return m_widget; }
58 inline GLXContext GetContext() const { return m_glContext; }
59
60public:
61 GLXContext m_glContext;
62
63 GtkWidget *m_widget;
64 wxPalette m_palette;
65 wxWindow* m_window;
2b5f62a0 66
8b089c5e
JS
67private:
68 DECLARE_CLASS(wxGLContext)
69};
70
71//---------------------------------------------------------------------------
a6f5aa49 72// wxGLCanvas
8b089c5e
JS
73//---------------------------------------------------------------------------
74
4660d7e5 75class WXDLLEXPORT wxGLCanvas: public wxWindow
8b089c5e
JS
76{
77public:
78 inline wxGLCanvas() {
79 m_glContext = (wxGLContext*) NULL;
80 m_sharedContext = (wxGLContext*) NULL;
81 m_glWidget = (GtkWidget*) NULL;
82 m_vi = (void*) NULL;
83 m_exposed = FALSE;
84 }
2b5f62a0 85 wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
8b089c5e 86 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
87 const wxSize& size = wxDefaultSize,
88 long style = 0, const wxString& name = wxGLCanvasName,
89 int *attribList = (int*) NULL,
8b089c5e 90 const wxPalette& palette = wxNullPalette );
a0573e8e 91 wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
2b5f62a0 92 wxWindowID id = -1,
8b089c5e 93 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
94 const wxSize& size = wxDefaultSize,
95 long style = 0, const wxString& name = wxGLCanvasName,
96 int *attribList = (int*) NULL,
8b089c5e 97 const wxPalette& palette = wxNullPalette );
a0573e8e 98 wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
2b5f62a0 99 wxWindowID id = -1,
8b089c5e 100 const wxPoint& pos = wxDefaultPosition,
2b5f62a0
VZ
101 const wxSize& size = wxDefaultSize,
102 long style = 0, const wxString& name = wxGLCanvasName,
103 int *attribList = (int*) NULL,
8b089c5e
JS
104 const wxPalette& palette = wxNullPalette );
105
2b5f62a0
VZ
106 bool Create( wxWindow *parent,
107 const wxGLContext *shared = (wxGLContext*)NULL,
108 const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
109 wxWindowID id = -1,
110 const wxPoint& pos = wxDefaultPosition,
111 const wxSize& size = wxDefaultSize,
112 long style = 0,
113 const wxString& name = wxGLCanvasName,
114 int *attribList = (int*) NULL,
115 const wxPalette& palette = wxNullPalette );
116
d3c7fc99 117 virtual ~wxGLCanvas();
8b089c5e
JS
118
119 void SetCurrent();
2b5f62a0 120 void SetColour(const wxChar *colour);
8b089c5e
JS
121 void SwapBuffers();
122
123 void OnSize(wxSizeEvent& event);
2b5f62a0 124
8b089c5e
JS
125 void OnInternalIdle();
126
2b5f62a0 127 inline wxGLContext* GetContext() const { return m_glContext; }
8b089c5e
JS
128
129 // implementation
2b5f62a0 130
8b089c5e
JS
131 wxGLContext *m_glContext,
132 *m_sharedContext;
133 wxGLCanvas *m_sharedContextOf;
a6f5aa49 134 void *m_vi; // actually an XVisualInfo*
34a34b02 135 GLXFBConfig *m_fbc;
a6f5aa49 136 bool m_canFreeVi;
34a34b02 137 bool m_canFreeFBC;
8b089c5e
JS
138 GtkWidget *m_glWidget;
139 bool m_exposed;
2b5f62a0 140
a6f5aa49
VZ
141 // returns an XVisualInfo* based on desired GL attributes;
142 // returns NULL if an appropriate visual is not found. The
2b5f62a0 143 // caller is reponsible for using XFree() to deallocate
a6f5aa49
VZ
144 // the returned structure.
145 static void* ChooseGLVisual(int *attribList);
34a34b02
VZ
146 static void* ChooseGLFBC(int *attribList);
147 static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
8b089c5e 148
34a34b02
VZ
149 static void QueryGLXVersion();
150 static int GetGLXVersion();
151 static int m_glxVersion;
8b089c5e
JS
152private:
153 DECLARE_EVENT_TABLE()
154 DECLARE_CLASS(wxGLCanvas)
155};
156
8b089c5e
JS
157#endif
158 // _WX_GLCANVAS_H_
159