glcanvas.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/glcanvas.h
  3. // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Windows
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 04/01/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GLCANVAS_H_
  11. #define _WX_GLCANVAS_H_
  12. #include "wx/palette.h"
  13. #include "wx/msw/wrapwin.h"
  14. #include <GL/gl.h>
  15. // ----------------------------------------------------------------------------
  16. // wxGLContext: OpenGL rendering context
  17. // ----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
  19. {
  20. public:
  21. wxGLContext(wxGLCanvas *win, const wxGLContext* other = NULL);
  22. virtual ~wxGLContext();
  23. virtual bool SetCurrent(const wxGLCanvas& win) const;
  24. HGLRC GetGLRC() const { return m_glContext; }
  25. protected:
  26. HGLRC m_glContext;
  27. private:
  28. DECLARE_CLASS(wxGLContext)
  29. };
  30. // ----------------------------------------------------------------------------
  31. // wxGLCanvas: OpenGL output window
  32. // ----------------------------------------------------------------------------
  33. class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
  34. {
  35. public:
  36. wxEXPLICIT // avoid implicitly converting a wxWindow* to wxGLCanvas
  37. wxGLCanvas(wxWindow *parent,
  38. wxWindowID id = wxID_ANY,
  39. const int *attribList = NULL,
  40. const wxPoint& pos = wxDefaultPosition,
  41. const wxSize& size = wxDefaultSize,
  42. long style = 0,
  43. const wxString& name = wxGLCanvasName,
  44. const wxPalette& palette = wxNullPalette);
  45. bool Create(wxWindow *parent,
  46. wxWindowID id = wxID_ANY,
  47. const wxPoint& pos = wxDefaultPosition,
  48. const wxSize& size = wxDefaultSize,
  49. long style = 0,
  50. const wxString& name = wxGLCanvasName,
  51. const int *attribList = NULL,
  52. const wxPalette& palette = wxNullPalette);
  53. virtual ~wxGLCanvas();
  54. // implement wxGLCanvasBase methods
  55. virtual bool SwapBuffers();
  56. // MSW-specific helpers
  57. // --------------------
  58. // get the HDC used for OpenGL rendering
  59. HDC GetHDC() const { return m_hDC; }
  60. // try to find pixel format matching the given attributes list for the
  61. // specified HDC, return 0 on error, otherwise pfd is filled in with the
  62. // information from attribList if non-NULL
  63. static int ChooseMatchingPixelFormat(HDC hdc, const int *attribList,
  64. PIXELFORMATDESCRIPTOR *pfd = NULL);
  65. #if wxUSE_PALETTE
  66. // palette stuff
  67. bool SetupPalette(const wxPalette& palette);
  68. virtual wxPalette CreateDefaultPalette();
  69. void OnQueryNewPalette(wxQueryNewPaletteEvent& event);
  70. void OnPaletteChanged(wxPaletteChangedEvent& event);
  71. #endif // wxUSE_PALETTE
  72. // deprecated methods using the implicit wxGLContext, associate the context
  73. // explicitly with the window instead
  74. #if WXWIN_COMPATIBILITY_2_8
  75. wxDEPRECATED(
  76. wxGLCanvas(wxWindow *parent,
  77. wxWindowID id = wxID_ANY,
  78. const wxPoint& pos = wxDefaultPosition,
  79. const wxSize& size = wxDefaultSize,
  80. long style = 0,
  81. const wxString& name = wxGLCanvasName,
  82. const int *attribList = NULL,
  83. const wxPalette& palette = wxNullPalette)
  84. );
  85. wxDEPRECATED(
  86. wxGLCanvas(wxWindow *parent,
  87. const wxGLContext *shared,
  88. wxWindowID id = wxID_ANY,
  89. const wxPoint& pos = wxDefaultPosition,
  90. const wxSize& size = wxDefaultSize,
  91. long style = 0,
  92. const wxString& name = wxGLCanvasName,
  93. const int *attribList = NULL,
  94. const wxPalette& palette = wxNullPalette)
  95. );
  96. wxDEPRECATED(
  97. wxGLCanvas(wxWindow *parent,
  98. const wxGLCanvas *shared,
  99. wxWindowID id = wxID_ANY,
  100. const wxPoint& pos = wxDefaultPosition,
  101. const wxSize& size = wxDefaultSize,
  102. long style = 0,
  103. const wxString& name = wxGLCanvasName,
  104. const int *attribList = NULL,
  105. const wxPalette& palette = wxNullPalette)
  106. );
  107. #endif // WXWIN_COMPATIBILITY_2_8
  108. protected:
  109. // common part of all ctors
  110. void Init();
  111. // the real window creation function, Create() may reuse it twice as we may
  112. // need to create an OpenGL window to query the available extensions and
  113. // then potentially delete and recreate it with another pixel format
  114. bool CreateWindow(wxWindow *parent,
  115. wxWindowID id = wxID_ANY,
  116. const wxPoint& pos = wxDefaultPosition,
  117. const wxSize& size = wxDefaultSize,
  118. long style = 0,
  119. const wxString& name = wxGLCanvasName);
  120. // set up the pixel format using the given attributes and palette
  121. int DoSetup(PIXELFORMATDESCRIPTOR &pfd, const int *attribList);
  122. // HDC for this window, we keep it all the time
  123. HDC m_hDC;
  124. private:
  125. DECLARE_EVENT_TABLE()
  126. DECLARE_CLASS(wxGLCanvas)
  127. };
  128. #endif // _WX_GLCANVAS_H_