reorganized the code to put the logic in wxGLContext-derived class but keep the state...
[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 // the rendering context used by all GL canvases
18 class TestGLContext : public wxGLContext
19 {
20 public:
21 TestGLContext(wxGLCanvas *canvas);
22
23 // render the cube showing it at given angles
24 void DrawRotatedCube(float xangle, float yangle);
25
26 private:
27 // one-time OpenGL initialization, safe to call many times
28 void Init();
29
30
31 // the list of commands to draw the cube
32 GLuint m_gllist;
33 };
34
35 // Define a new application type
36 class MyApp: public wxApp
37 {
38 public:
39 MyApp() { m_glContext = NULL; }
40
41 // get the context we use creating it on demand (and set it as current)
42 TestGLContext& GetContext(wxGLCanvas *canvas);
43
44 // virtual wxApp methods
45 virtual bool OnInit();
46 virtual int OnExit();
47
48 private:
49 // the GL context we use for all our windows
50 TestGLContext *m_glContext;
51 };
52
53 // Define a new frame type
54 class MyFrame: public wxFrame
55 {
56 public:
57 MyFrame();
58
59 private:
60 void OnClose(wxCommandEvent& event);
61 void OnNewWindow(wxCommandEvent& event);
62 void OnDefRotateLeftKey(wxCommandEvent& event);
63 void OnDefRotateRightKey(wxCommandEvent& event);
64
65 DECLARE_EVENT_TABLE()
66 };
67
68 class TestGLCanvas : public wxGLCanvas
69 {
70 public:
71 TestGLCanvas(wxWindow *parent);
72
73 private:
74 void OnPaint(wxPaintEvent& event);
75 void OnSize(wxSizeEvent& event);
76 void OnKeyDown(wxKeyEvent& event);
77
78 // angles of rotation around x- and y- axis
79 float m_xangle,
80 m_yangle;
81
82 DECLARE_EVENT_TABLE()
83 };
84
85 #endif // _WX_CUBE_H_
86