summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-12-30 22:10:34 +0000
committerCarl Hetherington <cth@carlh.net>2019-05-06 21:31:09 +0100
commit905c2fef8d91f18a1a2ea694f17c641a9f7f3a97 (patch)
tree3d17be40e7a361a1740713da8456a34ffd4067c6
parent69c54ad0211bb772d143b37f14d3186f4d767ebb (diff)
Initial test code.
-rw-r--r--hacks/gl.cc86
-rw-r--r--hacks/makegl.sh2
2 files changed, 88 insertions, 0 deletions
diff --git a/hacks/gl.cc b/hacks/gl.cc
new file mode 100644
index 000000000..8b940bb90
--- /dev/null
+++ b/hacks/gl.cc
@@ -0,0 +1,86 @@
+#include <wx/wx.h>
+#include <wx/glcanvas.h>
+
+class wxGLCanvasSubClass : public wxGLCanvas {
+ void Render();
+public:
+ wxGLCanvasSubClass(wxFrame* parent);
+ void Paintit(wxPaintEvent& event);
+protected:
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxGLCanvasSubClass, wxGLCanvas)
+ EVT_PAINT (wxGLCanvasSubClass::Paintit)
+END_EVENT_TABLE()
+
+wxGLCanvasSubClass::wxGLCanvasSubClass(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();
+}
+
+void wxGLCanvasSubClass::Render()
+{
+ 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;
+
+ //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)
+// 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);
+
+ glFlush();
+ SwapBuffers();
+}
+
+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);
+
+ frame->Show (true);
+ return true;
+ }
+
+ wxGLCanvas* MyGLCanvas;
+};
+
+IMPLEMENT_APP(MyApp)
diff --git a/hacks/makegl.sh b/hacks/makegl.sh
new file mode 100644
index 000000000..4fb8dbdf6
--- /dev/null
+++ b/hacks/makegl.sh
@@ -0,0 +1,2 @@
+g++ -o gl gl.cc `wx-config --cflags --libs` -lGL -lGL -lwx_gtk2u_gl-3.0
+