fix the sample to work under X11 (where a context can't be made current before the...
[wxWidgets.git] / samples / opengl / cube / cube.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cube.h
3 // Purpose: wxGLCanvas demo program
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CUBE_H_
13 #define _WX_CUBE_H_
14
15 #include "wx/glcanvas.h"
16
17 // Define a new application type
18 class MyApp: public wxApp
19 {
20 public:
21 MyApp() { m_glContext = NULL; }
22
23 // set the specified canvas for current output
24 void SetCurrent(wxGLCanvas *canvas);
25
26 // virtual wxApp methods
27 virtual bool OnInit();
28 virtual int OnExit();
29
30 private:
31 // the GL context we use for all our windows
32 wxGLContext *m_glContext;
33 };
34
35 // Define a new frame type
36 class TestGLCanvas;
37
38 class MyFrame: public wxFrame
39 {
40 public:
41 MyFrame();
42
43 void OnExit(wxCommandEvent& event);
44 void OnNewWindow(wxCommandEvent& event);
45 void OnDefRotateLeftKey(wxCommandEvent& event);
46 void OnDefRotateRightKey(wxCommandEvent& event);
47
48 private:
49 TestGLCanvas *m_canvas;
50
51 DECLARE_EVENT_TABLE()
52 };
53
54 class TestGLCanvas : public wxGLCanvas
55 {
56 public:
57 TestGLCanvas(wxWindow *parent);
58
59 void OnPaint(wxPaintEvent& event);
60 void OnSize(wxSizeEvent& event);
61 void OnKeyDown(wxKeyEvent& event);
62
63 private:
64 // OpenGL calls can't be done until we're initialized
65 bool IsInitialized() const { return m_gllist != 0; }
66
67 // one-time OpenGL initialization, only does something if !IsInitialized()
68 void InitGL();
69
70 // render to window
71 void Render();
72
73
74 // the list of commands to draw the cube
75 GLuint m_gllist;
76
77 DECLARE_EVENT_TABLE()
78 };
79
80 #endif // _WX_CUBE_H_
81