Included two gl canvas with texture sharing and basic projection

This commit is contained in:
Tats
2013-11-15 11:41:54 +01:00
parent 4146740aa7
commit 3e5552eb08
8 changed files with 40 additions and 6 deletions
+3 -3
View File
@@ -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 ) );
@@ -34,6 +34,9 @@ void DestinationGLCanvas::doRender() {
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
wxASSERT(texture != NULL);
if (texture->getTextureId() == 0)
texture->loadTexture();
// Now, draw
// DRAW THE TEXTURE
glPushMatrix();
+10
View File
@@ -43,6 +43,11 @@ public:
: _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; }
@@ -61,6 +66,10 @@ public:
_inputShape(inputShape)
{}
virtual void build() {
Mapping::build();
_inputShape->build();
}
public:
std::tr1::shared_ptr<Shape> getInputShape() const { return _inputShape; }
};
@@ -132,6 +141,7 @@ public:
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);
@@ -84,7 +84,10 @@ void MapperGLCanvas::OnMouseEvent(wxMouseEvent& event) {
}
void MapperGLCanvas::Render() {
SetCurrent();
if (!sharedContext) {
sharedContext = GetContext();
}
SetCurrent(*sharedContext);
wxPaintDC dc(this);
enterRender();
+5 -1
View File
@@ -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; }
};
+3
View File
@@ -38,6 +38,9 @@ public:
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)
@@ -34,6 +34,9 @@ void SourceGLCanvas::doRender() {
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
wxASSERT(texture != NULL);
if (texture->getTextureId() == 0)
texture->loadTexture();
// Now, draw
// DRAW THE TEXTURE
glPushMatrix();
+9 -1
View File
@@ -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;
}
//