Initial test code.
authorCarl Hetherington <cth@carlh.net>
Sun, 30 Dec 2018 22:10:34 +0000 (22:10 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 May 2019 20:31:09 +0000 (21:31 +0100)
hacks/gl.cc [new file with mode: 0644]
hacks/makegl.sh [new file with mode: 0644]

diff --git a/hacks/gl.cc b/hacks/gl.cc
new file mode 100644 (file)
index 0000000..8b940bb
--- /dev/null
@@ -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 (file)
index 0000000..4fb8dbd
--- /dev/null
@@ -0,0 +1,2 @@
+g++ -o gl gl.cc `wx-config --cflags --libs` -lGL -lGL -lwx_gtk2u_gl-3.0
+