diff --git a/prototypes/wx-02-input-output/Common.cpp b/prototypes/wx-02-input-output/Common.cpp index e7ef8b7..29d7816 100644 --- a/prototypes/wx-02-input-output/Common.cpp +++ b/prototypes/wx-02-input-output/Common.cpp @@ -26,9 +26,9 @@ void Common::initializeLibremapper() { TextureMapping* tm = new TextureMapping( new Image("example.png"), new Quad(Point(0, 0), Point(320, 0), - Point(0, 240), Point(320, 240)), - new Quad(Point(-320, -240), Point(-320, 0), - Point(0, -240), Point(0, 0)) + Point(320, 240), Point(0, 240)), + new Quad(Point(0, 0), Point(320, 0), + Point(320, 240), Point(0, 240)) ); Common::currentMapping.reset( tm ); Common::currentMapper.reset( new QuadTextureMapper( tm ) ); diff --git a/prototypes/wx-02-input-output/DestinationGLCanvas.cpp b/prototypes/wx-02-input-output/DestinationGLCanvas.cpp index c885c74..0f966b7 100644 --- a/prototypes/wx-02-input-output/DestinationGLCanvas.cpp +++ b/prototypes/wx-02-input-output/DestinationGLCanvas.cpp @@ -34,6 +34,9 @@ void DestinationGLCanvas::doRender() { std::tr1::shared_ptr texture = std::tr1::static_pointer_cast(textureMapping->getPaint()); wxASSERT(texture != NULL); + if (texture->getTextureId() == 0) + texture->loadTexture(); + // Now, draw // DRAW THE TEXTURE glPushMatrix(); diff --git a/prototypes/wx-02-input-output/Mapper.h b/prototypes/wx-02-input-output/Mapper.h index ea76e53..a192074 100644 --- a/prototypes/wx-02-input-output/Mapper.h +++ b/prototypes/wx-02-input-output/Mapper.h @@ -43,6 +43,11 @@ public: : _paint(paint), _shape(shape) {} + virtual void build() { + _paint->build(); + _shape->build(); + } + public: std::tr1::shared_ptr getPaint() const { return _paint; } std::tr1::shared_ptr getShape() const { return _shape; } @@ -61,6 +66,10 @@ public: _inputShape(inputShape) {} + virtual void build() { + Mapping::build(); + _inputShape->build(); + } public: std::tr1::shared_ptr getInputShape() const { return _inputShape; } }; @@ -132,6 +141,7 @@ public: std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape()); wxASSERT(inputQuad != NULL); + printf("Texid: %d\n", texture->getTextureId()); // Project source texture and sent it to destination. glEnable (GL_TEXTURE_2D); diff --git a/prototypes/wx-02-input-output/MapperGLCanvas.cpp b/prototypes/wx-02-input-output/MapperGLCanvas.cpp index 1a6b637..73a9067 100644 --- a/prototypes/wx-02-input-output/MapperGLCanvas.cpp +++ b/prototypes/wx-02-input-output/MapperGLCanvas.cpp @@ -84,7 +84,10 @@ void MapperGLCanvas::OnMouseEvent(wxMouseEvent& event) { } void MapperGLCanvas::Render() { - SetCurrent(); + if (!sharedContext) { + sharedContext = GetContext(); + } + SetCurrent(*sharedContext); wxPaintDC dc(this); enterRender(); diff --git a/prototypes/wx-02-input-output/Paint.h b/prototypes/wx-02-input-output/Paint.h index ad5bac5..9913c5e 100644 --- a/prototypes/wx-02-input-output/Paint.h +++ b/prototypes/wx-02-input-output/Paint.h @@ -43,6 +43,7 @@ protected: public: GLuint getTextureId() const { return textureId; } + virtual void loadTexture() = 0; virtual int getWidth() const = 0; virtual int getHeight() const = 0; }; @@ -58,13 +59,16 @@ public: Image(const std::string imagePath_) : Texture(), imagePath(imagePath_), width(-1), height(-1) {} virtual ~Image() {} - virtual void build() { + virtual void loadTexture() { unsigned char * data = SOIL_load_image(imagePath.c_str(), &width, &height, 0, SOIL_LOAD_RGB ); wxASSERT(data); textureId = SOIL_create_OGL_texture ( data, width, height, 3, textureId, 0); // TODO: free data? } + virtual void build() { + } + virtual int getWidth() const { return width; } virtual int getHeight() const { return height; } }; diff --git a/prototypes/wx-02-input-output/Shape.h b/prototypes/wx-02-input-output/Shape.h index c1f6331..279e235 100644 --- a/prototypes/wx-02-input-output/Shape.h +++ b/prototypes/wx-02-input-output/Shape.h @@ -38,6 +38,9 @@ public: Shape() {} Shape(std::vector 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) diff --git a/prototypes/wx-02-input-output/SourceGLCanvas.cpp b/prototypes/wx-02-input-output/SourceGLCanvas.cpp index 42f6061..d491e09 100644 --- a/prototypes/wx-02-input-output/SourceGLCanvas.cpp +++ b/prototypes/wx-02-input-output/SourceGLCanvas.cpp @@ -34,6 +34,9 @@ void SourceGLCanvas::doRender() { std::tr1::shared_ptr texture = std::tr1::static_pointer_cast(textureMapping->getPaint()); wxASSERT(texture != NULL); + if (texture->getTextureId() == 0) + texture->loadTexture(); + // Now, draw // DRAW THE TEXTURE glPushMatrix(); diff --git a/prototypes/wx-02-input-output/main.cpp b/prototypes/wx-02-input-output/main.cpp index 64ba986..305281b 100644 --- a/prototypes/wx-02-input-output/main.cpp +++ b/prototypes/wx-02-input-output/main.cpp @@ -28,11 +28,19 @@ bool MyApp::OnInit() { Common::initializeLibremapper(); 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); + destinationCanvas = new DestinationGLCanvas(frame); + + topSizer->Add(sourceCanvas, 1, wxEXPAND); + topSizer->Add(destinationCanvas, 1, wxEXPAND); + // frame->SetWindowStyle(wxWANTS_CHARS); + frame->SetSizer(topSizer); frame->Show(TRUE); + return TRUE; } //