2 #include <wx/glcanvas.h>
3 #include <boost/bind.hpp>
5 class GLView : public wxGLCanvas
8 GLView (wxFrame* parent);
12 void paint (wxPaintEvent& event);
14 wxGLContext* _context;
17 GLView::GLView(wxFrame *parent)
18 : wxGLCanvas (parent, wxID_ANY, 0)
20 _context = new wxGLContext (this);
21 Bind (wxEVT_PAINT, boost::bind(&GLView::paint, this, _1));
29 void GLView::paint (wxPaintEvent &)
31 SetCurrent (*_context);
33 glClear(GL_COLOR_BUFFER_BIT);
35 glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
36 glEnable(GL_TEXTURE_2D);
37 glDisable(GL_DEPTH_TEST);
38 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
40 glViewport (0, 0, GetSize().x, GetSize().y);
41 glMatrixMode(GL_PROJECTION);
44 glOrtho (0, GetSize().x, GetSize().y, 0, -1, 1);
45 glMatrixMode(GL_MODELVIEW);
48 //create test checker image
49 unsigned char texDat[64];
50 for (int i = 0; i < 64; ++i)
51 texDat[i] = ((i + (i / 8)) % 2) * 128 + 127;
53 //upload to GPU texture
55 glGenTextures(1, &tex);
56 glBindTexture(GL_TEXTURE_2D, tex);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
59 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texDat);
60 glBindTexture(GL_TEXTURE_2D, 0);
62 //match projection to window resolution (could be in reshape callback)
63 // glMatrixMode(GL_PROJECTION);
64 // glOrtho(0, 800, 0, 600, -1, 1);
65 // glMatrixMode(GL_MODELVIEW);
67 glClear(GL_COLOR_BUFFER_BIT);
69 glBindTexture(GL_TEXTURE_2D, tex);
70 glEnable(GL_TEXTURE_2D);
72 glTexCoord2i(0, 0); glVertex2f(0, 0);
73 glTexCoord2i(0, 1); glVertex2f(0, 100);
74 glTexCoord2i(1, 1); glVertex2f(100, 100);
75 glTexCoord2i(1, 0); glVertex2f(100, 0);
77 glDisable(GL_TEXTURE_2D);
78 glBindTexture(GL_TEXTURE_2D, 0);
84 class MyApp : public wxApp
88 wxFrame *frame = new wxFrame (0, -1, wxT("Hello GL World"), wxPoint(50,50), wxSize(200,200));