Browse Source

Merge branch 'CircleSurface-no-RPi-shaders'

master
c-mendoza 8 years ago
parent
commit
1fc5ba9248
  1. 8
      example/bin/data/magslideshow_settings.xml
  2. 169
      example/bin/data/ofxpimapper.xml
  3. 2
      example/src/main.cpp
  4. 8
      src/Application/Modes/ProjectionMappingMode.cpp
  5. 88
      src/Application/SettingsLoader.cpp
  6. 3
      src/Gui/Widgets/TextureEditorWidget.cpp
  7. 11
      src/Info/Info.cpp
  8. 305
      src/Surfaces/CircleSurface.cpp
  9. 64
      src/Surfaces/CircleSurface.h
  10. 7
      src/Surfaces/SurfaceFactory.cpp
  11. 2
      src/Surfaces/SurfaceFactory.h
  12. 3
      src/Surfaces/SurfaceType.h

8
example/bin/data/magslideshow_settings.xml

@ -1,14 +1,14 @@
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<Width>800</Width>
<Height>600</Height>
<SlideDuration>2</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
<Type>NORMAL</Type> <!-- NONE | NORMAL | PING-PONG -->
<Count>0</Count> <!-- 0 = forever -->
</Loop>
<Transition>
<Type>Dissolve</Type>
<Duration>2</Duration>
<Duration>3</Duration>
</Transition>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>

169
example/bin/data/ofxpimapper.xml

@ -2,16 +2,16 @@
<surface type="0">
<vertices>
<vertex>
<x>244.000000000</x>
<y>151.187255859</y>
<x>119.000000000</x>
<y>379.000000000</y>
</vertex>
<vertex>
<x>397.625549316</x>
<y>304.812774658</y>
<x>387.000000000</x>
<y>96.000000000</y>
</vertex>
<vertex>
<x>90.374511719</x>
<y>304.812774658</y>
<x>405.000000000</x>
<y>657.000000000</y>
</vertex>
</vertices>
<texCoords>
@ -33,23 +33,68 @@
<source-name>image4.jpg</source-name>
</source>
</surface>
<surface type="1">
<surface type="5">
<vertices>
<vertex>
<x>305.332824707</x>
<y>158.923416138</y>
<x>162.000000000</x>
<y>96.000000000</y>
</vertex>
<vertex>
<x>823.889770508</x>
<y>135.275909424</y>
<x>637.290893555</x>
<y>79.031463623</y>
</vertex>
<vertex>
<x>883.853393555</x>
<y>670.724243164</y>
<x>605.286376953</x>
<y>652.968627930</y>
</vertex>
<vertex>
<x>241.146575928</x>
<y>656.366699219</y>
<x>180.000000000</x>
<y>657.000000000</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.159322947</x>
<y>0.055312362</y>
</texCoord>
<texCoord>
<x>0.830520868</x>
<y>0.055312362</y>
</texCoord>
<texCoord>
<x>0.830520868</x>
<y>0.938813090</y>
</texCoord>
<texCoord>
<x>0.159322947</x>
<y>0.938813090</y>
</texCoord>
</texCoords>
<source>
<source-type>fbo</source-type>
<source-name>Slide Show Source</source-name>
</source>
<properties>
<perspectiveWarping>1</perspectiveWarping>
</properties>
</surface>
<surface type="5">
<vertices>
<vertex>
<x>860.523620605</x>
<y>46.077301025</y>
</vertex>
<vertex>
<x>887.000000000</x>
<y>402.000000000</y>
</vertex>
<vertex>
<x>1379.000000000</x>
<y>533.000000000</y>
</vertex>
<vertex>
<x>1183.476318359</x>
<y>46.077301025</y>
</vertex>
</vertices>
<texCoords>
@ -71,8 +116,98 @@
</texCoord>
</texCoords>
<source>
<source-type>fbo</source-type>
<source-name>Slide Show Source</source-name>
<source-type>image</source-type>
<source-name>image2.jpg</source-name>
</source>
<properties>
<perspectiveWarping>1</perspectiveWarping>
</properties>
</surface>
<surface type="5">
<vertices>
<vertex>
<x>1364.000000000</x>
<y>252.000000000</y>
</vertex>
<vertex>
<x>742.000000000</x>
<y>392.000000000</y>
</vertex>
<vertex>
<x>795.000000000</x>
<y>857.000000000</y>
</vertex>
<vertex>
<x>1372.000000000</x>
<y>756.000000000</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.101562500</x>
<y>0.000000000</y>
</texCoord>
<texCoord>
<x>0.884374976</x>
<y>0.000000000</y>
</texCoord>
<texCoord>
<x>0.884374976</x>
<y>1.002777815</y>
</texCoord>
<texCoord>
<x>0.101562500</x>
<y>1.002777815</y>
</texCoord>
</texCoords>
<source>
<source-type>video</source-type>
<source-name>control-panel-and-operation.mp4</source-name>
</source>
<properties>
<perspectiveWarping>1</perspectiveWarping>
</properties>
</surface>
<surface type="5">
<vertices>
<vertex>
<x>341.000000000</x>
<y>222.000000000</y>
</vertex>
<vertex>
<x>341.000000000</x>
<y>990.000000000</y>
</vertex>
<vertex>
<x>1365.000000000</x>
<y>990.000000000</y>
</vertex>
<vertex>
<x>1365.000000000</x>
<y>222.000000000</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.016666668</x>
<y>0.006666641</y>
</texCoord>
<texCoord>
<x>0.536666691</x>
<y>0.006666641</y>
</texCoord>
<texCoord>
<x>0.536666691</x>
<y>0.526666641</y>
</texCoord>
<texCoord>
<x>0.016666668</x>
<y>0.526666641</y>
</texCoord>
</texCoords>
<source>
<source-type>image</source-type>
<source-name>image2.jpg</source-name>
</source>
<properties>
<perspectiveWarping>1</perspectiveWarping>

2
example/src/main.cpp

@ -14,7 +14,7 @@ int main(int argc, char * argv[]){
break;
}
}
Settings::instance()->setFullscreen(fullscreen);
ofSetupOpenGL(1024, 768, OF_WINDOW);

8
src/Application/Modes/ProjectionMappingMode.cpp

@ -58,8 +58,12 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg
case 'q':
app->createSurface(SurfaceType::QUAD_SURFACE);
break;
break;
case 'r':
app->createSurface(SurfaceType::CIRCLE_SURFACE);
break;
case 'g':
app->createSurface(SurfaceType::GRID_WARP_SURFACE);
break;

88
src/Application/SettingsLoader.cpp

@ -20,46 +20,46 @@ bool SettingsLoader::load(
SurfaceManager & surfaceManager,
MediaServer & mediaServer,
string fileName){
ofxXmlSettings * xmlSettings = new ofxXmlSettings();
string sourceType = "";
string sourceName = "";
BaseSource * source = 0;
if(!xmlSettings->loadFile(fileName)){
ofLogWarning("SettingsLoader::load()") << "Could not load XML settings";
return false;
}
if(!xmlSettings->tagExists("surfaces")){
xmlSettings->addTag("surfaces");
}
// Count <surfaces> tags.
unsigned int numPresets = xmlSettings->getNumTags("surfaces");
cout << "numPresets: " << numPresets << endl;
// Clear previous presets and surfaces first.
surfaceManager.clearPresets();
// Loop through <surfaces> tags in the XML.
for(unsigned int i = 0; i < numPresets; ++i){
xmlSettings->pushTag("surfaces", i);
SurfaceStack * surfaces = surfaceManager.createPreset();
int numSurfaces = xmlSettings->getNumTags("surface");
for(int i = 0; i < numSurfaces; i++){
if(xmlSettings->tagExists("surface", i)){
SurfaceType type = SurfaceType::NONE;
if(xmlSettings->attributeExists("surface", "type")){
type = static_cast<SurfaceType>(
xmlSettings->getAttribute("surface", "type", 0, i));
}
xmlSettings->pushTag("surface", i);
// attempt to load surface source
@ -122,6 +122,13 @@ bool SettingsLoader::load(
quadSurface->setSource(source);
}
surfaces->push_back(quadSurface);
}else if(type == SurfaceType::CIRCLE_SURFACE){
QuadSurface * base = (QuadSurface*)getQuadSurface(xmlSettings);
CircleSurface * circleSurface = new CircleSurface(*base);
if(sourceName != "none" && source != 0){
circleSurface->setSource(source);
}
surfaces->push_back(circleSurface);
}else if(type == SurfaceType::GRID_WARP_SURFACE){
BaseSurface * gridWarpSurface = getGridWarpSurface(xmlSettings);
if(sourceName != "none" && source != 0){
@ -209,7 +216,8 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
// Save surface options
// For now only if quad surface
if(surface->getType() == SurfaceType::QUAD_SURFACE){
if (surface->getType() == SurfaceType::QUAD_SURFACE ||
surface->getType() == SurfaceType::CIRCLE_SURFACE) {
QuadSurface * qs = (QuadSurface *)surface;
if(!xmlSettings->tagExists("properties")){
xmlSettings->addTag("properties");
@ -227,13 +235,13 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->addValue("gridRows", gws->getGridRows());
xmlSettings->popTag();
}
xmlSettings->popTag(); // surface
}
xmlSettings->popTag(); // surfaces
} // for
xmlSettings->save(fileName);
}
@ -245,17 +253,17 @@ bool SettingsLoader::create(string fileName){
BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 1)){
xmlSettings->pushTag("vertex", 1);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f),
@ -277,14 +285,14 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords");
if(xmlSettings->tagExists("texCoord", 0)){
xmlSettings->pushTag("texCoord", 0);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("texCoord", 1)){
xmlSettings->pushTag("texCoord", 1);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f),
@ -308,16 +316,16 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
SurfaceType::TRIANGLE_SURFACE);
triangleSurface->setVertices(vertices);
triangleSurface->setTexCoords(texCoords);
return triangleSurface;
}
BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f),
@ -348,7 +356,7 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices
}
vector <ofVec2f> texCoords;
if(xmlSettings->tagExists("texCoords")){
@ -360,7 +368,7 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("texCoord", 1)){
xmlSettings->pushTag("texCoord", 1);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f),
@ -384,14 +392,14 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // texCoords
}
// Create and add quad surface
BaseSurface * quadSurface =
SurfaceFactory::instance()->createSurface(
SurfaceType::QUAD_SURFACE);
quadSurface->setVertices(vertices);
quadSurface->setTexCoords(texCoords);
// Read properties
// Only perspective warping for now
bool perspectiveWarping = false;
@ -402,18 +410,18 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
}
QuadSurface * qs = (QuadSurface *)quadSurface;
qs->setPerspectiveWarping(perspectiveWarping);
return quadSurface;
}
BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
int iv = 0;
while(xmlSettings->tagExists("vertex", iv)){
xmlSettings->pushTag("vertex", iv);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f),
@ -424,14 +432,14 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices
}
vector <ofVec2f> texCoords;
if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords");
int it = 0;
while(xmlSettings->tagExists("texCoord", it)){
xmlSettings->pushTag("texCoord", it);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f),
@ -442,7 +450,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // texCoords
}
// Read properties
// Only perspective warping for now
int gridCols = 0;
@ -453,7 +461,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
gridRows = xmlSettings->getValue("gridRows", 0);
xmlSettings->popTag(); // properties
}
// Create and add quad surface
BaseSurface * gridWarpSurface =
SurfaceFactory::instance()->createSurface(
@ -463,16 +471,16 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
((GridWarpSurface *)gridWarpSurface)->createGridMesh();
gridWarpSurface->setVertices(vertices);
gridWarpSurface->setTexCoords(texCoords);
return gridWarpSurface;
}
BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
unsigned int v = 0;
while(xmlSettings->tagExists("vertex", v)){
xmlSettings->pushTag("vertex", v);
@ -489,7 +497,7 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords");
unsigned int t = 0;
while(xmlSettings->tagExists("texCoord", t)){
xmlSettings->pushTag("texCoord", t);
@ -508,7 +516,7 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
SurfaceType::HEXAGON_SURFACE);
hexagonSurface->setVertices(vertices);
hexagonSurface->setTexCoords(texCoords);
return hexagonSurface;
}

3
src/Gui/Widgets/TextureEditorWidget.cpp

@ -149,7 +149,8 @@ void TextureEditorWidget::createJoints(){
if(surface->getType() == SurfaceType::TRIANGLE_SURFACE){
tc = texCoords;
}else if(surface->getType() == SurfaceType::QUAD_SURFACE){
}else if(surface->getType() == SurfaceType::QUAD_SURFACE ||
surface->getType() == SurfaceType::CIRCLE_SURFACE){
tc = texCoords;
}else if(surface->getType() == SurfaceType::HEXAGON_SURFACE){
tc = texCoords;

11
src/Info/Info.cpp

@ -13,15 +13,16 @@ Info::Info(){
" 3. Projection mapping mode\n"
" - Press <,> and <.> to select previous or next surface\n"
" - Press \"<\" and \">\" to select previous or next vertex\n"
" - Press <t> to add new triangle surface\n"
" - Press <q> to add new quad surface\n"
" - Press <p> to toggle perspective warping while quad surface selected\n"
" - Press <g> to add new grid surface\n"
" - Press <t> to add new Triangle surface\n"
" - Press <q> to add new Quad surface\n"
" - Press <r> to add a new ciRcle surface\n"
" - Press <p> to toggle Perspective warping while quad surface selected\n"
" - Press <g> to add new Grid surface\n"
" - Press <[> and <]> to remove or add columns to selected grid surface\n"
" - Press <{> and <}> to remove or add rows to selected grid surface\n"
" - Press <+> and <-> to scale surface up and down\n"
" - Press <9> and <0> to move selected surface one layer up or down\n"
" - Press <l> to hide/show layer panel\n"
" - Press <l> to hide/show Layer panel\n"
" - Press <BACKSPACE> to delete selection\n"
" - Press <SPACE> to play/pause the video\n"
" - Type <new> to clear composition\n"

305
src/Surfaces/CircleSurface.cpp

@ -0,0 +1,305 @@
//
// CircleSurface.cpp
// Copyright (c) 2017 Cristobal Mendoza
// http://cuppetellimendoza.com
#include "CircleSurface.h"
namespace ofx {
namespace piMapper {
CircleSurface::CircleSurface() : QuadSurface() {
setup();
}
CircleSurface::CircleSurface(QuadSurface &surface) {
setup();
setVertices(surface.getVertices());
setTexCoords(surface.getTexCoords());
setPerspectiveWarping(surface.getPerspectiveWarping());
}
CircleSurface::~CircleSurface() {}
void CircleSurface::setup() {
QuadSurface::setup();
setPerspectiveWarping(true);
lastSourceTextureId = UINT_MAX;
updateMask = true;
// maskIsReady = false;
// glESVertexShader = CIRCLE_SURFACE_STRINGIFY(
// attribute vec4 position;
// attribute vec4 color;
// attribute vec4 normal;
// attribute vec2 texcoord;
//
// uniform mat4 modelViewMatrix;
// uniform mat4 projectionMatrix;
// uniform sampler2D maskTex;
//
// varying vec4 colorVarying;
// varying vec2 texCoordVarying;
//
// void main() {
//
// //get our current vertex position so we can modify it
// vec4 pos = projectionMatrix*modelViewMatrix*position;
//
// gl_Position = pos;
// colorVarying = color;
// texCoordVarying = texcoord;
// }
// );
//
// glESFragmentShader = CIRCLE_SURFACE_STRINGIFY(
////#ifdef GL_ES
//// define default precision for float, vec, mat.
// precision highp float;
////#endif
//
// uniform sampler2D tex0;
// uniform sampler2D maskTex;
// uniform vec4 globalColor;
//
// varying vec2 texCoordVarying;
//
// void main (void)
// {
// vec2 pos = texCoordVarying;
// vec3 src = texture2D(tex0, pos).rgb;
// float mask = texture2D(maskTex, pos).r;
// gl_FragColor = vec4( src , mask);
// }
// );
//
// gl2FragmentShader = "#version 120\n #extension GL_ARB_texture_rectangle : enable\n";
// gl2FragmentShader += CIRCLE_SURFACE_STRINGIFY(
// uniform sampler2DRect tex0;
// uniform sampler2DRect maskTex;
//
// void main (void) {
// vec2 pos = gl_TexCoord[0].st;
//
// vec3 src = texture2DRect(tex0, pos).rgb;
// float mask = texture2DRect(maskTex, pos).r;
//
// gl_FragColor = vec4(src, mask);
// }
// );
//
//#ifdef TARGET_OPENGLES
// maskShader.setupShaderFromSource(GL_VERTEX_SHADER, glESVertexShader);
// maskShader.setupShaderFromSource(GL_FRAGMENT_SHADER, glESFragmentShader);
// maskShader.bindDefaults();
// maskShader.linkProgram();
//#else
// if (ofIsGLProgrammableRenderer()) {
//
// } else {
// maskShader.setupShaderFromSource(GL_FRAGMENT_SHADER, gl2FragmentShader);
// maskShader.linkProgram();
// }
//#endif
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f));
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f));
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f));
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f));
defaultTexCoords.push_back(t1);
defaultTexCoords.push_back(t2);
defaultTexCoords.push_back(t3);
defaultTexCoords.push_back(t4);
}
void CircleSurface::draw() {
ofEnableAlphaBlending();
if (source->getTexture() == 0)
{
return;
}
if (!source->getTexture()->isAllocated()){
return;
}
if (source != currentSource) { // Pointer comparison
// Create the mask here
setupTextures();
lastSourceTextureId = UINT_MAX;
currentSource = source;
}
// Save Normie state:
auto isNorm = ofGetUsingNormalizedTexCoords();
// If we get to this part of the function, the mask fbo
// should already be allocated and the mask texture created.
ofEnableNormalizedTexCoords();
// Get the texture from the source an store a copy
// of the source texture's id:
auto sourceTex = ofTexture(*(source->getTexture()));
auto sourceTexId = sourceTex.getTextureData().textureID;
// Draw the mask only if the sources are FBO's, videos,
// or if the last texture id was UINT_MAX (which means that
// the mask has not yet been draw).
// if (source->getType() == SOURCE_TYPE_FBO ||
// source->getType() == SOURCE_TYPE_VIDEO ||
// lastSourceTextureId == UINT_MAX) {
if (true) {
lastSourceTextureId = sourceTexId;
drawMaskForSource(sourceTex);
}
// Swap the texture id of the source with the one of our
// newly drawn outputFbo:
source->getTexture()->getTextureData().textureID = outputFbo.getTexture().getTextureData().textureID;
auto texCoords = getMesh().getTexCoords();
getMesh().clearTexCoords();
getMesh().addTexCoords(defaultTexCoords);
// Draw the Quad:
QuadSurface::draw();
// Reset the texture id of the source
source->getTexture()->getTextureData().textureID = lastSourceTextureId;
// Reset the texture coords of the QuadSurface mesh:
getMesh().clearTexCoords();
getMesh().addTexCoords(texCoords);
if (!isNorm) ofDisableNormalizedTexCoords();
}
void CircleSurface::setFeathering(float f) {
feathering = f;
updateMask = true;
}
void CircleSurface::drawMaskForSource(ofTexture &sourceTex) {
auto quadTexCoords = getMesh().getTexCoords();
maskMesh.clearTexCoords();
// Set the mesh's texture coords to the quads.
// This gets us the coordinates set in the TextureEditor
maskMesh.addTexCoords(quadTexCoords);
outputFbo.begin(true);
{
ofClear(0, 0, 0, 0);
ofEnableNormalizedTexCoords();
ofSetColor(255);
ofFill();
ofSetRectMode(OF_RECTMODE_CORNER);
//#ifdef TARGET_RASPBERRY_PI
sourceTex.bind();
maskMesh.draw();
sourceTex.unbind();
// Masking without shaders...
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
ofSetColor(255);
ofFill();
ofDisableNormalizedTexCoords();
maskFbo.draw(0, 0);
ofPopStyle();
//#else
// maskShader.begin();
// maskShader.setUniformTexture("maskTex", maskFbo.getTexture(), 1);
// ofSetColor(255);
// ofFill();
// ofSetRectMode(OF_RECTMODE_CORNER);
// scaledSourceFbo.getTexture().bind();
// maskMesh.draw();
// scaledSourceFbo.getTexture().unbind();
// maskShader.end();
//#endif
}
outputFbo.end();
}
void CircleSurface::setupTextures() {
float w = source->getTexture()->getWidth();
float h = source->getTexture()->getHeight();
float dia = 0;
if (w > h) {
dia = h;
} else {
dia = w;
}
float padding = 10;
maskFbo.allocate(w, h);
maskFbo.begin(false);
ofPushStyle();
ofSetupScreenOrtho(w, h, -1, 1);
ofClear(0, 0, 0, 255);
ofFill();
ofSetColor(255);
ofSetCircleResolution(300);
ofDrawEllipse(w/2, h/2, w-padding, h-padding);
ofPopStyle();
maskFbo.end();
outputFbo.allocate(w, h);
outputFbo.begin();
ofClear(0, 0, 0, 255);
outputFbo.end();
// scaledSourceFbo.allocate(w, h);
// scaledSourceFbo.begin();
// ofClear(0, 0, 0, 255);
// scaledSourceFbo.end();
// This is lifted from QuadSurface::setup to ensure that the two
// meshes are similar:
// Create 4 points for the 2 triangles
ofVec2f p1 = ofVec2f(0, 0);
ofVec2f p2 = ofVec2f(0, h);
ofVec2f p3 = ofVec2f(w, h);
ofVec2f p4 = ofVec2f(w, 0);
// Create 4 point for the texture coordinates
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 1.0f));
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 1.0f));
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 0.0f));
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 0.0f));
// Clear maskMesh
maskMesh.clear();
// Create a surface with the points
maskMesh.addVertex(p1);
maskMesh.addVertex(p2);
maskMesh.addVertex(p3);
maskMesh.addVertex(p4);
// Add 2 triangles
maskMesh.addTriangle(0, 2, 3);
maskMesh.addTriangle(0, 1, 2);
// Add texture coordinates
maskMesh.addTexCoord(t1);
maskMesh.addTexCoord(t2);
maskMesh.addTexCoord(t3);
maskMesh.addTexCoord(t4);
}
int CircleSurface::getType() {
return SurfaceType::CIRCLE_SURFACE;
}
}
}

64
src/Surfaces/CircleSurface.h

@ -0,0 +1,64 @@
//
// CircleSurface.h
// Copyright (c) 2017 Cristobal Mendoza
// http://cuppetellimendoza.com
#ifndef OFXPIMAPPER_CIRCLESURFACE_H
#define OFXPIMAPPER_CIRCLESURFACE_H
#include "QuadSurface.h"
#define CIRCLE_SURFACE_STRINGIFY(A) #A
namespace ofx {
namespace piMapper {
class CircleSurface : public QuadSurface {
public:
CircleSurface();
CircleSurface(QuadSurface &surface);
int getType() override;
~CircleSurface();
void draw() override;
void setup() override;
// TODO: Feathering
void setFeathering(float f);
protected:
void setupTextures();
void drawMaskForSource(ofTexture &sourceTexture);
ofFbo maskFbo;
// ofFbo scaledSourceFbo;
ofFbo outputFbo;
// ofShader maskShader;
float feathering = 0.0f;
bool updateMask;
bool maskIsReady;
// string glESFragmentShader;
// string glESVertexShader;
//
// string gl2FragmentShader;
// string gl2VertexShader;
ofMesh maskMesh;
// TODO: gl3 Shaders
// string gl3VertexShader;
// string gl3FragmentShader;
private:
std::vector<ofVec2f> defaultTexCoords;
// We will use this pointer to determine if the source has changed.
// This is a total kludge, but it keeps me from messing with the
// upstream source.
BaseSource* currentSource = 0;
unsigned int lastSourceTextureId;
};
}
}
#endif //OFXPIMAPPER_CIRCLESURFACE_H

7
src/Surfaces/SurfaceFactory.cpp

@ -21,6 +21,8 @@ BaseSurface * SurfaceFactory::createSurface(SurfaceType type){
return createGridWarpSurface();
}else if(type == SurfaceType::HEXAGON_SURFACE){
return createHexagonSurface();
}else if(type == SurfaceType::CIRCLE_SURFACE){
return createCircleSurface();
}else{
throw runtime_error("Undefined surface type");
}
@ -83,5 +85,10 @@ HexagonSurface * SurfaceFactory::createHexagonSurface(){
return hexagonSurface;
}
CircleSurface * SurfaceFactory::createCircleSurface() {
CircleSurface * circleSurface = new CircleSurface();
return circleSurface;
}
} // namespace piMapper
} // namespace ofx

2
src/Surfaces/SurfaceFactory.h

@ -7,6 +7,7 @@
#include "QuadSurface.h"
#include "GridWarpSurface.h"
#include "HexagonSurface.h"
#include "CircleSurface.h"
namespace ofx {
namespace piMapper {
@ -26,6 +27,7 @@ class SurfaceFactory {
QuadSurface * createQuadSurface();
GridWarpSurface * createGridWarpSurface();
HexagonSurface * createHexagonSurface();
CircleSurface* createCircleSurface();
};
} // namespace piMapper

3
src/Surfaces/SurfaceType.h

@ -8,7 +8,8 @@ enum SurfaceType{
QUAD_SURFACE,
GRID_WARP_SURFACE,
HEXAGON_SURFACE,
NONE
NONE,
CIRCLE_SURFACE
};
} // namespace piMapper

Loading…
Cancel
Save