Skip to content

Instantly share code, notes, and snippets.

@simongeilfus
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongeilfus/ed4d80220e5764142b4f to your computer and use it in GitHub Desktop.
Save simongeilfus/ed4d80220e5764142b4f to your computer and use it in GitHub Desktop.
glNext Framerate/Borderless/Multiwindow
#include "cinder/app/AppNative.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/TextureFont.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class CinderProjectApp : public AppNative {
public:
void setup() override;
void keyDown( KeyEvent event ) override;
void draw() override;
gl::TextureFontRef mTexFont;
};
void CinderProjectApp::setup()
{
disableFrameRate();
mTexFont = gl::TextureFont::create( Font( "Helvetica", 12 ) );
getWindow()->setTitle( "Window_" + to_string( getNumWindows() ) );
}
void CinderProjectApp::keyDown( KeyEvent event )
{
size_t windows = getNumWindows();
switch ( event.getCode() ) {
case KeyEvent::KEY_a:
if( !event.isShiftDown() ){
createWindow()->setTitle( "Window_" + to_string( getNumWindows() ) );
}
else {
auto x = getDisplay()->getWidth() / getWindowWidth();
for( int i = 0; i < 10; i++ ){
auto w = createWindow();
w->setPos( vec2( i % x, i / x ) * vec2( getWindowSize() ) );
w->setTitle( "Window_" + to_string( getNumWindows() ) );
}
}
break;
case KeyEvent::KEY_b:
for( size_t window = 0; window < windows; window ++ ){
auto w = getWindowIndex( window );
w->setBorderless( !w->isBorderless() );
}
break;
case KeyEvent::KEY_f:
for( size_t window = 0; window < windows; window ++ ){
auto w = getWindowIndex( window );
w->setFullScreen( !w->isFullScreen() );
}
break;
case KeyEvent::KEY_h:
for( size_t window = 1; window < windows; window ++ ){
auto w = getWindowIndex( window );
if( w->isHidden() ) w->show();
else w->hide();
}
break;
}
}
void CinderProjectApp::draw()
{
gl::clear( Color( 0, 0, 0 ) );
if( gl::isVerticalSyncEnabled() ) gl::enableVerticalSync( false );
gl::enableAlphaBlending( mTexFont->isPremultiplied() );
mTexFont->drawString( to_string( (int) getAverageFps() ), vec2( 10, 20 ) );
}
CINDER_APP_NATIVE( CinderProjectApp, RendererGl( RendererGl::Options().msaa(0) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment