diff options
| author | Tim Redfern <tim@eclectronics.org> | 2011-12-31 18:14:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2011-12-31 18:14:38 +0000 |
| commit | a728ca18def61a13bbd7d0680dfab011d7ea20ac (patch) | |
| tree | 47f6555e649b1dcdf459d9e2180ac7352b77e403 /src | |
| parent | 4f1d5b3a6efe1de7885b37b091595f7bbc8a9b29 (diff) | |
succesfully combined camera and FBO
Diffstat (limited to 'src')
| -rw-r--r-- | src/mapUtils.cpp | 79 | ||||
| -rw-r--r-- | src/mapUtils.h | 16 |
2 files changed, 95 insertions, 0 deletions
diff --git a/src/mapUtils.cpp b/src/mapUtils.cpp new file mode 100644 index 0000000..1023a40 --- /dev/null +++ b/src/mapUtils.cpp @@ -0,0 +1,79 @@ +/* + * mapUtils.h + * + * Created by Tim Redfern on 20/12/2011. + * global utils for projection mapping + * + */ +#pragma once + +#include "ofMain.h" + +void bindTexture(ofBaseHasTexture &t) { + ofTexture &tex = t.getTextureReference(); + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTexture(ofBaseHasTexture &t) { + t.getTextureReference().unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} +ofPoint distort(ofPoint pt,float d){ + //normalised coords -1..1, d + float r=pow(pow(pow(pt.x,2.0f)+pow(pt.y,2.0f),0.5f),1.0f+d); + float a=atan2f(pt.x,pt.y); + return ofPoint(r*sin(a),r*cos(a)); +}; + +void drawBox(float size) { + // this func just draws a perfectly normal box with some texture coordinates + glBegin(GL_QUADS); + // Front Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, size); // Top Left Of The Texture and Quad + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, -size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, -size); // Bottom Left Of The Texture and Quad + // Top Face + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // Top Right Of The Texture and Quad + // Bottom Face + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, -size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, -size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Right Of The Texture and Quad + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, -size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Left Of The Texture and Quad + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, -size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // Top Left Of The Texture and Quad + glEnd(); +} + + diff --git a/src/mapUtils.h b/src/mapUtils.h new file mode 100644 index 0000000..002f90a --- /dev/null +++ b/src/mapUtils.h @@ -0,0 +1,16 @@ +/* + * mapUtils.h + * + * Created by Tim Redfern on 20/12/2011. + * global utils for projection mapping + * + */ +#pragma once + +#include "ofMain.h" + +void bindTexture(ofBaseHasTexture &t); +void unbindTexture(ofBaseHasTexture &t); +ofPoint distort(ofPoint pt,float d); +void drawBox(float size); + |
