2 #include <wx/glcanvas.h>
3 #include <boost/bind.hpp>
5 class GLView : public wxGLCanvas
8 GLView (wxFrame* parent);
11 void paint (wxPaintEvent& event);
15 GLView::GLView(wxFrame *parent)
16 : wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas"))
18 Bind (wxEVT_PAINT, boost::bind(&GLView::paint, this, _1));
21 void GLView::paint (wxPaintEvent &)
25 glClearColor(0.0, 0.0, 0.0, 0.0);
26 glClear(GL_COLOR_BUFFER_BIT);
27 glViewport(0, 0, (GLint)GetSize().x, (GLint)GetSize().y);
29 //create test checker image
30 unsigned char texDat[64];
31 for (int i = 0; i < 64; ++i)
32 texDat[i] = ((i + (i / 8)) % 2) * 128 + 127;
34 //upload to GPU texture
36 glGenTextures(1, &tex);
37 glBindTexture(GL_TEXTURE_2D, tex);
38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
40 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texDat);
41 glBindTexture(GL_TEXTURE_2D, 0);
43 //match projection to window resolution (could be in reshape callback)
44 // glMatrixMode(GL_PROJECTION);
45 // glOrtho(0, 800, 0, 600, -1, 1);
46 // glMatrixMode(GL_MODELVIEW);
48 glClear(GL_COLOR_BUFFER_BIT);
50 glBindTexture(GL_TEXTURE_2D, tex);
51 glEnable(GL_TEXTURE_2D);
53 glTexCoord2i(0, 0); glVertex2f(-0.5, -0.5);
54 glTexCoord2i(0, 1); glVertex2f(-0.5, 0.5);
55 glTexCoord2i(1, 1); glVertex2f(0.5, 0.5);
56 glTexCoord2i(1, 0); glVertex2f(0.5, -0.5);
58 glDisable(GL_TEXTURE_2D);
59 glBindTexture(GL_TEXTURE_2D, 0);
65 class MyApp : public wxApp
69 wxFrame *frame = new wxFrame (0, -1, wxT("Hello GL World"), wxPoint(50,50), wxSize(200,200));