Created
June 23, 2010 17:47
-
-
Save sansumbrella/450273 to your computer and use it in GitHub Desktop.
Sample WrittenImages TinderBox Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/AppBasic.h" | |
#include "cinder/params/Params.h" | |
#include "cinder/ImageIo.h" | |
#include "cinder/gl/TileRender.h" | |
#include "cinder/Utilities.h" | |
#include "cinder/Rand.h" | |
#include <vector> | |
using namespace ci; | |
using namespace ci::app; | |
using namespace std; | |
class SampleApp : public AppBasic { | |
public: | |
void prepareSettings(Settings *settings); | |
void launch( const char *title, int argc, char * const argv[] ); | |
void setup(); | |
void update(); | |
void draw(); | |
void renderTiles( string toFile ); | |
void simulateSketch(); | |
void shutdown(); | |
void keyDown( KeyEvent event ); | |
void mouseDown( MouseEvent event ); | |
void mouseUp( MouseEvent event ); | |
void mouseDrag( MouseEvent event ); | |
void fileDrop( FileDropEvent event ); | |
private: | |
params::InterfaceGl mParams; | |
Color mBackgroundColor; | |
bool mDrawingTiles; | |
bool mDoBatchRender; | |
vector<string> mFilenames; | |
}; | |
void SampleApp::launch( const char *title, int argc, char * const argv[] ) | |
{ | |
// providing filename arguments at launch will set mDoBatchRender to true | |
// setting to true without passing args will batch render the default filenames | |
mDoBatchRender = false; | |
for ( int i=1; i != argc; ++i ) | |
{ | |
string arg = argv[i]; | |
// ignore strange args from osx open command | |
if( arg.find("-psn_") == 0 ) | |
{ | |
continue; | |
} | |
mFilenames.push_back( arg ); | |
} | |
if( mFilenames.size() != 0 ) | |
{ | |
// we received args, just render to those paths | |
mDoBatchRender = true; | |
} else | |
{ | |
// create some default filenames for testing | |
string dir = getHomeDirectory() + "cinder" + getPathSeparator() + "writtenImages" + getPathSeparator() + "Sample" + getPathSeparator(); | |
for( int i=1; i != 5; ++i ) | |
{ | |
mFilenames.push_back( dir + toString<int>(i) + ".png" ); | |
} | |
} | |
// launch the app normally | |
AppBasic::launch( title, argc, argv ); | |
} | |
void SampleApp::prepareSettings(Settings *settings) | |
{ | |
// make the app fit on screen | |
// but proportional to the final printed size | |
settings->setWindowSize( 4080/4, 2720/4 ); | |
settings->setTitle("Sample"); | |
} | |
void SampleApp::setup() | |
{ | |
mDrawingTiles = false; | |
// I generally find having one of these useful | |
mParams = params::InterfaceGl( "Settings", Vec2i( 200, 400 ) ); | |
mParams.addParam( "Background color", &mBackgroundColor ); | |
if( mDoBatchRender ) | |
{ | |
Rand::randomize(); | |
// save an image to each supplied path | |
for ( vector<string>::iterator file = mFilenames.begin(); file != mFilenames.end(); ++file) | |
{ | |
simulateSketch(); | |
renderTiles( *file ); | |
} | |
quit(); | |
} | |
} | |
void SampleApp::simulateSketch() | |
{ | |
// perhaps loop through a series of updates, perhaps not | |
// maybe apply some input that acts like your mouse did | |
// you could reset your application to a blank slate, | |
// or pile versions on top of each other | |
// we'll just set the background to a random cool hue | |
mBackgroundColor = Color( CM_HSV, Rand::randFloat( 0.4f, 0.65f ), 0.8f, 0.7f ); | |
} | |
void SampleApp::update() | |
{ | |
} | |
void SampleApp::draw() | |
{ | |
// clear the background | |
gl::clear(mBackgroundColor); | |
if( mDrawingTiles ) | |
{ // anything special you might need to do for the tiles | |
// maybe adjust texCoords, not sure | |
} | |
// draw your stuff | |
if( !mDrawingTiles ) | |
{ // draw interface and things you don't want in your final print | |
params::InterfaceGl::draw(); | |
} | |
} | |
void SampleApp::renderTiles( string toFile ) | |
{ | |
//4080 x 2720 px image | |
gl::TileRender tr( 4080, 2720 ); | |
tr.setMatricesWindow(getWindowWidth(), getWindowHeight()); | |
mDrawingTiles = true; | |
while( tr.nextTile() ) { | |
draw(); | |
} | |
mDrawingTiles = false; | |
writeImage( toFile, tr.getSurface() ); | |
gl::setMatricesWindow( getWindowWidth(), getWindowHeight(), true ); | |
} | |
//MouseEvents | |
void SampleApp::mouseDown( MouseEvent event ) | |
{ | |
} | |
void SampleApp::mouseUp( MouseEvent event ) | |
{ | |
} | |
void SampleApp::mouseDrag( MouseEvent event ) | |
{ | |
} | |
//KeyEvents | |
void SampleApp::keyDown( KeyEvent event ) | |
{ | |
switch( event.getChar() ){ | |
case ' ': | |
//renderTiles("../renders/quickgrab.png"); | |
renderTiles( mFilenames[0] ); | |
break; | |
default: | |
break; | |
} | |
} | |
void SampleApp::fileDrop( FileDropEvent event ) | |
{ | |
} | |
void SampleApp::shutdown() | |
{ | |
} | |
// This line tells Cinder to actually create the application | |
CINDER_APP_BASIC( SampleApp, RendererGl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment