diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-12-30 22:19:41 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-05-06 21:31:09 +0100 |
| commit | bdbcdcaaa88d85579c2cd54bd220bcf85d0d6a68 (patch) | |
| tree | 21d190b93c02e7c4af34c3dc7d8059e1da2ece5f | |
| parent | 905c2fef8d91f18a1a2ea694f17c641a9f7f3a97 (diff) | |
Tidy up test program a little.
| -rw-r--r-- | hacks/gl.cc | 101 |
1 files changed, 46 insertions, 55 deletions
diff --git a/hacks/gl.cc b/hacks/gl.cc index 8b940bb90..f49e69a35 100644 --- a/hacks/gl.cc +++ b/hacks/gl.cc @@ -1,86 +1,77 @@ #include <wx/wx.h> #include <wx/glcanvas.h> +#include <boost/bind.hpp> -class wxGLCanvasSubClass : public wxGLCanvas { - void Render(); +class GLView : public wxGLCanvas +{ public: - wxGLCanvasSubClass(wxFrame* parent); - void Paintit(wxPaintEvent& event); -protected: - DECLARE_EVENT_TABLE() -}; + GLView (wxFrame* parent); -BEGIN_EVENT_TABLE(wxGLCanvasSubClass, wxGLCanvas) - EVT_PAINT (wxGLCanvasSubClass::Paintit) -END_EVENT_TABLE() +private: + void paint (wxPaintEvent& event); + void Render(); +}; -wxGLCanvasSubClass::wxGLCanvasSubClass(wxFrame *parent) - : wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas")) +GLView::GLView(wxFrame *parent) + : wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas")) { - int argc = 1; - char* argv[1] = { wxString((wxTheApp->argv)[0]).char_str() }; -} - -void wxGLCanvasSubClass::Paintit(wxPaintEvent& WXUNUSED(event)){ - Render(); + Bind (wxEVT_PAINT, boost::bind(&GLView::paint, this, _1)); } -void wxGLCanvasSubClass::Render() +void GLView::paint (wxPaintEvent &) { - SetCurrent(); - wxPaintDC(this); - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, (GLint)GetSize().x, (GLint)GetSize().y); + SetCurrent(); + wxPaintDC(this); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + glViewport(0, 0, (GLint)GetSize().x, (GLint)GetSize().y); - //create test checker image - unsigned char texDat[64]; - for (int i = 0; i < 64; ++i) - texDat[i] = ((i + (i / 8)) % 2) * 128 + 127; + //create test checker image + unsigned char texDat[64]; + for (int i = 0; i < 64; ++i) + texDat[i] = ((i + (i / 8)) % 2) * 128 + 127; - //upload to GPU texture - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texDat); - glBindTexture(GL_TEXTURE_2D, 0); + //upload to GPU texture + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texDat); + glBindTexture(GL_TEXTURE_2D, 0); - //match projection to window resolution (could be in reshape callback) + //match projection to window resolution (could be in reshape callback) // glMatrixMode(GL_PROJECTION); // glOrtho(0, 800, 0, 600, -1, 1); // glMatrixMode(GL_MODELVIEW); - glClear(GL_COLOR_BUFFER_BIT); - glColor3f(1, 1, 1); - glBindTexture(GL_TEXTURE_2D, tex); - glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - glTexCoord2i(0, 0); glVertex2f(-0.5, -0.5); - glTexCoord2i(0, 1); glVertex2f(-0.5, 0.5); - glTexCoord2i(1, 1); glVertex2f(0.5, 0.5); - glTexCoord2i(1, 0); glVertex2f(0.5, -0.5); - glEnd(); - glDisable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 0); + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1, 1, 1); + glBindTexture(GL_TEXTURE_2D, tex); + glEnable(GL_TEXTURE_2D); + glBegin(GL_QUADS); + glTexCoord2i(0, 0); glVertex2f(-0.5, -0.5); + glTexCoord2i(0, 1); glVertex2f(-0.5, 0.5); + glTexCoord2i(1, 1); glVertex2f(0.5, 0.5); + glTexCoord2i(1, 0); glVertex2f(0.5, -0.5); + glEnd(); + glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); - glFlush(); - SwapBuffers(); + glFlush(); + SwapBuffers(); } -class MyApp: public wxApp +class MyApp : public wxApp { bool OnInit() { wxFrame *frame = new wxFrame (0, -1, wxT("Hello GL World"), wxPoint(50,50), wxSize(200,200)); - new wxGLCanvasSubClass(frame); + new GLView(frame); frame->Show (true); return true; } - - wxGLCanvas* MyGLCanvas; }; IMPLEMENT_APP(MyApp) |
