Created
April 24, 2011 06:09
-
-
Save sansumbrella/939368 to your computer and use it in GitHub Desktop.
Basic IOS Utilities for Cinder
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
// normal TextLayout code | |
TextLayout layout; | |
layout.clear( ColorA( CM_HSV, 0.0f, 0.0f, 0.0f, 0.0f ) ); | |
layout.setFont( mDateFont ); | |
layout.setColor( ColorA( CM_HSV, 0.0f, 0.0f, 1.0f, 1.0f ) ); | |
layout.setLeadingOffset( 4.0f ); | |
// write some | |
layout.addLine( "Some Text" ); | |
layout.addLine( "Some more text." ); | |
// render with alpha, per usual | |
Surface render = layout.render( true ); | |
// create a square surface to play nice with openGL (this uses our new function) | |
Surface output( IOSUtils::textBox( render ) ); | |
// turn it into a texture | |
mDateTexture = gl::Texture( 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
// | |
// Utilities.hpp | |
// WaterController | |
// | |
// Created by David Wicks on 4/9/11. | |
// Copyright 2011 __MyCompanyName__. All rights reserved. | |
// | |
#pragma once | |
#include "cinder/Vector.h" | |
#include "cinder/Surface.h" | |
namespace sansumbrella | |
{ | |
struct IOSUtils | |
{ | |
static ci::Vec2f screenify( const ci::Vec2f& in ) | |
{ | |
return ci::Vec2f( 1024.0f - in.y, in.x ); | |
} | |
static ci::Surface textBox( const ci::Surface in ) | |
{ | |
int maxDimension = in.getWidth() > in.getHeight() ? in.getWidth() : in.getHeight(); | |
// create a transparent texture | |
ci::Surface s( maxDimension, maxDimension, true ); | |
ci::Surface::Iter iter = s.getIter(); | |
// make sure it's transparent | |
while( iter.line() ) { while( iter.pixel() ) { iter.a() = 0; } } | |
s.copyFrom( in, s.getBounds() ); | |
return s; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment