Removed wxWidget prototypes

This commit is contained in:
Tats
2014-03-15 22:02:13 -04:00
parent c20b47aaf4
commit e6dfbf176d
19 changed files with 0 additions and 1691 deletions
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
# libwxgtk2.8-dev
g++ main.cpp -o run `wx-config --libs --cxxflags --gl-libs` -lglut -lGL -lSOIL -I/usr/include
Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

-373
View File
@@ -1,373 +0,0 @@
// NOTE: To run, it is recommended not to be in Compiz or Beryl, they have shown some instability.
// Needs: libwxgtk2.8-dev libsoil-dev
// g++ main.cpp -o run `wx-config --libs --cxxflags --gl-libs` -lSOIL
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <stdlib.h>
#include <stdio.h>
#include <SOIL/SOIL.h>
#ifndef WIN32
#include <unistd.h> // FIXME: ¿This work/necessary in Windows?
//Not necessary, but if it was, it needs to be replaced by process.h AND io.h
#endif
typedef struct _Quad
{
int x1;
int x2;
int x3;
int x4;
int y1;
int y2;
int y3;
int y4;
} Quad;
static void
move_point (Quad *src, Quad *dst, int index, int x, int y)
{
printf ("move_point (index=%d, x=%d, y=%d)\n", index, x, y);
switch (index)
{
case 1:
src->x1 += x;
src->y1 += y;
break;
case 2:
src->x2 += x;
src->y2 += y;
break;
case 3:
src->x3 += x;
src->y3 += y;
break;
case 4:
src->x4 += x;
src->y4 += y;
break;
case 5:
dst->x1 += x;
dst->y1 += y;
break;
case 6:
dst->x2 += x;
dst->y2 += y;
break;
case 7:
dst->x3 += x;
dst->y3 += y;
break;
case 8:
dst->x4 += x;
dst->y4 += y;
break;
}
}
GLuint load_image (const char *imagepath, float *image_width, float *image_height)
{
int width, height;
GLuint textureID = 0;
unsigned char * data =
SOIL_load_image(imagepath, &width, &height, 0, SOIL_LOAD_RGB );
textureID = SOIL_create_OGL_texture (
data, width, height, 3, textureID, 0);
// TODO: free data?
(* image_width) = width;
(* image_height) = height;
return textureID;
}
class wxGLCanvasSubClass: public wxGLCanvas
{
void Render();
public:
wxGLCanvasSubClass(wxFrame* parent);
void Paintit(wxPaintEvent& event);
void movePoint(int index, int x, int y);
protected:
DECLARE_EVENT_TABLE()
private:
GLuint texture;
float image_width;
float image_height;
Quad src;
Quad dst;
void OnChar(wxKeyEvent & event);
void OnMouseEvent(wxMouseEvent& event);
void setup_texture();
};
BEGIN_EVENT_TABLE(wxGLCanvasSubClass, wxGLCanvas)
EVT_PAINT (wxGLCanvasSubClass::Paintit)
EVT_KEY_DOWN (wxGLCanvasSubClass::OnChar)
EVT_MOUSE_EVENTS(wxGLCanvasSubClass::OnMouseEvent)
// EVT_ENTER_WINDOW(wxGLCanvasSubClass::OnMouseEnter)
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::OnChar(wxKeyEvent & event)
{
static int current = 0;
printf("hello");
switch (event.GetKeyCode())
{
case WXK_TAB:
current = (current + 1) % 8;
printf ("Current = %d\n", current);
break;
case WXK_UP:
move_point (&src, &dst, current + 1, 0, 1);
break;
case WXK_DOWN:
move_point (&src, &dst, current + 1, 0, -1);
break;
case WXK_LEFT:
move_point (&src, &dst, current + 1, -1, 0);
break;
case WXK_RIGHT:
move_point (&src, &dst, current + 1, 1, 0);
break;
default:
printf ("Unhandled key");
break;
}
Render();
}
void wxGLCanvasSubClass::OnMouseEvent(wxMouseEvent& event)
{
printf("x=%d y=%d LeftIsDown=%d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown());
SetFocus();
}
void wxGLCanvasSubClass::setup_texture()
{
texture = load_image ("example.png", &image_width, &image_height);
//source
src.x1 = 0;
src.y1 = 0;
src.x2 = 320;
src.y2 = 0;
src.x3 = 320;
src.y3 = 240;
src.x4 = 0;
src.y4 = 240;
//destination
dst.x1 = -320;
dst.y1 = -240;
dst.x2 = 0;
dst.y2 = -240;
dst.x3 = 0;
dst.y3 = 0;
dst.x4 = -320;
dst.y4 = 0; // 240;
}
void wxGLCanvasSubClass::Render()
{
static bool texture_is_set = false;
float ratio;
SetCurrent();
wxPaintDC dc(this);
if (! texture_is_set)
{
this->setup_texture();
texture_is_set = true;
}
ratio = (float) GetSize().x / (float) GetSize().y;
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, (GLint) GetSize().x, (GLint) GetSize().y);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
// Now, draw
// DRAW THE TEXTURE
glPushMatrix ();
// Enable blending mode (for alphas).
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_LIGHTING);
glEnable (GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Draw source texture (not moving).
glColor4f (1, 1, 1, 0.5f);
glBegin (GL_QUADS);
{
glTexCoord2f (0, 0);
glVertex3f (0, 0, 0);
glTexCoord2f (1, 0);
glVertex3f (1, 0, 0);
glTexCoord2f (1, 1);
glVertex3f (1, 1, 0);
glTexCoord2f (0, 1);
glVertex3f (0, 1, 0);
}
glEnd ();
// Project source texture and sent it to destination.
glColor4f (1, 1, 1, 1.0f);
glBegin (GL_QUADS);
{
glTexCoord2f (src.x1 / image_width, src.y1 / image_height);
glVertex3f (dst.x1 / image_width, dst.y1 / image_height, 0);
glTexCoord2f (src.x2 / image_width, src.y2 / image_height);
glVertex3f (dst.x2 / image_width, dst.y2 / image_height, 0);
glTexCoord2f (src.x3 / image_width, src.y3 / image_height);
glVertex3f (dst.x3 / image_width, dst.y3 / image_height, 0);
glTexCoord2f (src.x4 / image_width, src.y4 / image_height);
glVertex3f (dst.x4 / image_width, dst.y4 / image_height, 0);
}
glEnd ();
glDisable(GL_TEXTURE_2D);
glColor4f (1, 1, 1, 1);
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
glVertex3f(src.x1 / image_width, src.y1 / image_height, 0);
glVertex3f(src.x2 / image_width, src.y2 / image_height, 0);
glVertex3f(src.x3 / image_width, src.y3 / image_height, 0);
glVertex3f(src.x4 / image_width, src.y4 / image_height, 0);
glVertex3f(src.x1 / image_width, src.y1 / image_height, 0);
}
glEnd ();
glColor4f (1, 0, 0, 1);
// Destination quad.
glBegin (GL_LINE_STRIP);
{
glVertex3f(dst.x1 / image_width, dst.y1 / image_height, 0);
glVertex3f(dst.x2 / image_width, dst.y2 / image_height, 0);
glVertex3f(dst.x3 / image_width, dst.y3 / image_height, 0);
glVertex3f(dst.x4 / image_width, dst.y4 / image_height, 0);
glVertex3f(dst.x1 / image_width, dst.y1 / image_height, 0);
}
glEnd ();
glDisable (GL_TEXTURE_2D);
glPopMatrix ();
// Done drawing
glFlush();
SwapBuffers();
}
void wxGLCanvasSubClass::movePoint(int index, int x, int y)
{
move_point (&src, &dst, index, x, y);
}
class MyApp: public wxApp
{
private:
virtual bool OnInit();
wxGLCanvasSubClass * MyGLCanvas;
int FilterEvent(wxEvent& event);
};
int MyApp::FilterEvent(wxEvent& event)
{
static int current = 0;
if ((event.GetEventType() == wxEVT_KEY_DOWN))
{
switch (((wxKeyEvent&)event).GetKeyCode())
{
case WXK_TAB:
current = (current + 1) % 8;
printf ("Current = %d\n", current);
return true;
break;
case WXK_UP:
MyGLCanvas->movePoint(current + 1, 0, 1);
return true;
break;
case WXK_DOWN:
MyGLCanvas->movePoint(current + 1, 0, -1);
return true;
break;
case WXK_LEFT:
MyGLCanvas->movePoint(current + 1, -1, 0);
return true;
break;
case WXK_RIGHT:
MyGLCanvas->movePoint(current + 1, 1, 0);
return true;
break;
default:
printf ("Unhandled key");
break;
}
}
return -1;
}
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, wxT("Hello GL World"), wxPoint(50, 50), wxSize(640, 480));
MyGLCanvas = new wxGLCanvasSubClass(frame);
// frame->SetWindowStyle(wxWANTS_CHARS);
frame->Show(TRUE);
return TRUE;
}
-52
View File
@@ -1,52 +0,0 @@
/*
* Common.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Common.h"
std::tr1::shared_ptr<Mapping> Common::currentMapping;
std::tr1::shared_ptr<Mapper> Common::currentMapper;
void Common::initializeLibremapper(int frameWidth, int frameHeight) {
Image* img = new Image("example.png");
float centerX = frameWidth / 2;
float centerY = frameHeight / 2;
float textureHalfWidth = img->getWidth() / 2;
float textureHalfHeight = img->getHeight() / 2;
// printf("Common: %f %f %f %f\n", centerX, centerY, textureHalfWidth, textureHalfHeight);
TextureMapping* tm = new TextureMapping(
img,
// Destination.
new Quad(Point(centerX-textureHalfWidth, centerY-textureHalfHeight),
Point(centerX+textureHalfWidth, centerY-textureHalfHeight),
Point(centerX+textureHalfWidth, centerY+textureHalfHeight),
Point(centerX-textureHalfWidth, centerY+textureHalfHeight)),
// Input.
new Quad(Point(centerX-textureHalfWidth, centerY-textureHalfHeight),
Point(centerX+textureHalfWidth, centerY-textureHalfHeight),
Point(centerX+textureHalfWidth, centerY+textureHalfHeight),
Point(centerX-textureHalfWidth, centerY+textureHalfHeight))
);
Common::currentMapping.reset( tm );
Common::currentMapper.reset( new QuadTextureMapper( tm ) );
}
-38
View File
@@ -1,38 +0,0 @@
/*
* Common.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_H_
#define COMMON_H_
#include <tr1/memory>
#include "Paint.h"
#include "Shape.h"
#include "Mapper.h"
class Common {
public:
static std::tr1::shared_ptr<Mapping> currentMapping;
static std::tr1::shared_ptr<Mapper> currentMapper;
static void initializeLibremapper(int frameWidth, int frameHeight);
};
#endif /* COMMON_H_ */
@@ -1,71 +0,0 @@
/*
* DestinationGLCanvas.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DestinationGLCanvas.h"
DestinationGLCanvas::DestinationGLCanvas(wxFrame *parent) :
MapperGLCanvas(parent) {
// int argc = 1;
// char* argv[1] = { wxString((wxTheApp ->argv)[0]).char_str() };
}
void DestinationGLCanvas::doRender() {
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
// Il faut changer ca.
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
wxASSERT(textureMapping != NULL);
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
wxASSERT(texture != NULL);
if (texture->getTextureId() == 0)
{
texture->loadTexture();
texture->setPosition( (GetClientSize().x - texture->getWidth()) / 2,
(GetClientSize().y - texture->getHeight()) / 2 );
}
// Now, draw
// DRAW THE TEXTURE
glPushMatrix();
// Draw the mapping.
Common::currentMapper->draw();
// Draw the quad.
Quad& quad = getQuad();
glColor4f(1, 0, 0, 1);
// Destination quad.
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
for (int i=0; i<5; i++) {
glVertex3f(quad.getVertex(i % 4).x,
quad.getVertex(i % 4).y,
0);
}
}
glEnd ();
glPopMatrix();
}
@@ -1,49 +0,0 @@
/*
* DestinationGLCanvas.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DESTINATIONGLCANVAS_H_
#define DESTINATIONGLCANVAS_H_
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <stdlib.h>
#include <stdio.h>
#include <SOIL/SOIL.h>
#include "MapperGLCanvas.h"
class DestinationGLCanvas: public MapperGLCanvas {
public:
DestinationGLCanvas(wxFrame* parent);
virtual Quad& getQuad() {
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
wxASSERT(textureMapping != NULL);
std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(Common::currentMapping->getShape());
wxASSERT(quad != NULL);
return (*quad);
}
private:
virtual void doRender();
};
#endif /* DESTINATIONGLCANVAS_H_ */
-174
View File
@@ -1,174 +0,0 @@
/*
* Mapper.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAPPER_H_
#define MAPPER_H_
#include "Shape.h"
#include "Paint.h"
#include <tr1/memory>
#include <wx/wx.h>
#include <GL/gl.h>
#include <SOIL/SOIL.h>
#include <stdlib.h>
#include <stdio.h>
class Mapping
{
protected:
std::tr1::shared_ptr<Paint> _paint;
std::tr1::shared_ptr<Shape> _shape;
public:
Mapping(Paint* paint, Shape* shape)
: _paint(paint), _shape(shape)
{}
virtual void build() {
_paint->build();
_shape->build();
}
public:
std::tr1::shared_ptr<Paint> getPaint() const { return _paint; }
std::tr1::shared_ptr<Shape> getShape() const { return _shape; }
};
class TextureMapping : public Mapping
{
private:
std::tr1::shared_ptr<Shape> _inputShape;
public:
TextureMapping(Paint* paint,
Shape* shape,
Shape* inputShape)
: Mapping(paint, shape),
_inputShape(inputShape)
{}
virtual void build() {
Mapping::build();
_inputShape->build();
}
public:
std::tr1::shared_ptr<Shape> getInputShape() const { return _inputShape; }
};
class Mapper
{
protected:
std::tr1::shared_ptr<Mapping> _mapping;
Mapper(Mapping* mapping) : _mapping(mapping) {}
virtual ~Mapper() {}
public:
virtual void draw() = 0;
};
//class ShapeDrawer
//{
//protected:
// std:tr1::shared_ptr<Shape> _shape;
//
//public:
// ShapeDrawer(const std:tr1::shared_ptr<Shape>& shape) : _shape(shape) {}
// virtual ~ShapeDrawer() {}
//
// virtual void draw() = 0;
//};
//
//class QuadDrawer
//{
//public:
// QuadDrawer(const std:tr1::shared_ptr<Quad>& quad) : ShapeDrawer(quad) {}
//
// virtual void draw() {
// std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(_shape);
// wxASSERT(quad != NULL);
//
// glColor4f (1, 1, 1, 1);
//
// // Source quad.
// glLineWidth(5);
// glBegin (GL_LINE_STRIP);
// {
// for (int i=0; i<5; i++) {
// glVertex3f(quad->getVertex(i % 4).x / (GLfloat)texture->getWidth(),
// quad->getVertex(i % 4).y / (GLfloat)texture->getHeight(),
// 0);
// }
// }
// glEnd ();
// }
//};
class QuadTextureMapper : public Mapper
{
public:
QuadTextureMapper(TextureMapping* mapping) : Mapper(mapping) {}
virtual ~QuadTextureMapper() {}
virtual void draw() {
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(_mapping);
wxASSERT(textureMapping != NULL);
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
wxASSERT(texture != NULL);
std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(textureMapping->getShape());
wxASSERT(quad != NULL);
std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
wxASSERT(inputQuad != NULL);
printf("Texid: %d\n", texture->getTextureId());
// Project source texture and sent it to destination.
glEnable (GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor4f(1, 1, 1, 1.0f);
glBegin(GL_QUADS);
{
for (int i=0; i<4; i++)
{
glTexCoord2f( ( inputQuad->getVertex(i).x - texture->getX() ) / (GLfloat) texture->getWidth(),
( inputQuad->getVertex(i).y - texture->getY() ) / (GLfloat) texture->getHeight());
glVertex3f( quad->getVertex(i).x,
quad->getVertex(i).y,
0);
}
}
glEnd();
glDisable(GL_TEXTURE_2D);
}
};
#endif /* MAPPER_H_ */
@@ -1,120 +0,0 @@
/*
* MapperGLCanvas.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MapperGLCanvas.h"
wxGLContext* MapperGLCanvas::sharedContext = 0;
BEGIN_EVENT_TABLE (MapperGLCanvas, wxGLCanvas)
EVT_PAINT (MapperGLCanvas::Paintit)
EVT_KEY_DOWN (MapperGLCanvas::OnChar)
EVT_MOUSE_EVENTS(MapperGLCanvas::OnMouseEvent)
// EVT_ENTER_WINDOW(MapperGLCanvas::OnMouseEnter)
END_EVENT_TABLE()
MapperGLCanvas::MapperGLCanvas(wxFrame *parent) :
wxGLCanvas(parent, sharedContext, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0,
wxT("GLCanvas")) {
if (!sharedContext) {
sharedContext = GetContext();
}
// int argc = 1;
// char* argv[1] = { wxString((wxTheApp ->argv)[0]).char_str() };
}
void MapperGLCanvas::Paintit(wxPaintEvent& WXUNUSED(event)) {
GetParent()->Refresh();
Render();
}
void MapperGLCanvas::OnChar(wxKeyEvent & event) {
static int current = 0;
int xMove = 0;
int yMove = 0;
switch (event.GetKeyCode()) {
case WXK_TAB:
current = (current + 1) % 4;
break;
case WXK_UP:
yMove = -1;
break;
case WXK_DOWN:
yMove = +1;
break;
case WXK_LEFT:
xMove = -1;
break;
case WXK_RIGHT:
xMove = +1;
break;
default:
printf("Unhandled key");
break;
}
Quad& quad = getQuad();
Point p = quad.getVertex(current);
p.x += xMove;
p.y += yMove;
quad.setVertex(current, p);
Render();
}
void MapperGLCanvas::OnMouseEvent(wxMouseEvent& event) {
printf("x=%d y=%d LeftIsDown=%d\n", event.GetX(), event.GetY(),
(int) event.LeftIsDown());
SetFocus();
}
void MapperGLCanvas::Render() {
if (!sharedContext) {
sharedContext = GetContext();
}
SetCurrent(*sharedContext);
wxPaintDC dc(this);
enterRender();
doRender();
exitRender();
}
void MapperGLCanvas::enterRender() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint) GetSize().x, (GLint) GetSize().y);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (
0.0f, (float) GetSize().x, // left, right
(float) GetSize().y, 0.0f, // bottom, top
-1.0, 1.0f);
glMatrixMode (GL_MODELVIEW);
// glLoadIdentity (); // FIXME? is this needed here?
}
void MapperGLCanvas::exitRender() {
glFlush();
SwapBuffers();
}
@@ -1,56 +0,0 @@
/*
* MapperGLCanvas.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAPPERGLCANVAS_H_
#define MAPPERGLCANVAS_H_
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include "Common.h"
#include "Shape.h"
class MapperGLCanvas: public wxGLCanvas {
private:
static wxGLContext* sharedContext;
public:
MapperGLCanvas(wxFrame* parent);
virtual ~MapperGLCanvas() {}
virtual void Paintit(wxPaintEvent& event);
virtual Quad& getQuad() = 0;
protected:
DECLARE_EVENT_TABLE()
virtual void Render();
virtual void enterRender();
virtual void doRender() = 0;
virtual void exitRender();
private:
virtual void OnChar(wxKeyEvent& event);
virtual void OnMouseEvent(wxMouseEvent& event);
};
#endif /* MAPPERGLCANVAS_H_ */
-92
View File
@@ -1,92 +0,0 @@
/*
* Paint.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PAINT_H_
#define PAINT_H_
#include <wx/wx.h>
#include <GL/gl.h>
#include <SOIL/SOIL.h>
class Paint
{
protected:
Paint() {}
public:
virtual ~Paint() {}
virtual void build() {}
};
class Texture : public Paint
{
protected:
GLuint textureId;
int x;
int y;
Texture(GLuint textureId_=0) : textureId(textureId_) {}
virtual ~Texture() {}
public:
GLuint getTextureId() const { return textureId; }
virtual void loadTexture() = 0;
virtual int getWidth() const = 0;
virtual int getHeight() const = 0;
virtual void setPosition(int xPos, int yPos) {
x = xPos;
y = yPos;
}
virtual int getX() const { return x; }
virtual int getY() const { return y; }
};
class Image : public Texture
{
protected:
std::string imagePath;
int width;
int height;
int x;
int y;
unsigned char* imageData;
public:
Image(const std::string imagePath_) : Texture(), imagePath(imagePath_), width(-1), height(-1), x(-1), y(-1) {
imageData = SOIL_load_image(imagePath.c_str(), &width, &height, 0, SOIL_LOAD_RGB );
wxASSERT(imageData);
}
virtual ~Image() {}
virtual void loadTexture() {
textureId = SOIL_create_OGL_texture ( imageData, width, height, 3, textureId, 0);
// TODO: free data?
}
virtual void build() {
}
virtual int getWidth() const { return width; }
virtual int getHeight() const { return height; }
};
#endif /* PAINT_H_ */
-66
View File
@@ -1,66 +0,0 @@
/*
* Shape.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHAPE_H_
#define SHAPE_H_
#include <vector>
#include <SOIL/SOIL.h>
struct Point
{
double x;
double y;
Point(double x_, double y_) : x(x_), y(y_) {}
};
class Shape
{
public:
std::vector<Point> vertices;
Shape() {}
Shape(std::vector<Point> vertices_) : vertices(vertices_) {}
virtual ~Shape() {}
virtual void build() {}
const Point& getVertex(int i) { return vertices[i]; }
void setVertex(int i, Point v) { vertices[i] = v; }
void setVertex(int i, double x, double y)
{
vertices[i].x = x;
vertices[i].y = y;
}
};
class Quad : public Shape
{
public:
Quad() {}
Quad(Point p1, Point p2, Point p3, Point p4) {
vertices.push_back(p1);
vertices.push_back(p2);
vertices.push_back(p3);
vertices.push_back(p4);
}
virtual ~Quad() {}
};
#endif /* SHAPE_H_ */
@@ -1,109 +0,0 @@
/*
* SourceGLCanvas.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SourceGLCanvas.h"
SourceGLCanvas::SourceGLCanvas(wxFrame *parent) :
MapperGLCanvas(parent) {
// int argc = 1;
// char* argv[1] = { wxString((wxTheApp ->argv)[0]).char_str() };
}
void SourceGLCanvas::doRender() {
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
// Il faut changer ca.
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
wxASSERT(textureMapping != NULL);
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
wxASSERT(texture != NULL);
if (texture->getTextureId() == 0) {
texture->loadTexture();
texture->setPosition( (GetClientSize().x - texture->getWidth()) / 2,
(GetClientSize().y - texture->getHeight()) / 2 );
}
// Now, draw
// DRAW THE TEXTURE
glPushMatrix();
// Enable blending mode (for alphas).
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_LIGHTING);
glEnable (GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: Exact projection of texture
// see http://stackoverflow.com/questions/15242507/perspective-correct-texturing-of-trapezoid-in-opengl-es-2-0
// Draw source texture (not moving) in the center of the area.
float centerX = GetClientSize().x / 2;
float centerY = GetClientSize().y / 2;
float textureHalfWidth = texture->getWidth() / 2;
float textureHalfHeight = texture->getHeight() / 2;
//printf("SRC: %f %f %f %f\n", centerX, centerY, textureHalfWidth, textureHalfHeight);
glColor4f (1, 1, 1, 1.0f);
glBegin (GL_QUADS);
{
glTexCoord2f (0, 0);
glVertex3f (texture->getX(), texture->getY(), 0);
glTexCoord2f (1, 0);
glVertex3f (texture->getX()+texture->getWidth(), texture->getY(), 0);
glTexCoord2f (1, 1);
glVertex3f (texture->getX()+texture->getWidth(), texture->getY()+texture->getHeight(), 0);
glTexCoord2f (0, 1);
glVertex3f (texture->getX(), texture->getY()+texture->getHeight(), 0);
}
glEnd ();
glDisable(GL_TEXTURE_2D);
// Draw the quad.
Quad& quad = getQuad();
glColor4f(1, 0, 0, 1);
// Source quad.
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
for (int i=0; i<5; i++) {
glVertex3f(quad.getVertex(i % 4).x,
quad.getVertex(i % 4).y,
0);
}
}
glEnd ();
glPopMatrix();
}
@@ -1,50 +0,0 @@
/*
* SourceGLCanvas.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOURCEGLCANVAS_H_
#define SOURCEGLCANVAS_H_
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <stdlib.h>
#include <stdio.h>
#include <SOIL/SOIL.h>
#include "MapperGLCanvas.h"
class SourceGLCanvas: public MapperGLCanvas {
public:
SourceGLCanvas(wxFrame* parent);
virtual Quad& getQuad() {
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
wxASSERT(textureMapping != NULL);
std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
wxASSERT(inputQuad != NULL);
return (*inputQuad);
}
private:
virtual void doRender();
};
#endif /* DESTINATIONGLCANVAS_H_ */
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
# libwxgtk2.8-dev
g++ main.cpp Common.cpp DestinationGLCanvas.cpp SourceGLCanvas.cpp MapperGLCanvas.cpp -o run `wx-config --libs --cxxflags --gl-libs` -lglut -lGL -lSOIL -I/usr/include
Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

-63
View File
@@ -1,63 +0,0 @@
// NOTE: To run, it is recommended not to be in Compiz or Beryl, they have shown some instability.
#include <wx/wx.h>
#include "Common.h"
#include "DestinationGLCanvas.h"
#include "SourceGLCanvas.h"
#include <stdlib.h>
#include <stdio.h>
#ifndef WIN32
#include <unistd.h> // FIXME: ¿This work/necessary in Windows?
//Not necessary, but if it was, it needs to be replaced by process.h AND io.h
#endif
class MyApp: public wxApp
{
virtual bool OnInit();
SourceGLCanvas * sourceCanvas;
DestinationGLCanvas * destinationCanvas;
//public:
// int FilterEvent(wxEvent& event);
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, wxT("Libremapping"), wxPoint(50, 50), wxSize(640, 480));
wxBoxSizer* topSizer = new wxBoxSizer( wxHORIZONTAL );
sourceCanvas = new SourceGLCanvas(frame);
destinationCanvas = new DestinationGLCanvas(frame);
topSizer->Add(sourceCanvas, 1, wxEXPAND);
topSizer->AddSpacer(10);
topSizer->Add(destinationCanvas, 1, wxEXPAND);
// frame->SetWindowStyle(wxWANTS_CHARS);
frame->SetSizer(topSizer);
// HACK: values 320x480 should be retrieved automatically
Common::initializeLibremapper(320, 480);
frame->Show(TRUE);
return TRUE;
}
//
//int MyApp::FilterEvent(wxEvent& event) {
// printf("Event: %d %d\n", event.GetEventType(), wxEVT_KEY_DOWN);
//
// if (event.GetEventType() == wxEVT_CHAR) {
// printf("Char: %d\n", ((wxKeyEvent&)event).GetKeyCode());
// return true;
// }
//
// return -1;
//}
//
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
# libwxgtk2.8-dev
g++ main.cpp -o run `wx-config --libs --cxxflags --gl-libs`
-369
View File
@@ -1,369 +0,0 @@
// NOTE: To run, it is recommended not to be in Compiz or Beryl, they have shown some instability.
// Needs: libwxgtk2.8-dev
// g++ main.cpp -o run `wx-config --libs --cxxflags --gl-libs`
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#ifndef WIN32
#include <unistd.h> // FIXME: ¿This work/necessary in Windows?
//Not necessary, but if it was, it needs to be replaced by process.h AND io.h
#endif
typedef enum
{
LINES = 0,
POLYGON = 1
} Style;
/*
* Left: place point
* Right: remove previous point
* Middle: invisible line. (no line)
*/
class Point
{
public:
Point(float x, float y)
{
this->x = x;
this->y = y;
}
float x;
float y;
};
class PolyLine
{
public:
void addPoint(Point point);
void removeLastPoint();
void clear();
void draw();
unsigned int size();
void setStyle(Style style);
private:
std::vector<Point> points;
Style style;
};
void PolyLine::setStyle(Style style)
{
this->style = style;
}
unsigned int PolyLine::size()
{
return points.size();
}
void PolyLine::addPoint(Point point)
{
points.push_back(point);
}
void PolyLine::removeLastPoint()
{
if (points.size() >= 1)
points.erase(points.end());
}
void PolyLine::clear()
{
points.clear();
}
void PolyLine::draw()
{
std::vector<Point>::const_iterator iter;
glPushMatrix ();
if (style == LINES)
glBegin (GL_LINE_STRIP);
else if (style == POLYGON)
glBegin (GL_POLYGON);
for (iter = points.begin(); iter != points.end(); iter++)
glVertex3f ((*iter).x, (*iter).y, 0.0f);
glEnd ();
glPopMatrix ();
}
class Manager
{
public:
void addPoint(Point point);
void addPolyLine(Point point);
void removeLastPoint();
void draw();
void clear();
void setStyle(Style style);
Style getStyle();
private:
std::vector<PolyLine> lines;
unsigned int current;
Style style;
};
void Manager::setStyle(Style style)
{
this->style = style;
}
Style Manager::getStyle()
{
return style;
}
void Manager::addPoint(Point point)
{
if (lines.size() == 0)
{
lines.push_back(PolyLine());
current = 0;
}
lines[current].addPoint(point);
}
void Manager::addPolyLine(Point point)
{
lines.push_back(PolyLine());
current++;
lines[current].addPoint(point);
}
void Manager::removeLastPoint()
{
// TODO: return bool
if (lines.size() > 0)
{
if (lines[current].size() == 0)
if (current == 0)
lines.clear();
else
{
lines.erase(lines.end());
current--;
}
else
lines[current].removeLastPoint();
}
}
void Manager::draw()
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable (GL_TEXTURE_2D);
glEnable(GL_LINE_SMOOTH);
glLineWidth(3.0f);
glDisable (GL_LIGHTING);
glColor3f (0.2f, 1.0f, 0.2f);
std::vector<PolyLine>::iterator iter;
for (iter = lines.begin(); iter != lines.end(); iter++)
{
(*iter).setStyle(style);
(*iter).draw();
}
}
void Manager::clear()
{
lines.clear();
}
void draw_marquee(float x, float y)
{
const int length = 30;
const int distance = 10;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable (GL_TEXTURE_2D);
glEnable(GL_LINE_SMOOTH);
glLineWidth(3.0f);
glDisable (GL_LIGHTING);
glColor3f (1.0f, 0.0f, 0.0f);
glBegin(GL_LINES);
glVertex3f(x - (length + distance), y, 0.0f);
glVertex3f(x - distance, y, 0.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(x + (length + distance), y, 0.0f);
glVertex3f(x + distance, y, 0.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(x, y - (length + distance), 0.0f);
glVertex3f(x, y - distance, 0.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(x, y + (length + distance), 0.0f);
glVertex3f(x, y + distance, 0.0f);
glEnd();
}
class MyCanvas: public wxGLCanvas
{
void Render();
public:
MyCanvas(wxFrame* parent);
void evt_paint_cb(wxPaintEvent& event);
protected:
DECLARE_EVENT_TABLE()
private:
void evt_mouse_events_cb (wxMouseEvent& event);
void evt_key_down_cb (wxKeyEvent& event);
void setup_polyline ();
Manager manager;
float mousex;
float mousey;
};
BEGIN_EVENT_TABLE(MyCanvas, wxGLCanvas)
EVT_PAINT (MyCanvas::evt_paint_cb)
EVT_KEY_DOWN (MyCanvas::evt_key_down_cb)
EVT_MOUSE_EVENTS(MyCanvas::evt_mouse_events_cb)
END_EVENT_TABLE()
MyCanvas::MyCanvas(wxFrame *parent)
:wxGLCanvas(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas"))
{
int argc = 1;
char* argv[1] = { wxString((wxTheApp->argv)[0]).char_str() };
}
void MyCanvas::evt_paint_cb(wxPaintEvent& WXUNUSED(event))
{
Render();
}
void MyCanvas::evt_mouse_events_cb(wxMouseEvent& event)
{
//printf("x=%d y=%d LeftIsDown=%d\n", event.GetX(), event.GetY(), (int) event.LeftIsDown());
bool should_render = false;
Point point = Point(mousex, mousey);
mousex = (float) event.GetX();
mousey = (float) event.GetY();
should_render = true;
if (event.LeftIsDown())
{
manager.addPoint(point);
should_render = true;
}
else if (event.RightIsDown())
{
// FIXME
manager.removeLastPoint();
manager.removeLastPoint();
should_render = true;
}
else if (event.MiddleIsDown())
{
manager.addPolyLine(point);
should_render = true;
}
else
{
manager.removeLastPoint();
manager.addPoint(point);
should_render = true;
}
// if (event.Leaving()) { }
// else if (event.Entering()) { }
if (should_render)
Render();
// To catch keyboard events
SetFocus();
}
void MyCanvas::evt_key_down_cb(wxKeyEvent & event)
{
bool should_render = false;
switch (event.GetKeyCode())
{
case WXK_TAB:
if (manager.getStyle() == POLYGON)
manager.setStyle(LINES);
else
manager.setStyle(POLYGON);
should_render = true;
break;
case WXK_UP:
break;
case WXK_DOWN:
break;
case WXK_LEFT:
break;
case WXK_RIGHT:
break;
default:
break;
}
if (should_render)
Render();
}
void MyCanvas::setup_polyline()
{
manager.clear();
}
void MyCanvas::Render()
{
static bool polyline_is_set = false;
SetCurrent();
wxPaintDC(this);
if (! polyline_is_set)
{
setup_polyline();
polyline_is_set = true;
}
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint) GetSize().x, (GLint) GetSize().y);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (
0.0f, (float) GetSize().x, // left, right
(float) GetSize().y, 0.0f, // bottom, top
-1.0, 1.0f);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity (); // FIXME? is this needed here?
manager.draw();
draw_marquee(mousex, mousey);
glFlush();
SwapBuffers();
}
class MyApp: public wxApp
{
private:
virtual bool OnInit();
MyCanvas * MyGLCanvas;
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, wxT("LibreMapping - PolyLine Prototype"), wxPoint(50, 50), wxSize(640, 480));
//frame->SetWindowStyle(wxWANTS_CHARS);
MyGLCanvas = new MyCanvas(frame);
frame->Show(TRUE);
return TRUE;
}