From 905c2fef8d91f18a1a2ea694f17c641a9f7f3a97 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 30 Dec 2018 22:10:34 +0000 Subject: Initial test code. --- hacks/gl.cc | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hacks/makegl.sh | 2 ++ 2 files changed, 88 insertions(+) create mode 100644 hacks/gl.cc create mode 100644 hacks/makegl.sh 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 +#include + +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 + -- cgit v1.2.3