Applications

The following functions form the base of your Cinder application:

  • setup()
  • update()
  • draw()

We use setup() for the preparation, update() for calculations in the run loop, and draw() for drawing on the screen. You can use the shutdown() method to do something (clear memory, store data, or communicate with remote server) before our application closes. Remember that your main Cinder application class should derive from the BaseApp class and that you should implement the methods in the class declaration first.

void YourApp::setup() {
  // setup goes here
}

void YourApp::update() {
  // prepare data
}

void YourApp::draw() {
  // draw
}
void YourApp::shutdown() {
  // do something before the app closes
}

If you want to change the initial window size or other initial parameters of the application, use the prepareSettings() method (do not forget to declare this method first):

void YourApp::prepareSettings( Settings * settings ) {
  settings->setWindowSize( 800, 600 ); // set window to 800x600 px
}

Then, there are a couple of useful functions that you can use during setup and runtime.

cinder::app::getWindowWidth()

The preceding function returns the application window width as an int value.

cinder::app::getWindowHeight()

The preceding function returns the application window height as an int value.

cinder::app::getWindowSize()

The preceding function returns the application window size as a Vec2i value.

cinder::app::getFrameRate()

Sometimes, it is necessary to know the current frame rate of the application. The preceding function returns it as a float value.

cinder::app::getElapsedSeconds()

The preceding function returns the number of seconds that have passed since the application has started as a double value.

cinder::app::getElapsedFrames()

The preceding function returns the number of frames that have elapsed since the start of the application as an int value.

console()

Use the preceding function for debugging, for example, console() << "debug text" << std::endl;.

isFullScreen()

The preceding function returns true, if the application is in the fullscreen mode, false if not.

setFullScreen( bool fullScreen )

The preceding code sets the fullscreen state by passing true or false.

To make these functions work, you have to import the AppBasic header file as follows:

#include "cinder/app/AppBasic.h"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.186.202