refresh GL canvas itself, not the frame, when the GL context changes, otherwise it...
[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 // update the image shown on the canvas (after the shared wxGLContext was
44 // updated, presumably)
45 void RefreshCanvas();
46
47 private:
48 void OnExit(wxCommandEvent& event);
49 void OnNewWindow(wxCommandEvent& event);
50 void OnDefRotateLeftKey(wxCommandEvent& event);
51 void OnDefRotateRightKey(wxCommandEvent& event);
52
53 TestGLCanvas *m_canvas;
54
55 DECLARE_EVENT_TABLE()
56 };
57
58 class TestGLCanvas : public wxGLCanvas
59 {
60 public:
61 TestGLCanvas(wxWindow *parent);
62
63 private:
64 void OnPaint(wxPaintEvent& event);
65 void OnSize(wxSizeEvent& event);
66 void OnKeyDown(wxKeyEvent& event);
67
68 // OpenGL calls can't be done until we're initialized
69 bool IsInitialized() const { return m_gllist != 0; }
70
71 // one-time OpenGL initialization, only does something if !IsInitialized()
72 void InitGL();
73
74 // render to window
75 void Render();
76
77
78 // the list of commands to draw the cube
79 GLuint m_gllist;
80
81 DECLARE_EVENT_TABLE()
82 };
83
84 #endif // _WX_CUBE_H_
85