Esempio n. 1
0
void App::init()
{
    // Check if main instance already exists
    if (App::main_instance_)
    {
        throw Error ("Cannot create multiple apps at once.");
    }

    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        throw Error ("Could not initialize SDL.");
    }

    // Allow app to modify config
    Window::Config config;
    onInit(config);

    // Create new window with config
    window_ = std::make_unique<Window>(config);
    asset_manager_ = std::make_unique<AssetManager>();

    // Initialize GLEW with created window context
    glewExperimental = true;
    if (glewInit() != GLEW_OK)
    {
        throw Error ("Failed to init GLEW.");
    }

    // Flush errors caused by GLEW
    while (glGetError());

    App::main_instance_ = this;
    should_quit_ = false;
}
Esempio n. 2
0
bool ArticulatedViewer::onEvent(const GEvent& e, App* app) {
    if ((e.type == GEventType::MOUSE_BUTTON_DOWN) && (e.button.button == 0) && ! app->userInput->keyDown(GKey::LCTRL)) {
        // Intersect all tri lists with the ray from the camera
        const Ray& ray = app->activeCamera()->worldRay(e.button.x, e.button.y, 
            app->renderDevice->viewport());

        m_selectedPart = NULL;
        m_selectedMesh = NULL;
        m_selectedTriangleIndex = -1;
        Model::HitInfo hitInfo;
        float distance = finf();
        const bool hit = m_model->intersect(ray, m_offset, ArticulatedModel::defaultPose(), distance, hitInfo);

        if (hit) {
//            shared_ptr<ArticulatedModel> model = dynamic_pointer_cast<ArticulatedModel>(hitInfo.model);
//            alwaysAssertM(notNull(model), "Not a model!");
            m_selectedMesh = m_model->mesh(hitInfo.meshID);
            m_selectedTriangleIndex = hitInfo.primitiveIndex;
        }

        if (notNull(m_selectedMesh)) {
            m_selectedPart = m_selectedMesh->logicalPart;
        }
        return hit;
    } else if ((e.type == GEventType::KEY_DOWN) && (e.key.keysym.sym == 'r')) {
        onInit(m_filename);
        return true;
    }

    return false;
}
    void Core::init(int width, int height) {
        if (0 != SDL_Init(SDL_INIT_VIDEO)) {
            //fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
            Error::getInstance().fail(ErrorCodes::UNKNOWN);
        }
        
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
        
        m_camera.init(width, height);
        
        //_entityManager->getSystemManager()->addSystem<PhysicsSystem>(Component::getComponentBitmask<PositionComponent, PhysicsComponent, CollisionComponent>())->init();
        
        _entityManager->getSystemManager()->addSystem<RenderSystem>(Component::getComponentBitmask<TextureComponent, PositionComponent>())->init(&m_camera);
        
//        _entityManager->getSystemManager();
        
        onInit();
        
        loop();
    }
Esempio n. 4
0
  int AppBase::run()
  {
    if (!onInit()) {
      return -1;
    }

    frame_timer.reset();
    // game main loop begin .
    SDL_Event evnt;
    leave_main_loop = false;
    while (!leave_main_loop) {
      if (SDL_PollEvent(&evnt)) {
        processGlobalEvent(evnt);
        if (onEvent(evnt) == false) {
          processUnhandleEvent(evnt);
        }
      }

      if (!leave_main_loop) {
        onUpdate();
        onRender();
      }

      frame_timer.update();
    }

    onExit();
    return 0;
  }
Esempio n. 5
0
  void Process::initWorker()
  {
    log_debug("init worker");

    log_debug("onInit");
    onInit();

    if (!tnt::TntConfig::it().group.empty())
    {
      log_debug("set group to \"" << tnt::TntConfig::it().group << '"');
      ::setGroup(tnt::TntConfig::it().group);
    }

    if (!tnt::TntConfig::it().user.empty())
    {
      log_debug("set user to \"" << tnt::TntConfig::it().user << '"');
      ::setUser(tnt::TntConfig::it().user);
    }

    if (!tnt::TntConfig::it().dir.empty())
    {
      log_debug("set dir to \"" << tnt::TntConfig::it().dir << '"');
      ::setDir(tnt::TntConfig::it().dir);
    }

    if (!tnt::TntConfig::it().chrootdir.empty())
    {
      log_debug("change root to \"" << tnt::TntConfig::it().chrootdir << '"');
      ::setRootdir(tnt::TntConfig::it().chrootdir);
    }

    signal(SIGTERM, sigEnd);
    signal(SIGINT, sigEnd);
    signal(SIGHUP, sigReload);
  }
Esempio n. 6
0
int CDotWars::onExecute()
{
	currentTime = SDL_GetTicks();
	if(onInit() == false) {
        return -1;
    }

	a.setColor(0, 0, 0xff);
	a.setPosition(50, 100);
	a.velocity.x = 0;
	a.velocity.y = 0;
	b.color = 0x00FF00FF;
	a.gravity = false;
	gravityOverlord.playerDot = &a;

	//da_overlord.mouseDot = &b;
    SDL_Event Event;
 
    while(running) {
        while(SDL_PollEvent(&Event)) {
            onEvent(&Event);
        }
 
        onLoop();
        onRender();
    }
 
    onCleanup();
 
    return 0;
}
bool
ICamDevice::
init()
{
    Mutex::Autolock lock(mMtxLock);
    return  onInit();
}
Esempio n. 8
0
pcl::OpenNIGrabber::OpenNIGrabber (const std::string& device_id, const Mode& depth_mode, const Mode& image_mode)
  : rgb_sync_ ()
  , ir_sync_ ()
  , device_ ()
  , rgb_frame_id_ ()
  , depth_frame_id_ ()
  , image_width_ ()
  , image_height_ ()
  , depth_width_ ()
  , depth_height_ ()
  , image_required_ (false)
  , depth_required_ (false)
  , ir_required_ (false)
  , sync_required_ (false)
  , image_signal_ (), depth_image_signal_ (), ir_image_signal_ (), image_depth_image_signal_ ()
  , ir_depth_image_signal_ (), point_cloud_signal_ (), point_cloud_i_signal_ ()
  , point_cloud_rgb_signal_ (), point_cloud_rgba_signal_ ()
  , config2xn_map_ (), depth_callback_handle (), image_callback_handle (), ir_callback_handle ()
  , running_ (false)
  , rgb_array_size_ (0)
  , depth_buffer_size_ (0)
  , rgb_focal_length_x_ (std::numeric_limits<double>::quiet_NaN ())
  , rgb_focal_length_y_ (std::numeric_limits<double>::quiet_NaN ())
  , rgb_principal_point_x_ (std::numeric_limits<double>::quiet_NaN ())
  , rgb_principal_point_y_ (std::numeric_limits<double>::quiet_NaN ())
  , depth_focal_length_x_ (std::numeric_limits<double>::quiet_NaN ())
  , depth_focal_length_y_ (std::numeric_limits<double>::quiet_NaN ())
  , depth_principal_point_x_ (std::numeric_limits<double>::quiet_NaN ())
  , depth_principal_point_y_ (std::numeric_limits<double>::quiet_NaN ())
{
  // initialize driver
  onInit (device_id, depth_mode, image_mode);

  if (!device_->hasDepthStream ())
    PCL_THROW_EXCEPTION (pcl::IOException, "Device does not provide 3D information.");

  depth_image_signal_    = createSignal<sig_cb_openni_depth_image> ();
  ir_image_signal_       = createSignal<sig_cb_openni_ir_image> ();
  point_cloud_signal_    = createSignal<sig_cb_openni_point_cloud> ();
  point_cloud_i_signal_  = createSignal<sig_cb_openni_point_cloud_i> ();
  ir_depth_image_signal_ = createSignal<sig_cb_openni_ir_depth_image> ();

  ir_sync_.addCallback (boost::bind (&OpenNIGrabber::irDepthImageCallback, this, _1, _2));
  if (device_->hasImageStream ())
  {
    // create callback signals
    image_signal_             = createSignal<sig_cb_openni_image> ();
    image_depth_image_signal_ = createSignal<sig_cb_openni_image_depth_image> ();
    point_cloud_rgb_signal_   = createSignal<sig_cb_openni_point_cloud_rgb> ();
    point_cloud_rgba_signal_  = createSignal<sig_cb_openni_point_cloud_rgba> ();
    rgb_sync_.addCallback (boost::bind (&OpenNIGrabber::imageDepthImageCallback, this, _1, _2));
    openni_wrapper::DeviceKinect* kinect = dynamic_cast<openni_wrapper::DeviceKinect*> (device_.get ());
    if (kinect)
      kinect->setDebayeringMethod (openni_wrapper::ImageBayerGRBG::EdgeAware);
  }

  image_callback_handle = device_->registerImageCallback (&OpenNIGrabber::imageCallback, *this);
  depth_callback_handle = device_->registerDepthCallback (&OpenNIGrabber::depthCallback, *this);
  ir_callback_handle    = device_->registerIRCallback (&OpenNIGrabber::irCallback, *this);
}
INT_PTR CALLBACK dlgRen_msgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    INT_PTR status = FALSE;

    if (uMessage == WM_COMMAND) {
        switch (LOWORD(wParam)) {

            case IDOK:
                if (onOk(hDlg)) {
                    ::EndDialog(hDlg, 1);
                    status = TRUE;
                }
                break;

            case IDCANCEL:
                ::EndDialog(hDlg, 0);
                status = TRUE;
                break;
        }
    }
    else if (uMessage == WM_INITDIALOG) {
        _dialogData = (ChildDialogData*)lParam;
        onInit(hDlg);
    }

    return status;
}
Esempio n. 10
0
int main(int argc, char **argv)
{
	// inicializace knihovny GLUT
	glutInit(&argc, argv);
	
	// inicializaci parametru programu
	onInit();
	
	// nastaveni grafickeho modu okna programu
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
	// nastaveni pocatecnich rozmeru okna programu
	glutInitWindowSize(default_frame_w, default_frame_h);
	// vytvoreni hlavniho okna pogramu
	glutCreateWindow(PROGRAM_TITLE);
	
	// registrace fukce zajistujici prekresleni obsahu okna programu
	glutDisplayFunc(onDisplay);
	// registrace funkce reagujici na zmenu rozmeru okna programu
	glutReshapeFunc(onResize);
	// registrace funkce reagujici na stisknuti klavesnice
	glutKeyboardFunc(onKeyboard);
	// registrace funkce reagujici na stisknuti tlacitka mysi
	glutMouseFunc(onMouseClick);
	// registrace funkce reagujici na pohyb mysi
	glutMotionFunc(onMouseMotion);
	
	// nekonecna smycka volajici registrovane funkce
	glutMainLoop();
	
	return 0;
}
Esempio n. 11
0
//--------------------------------------------------------------------------
// Main global function
//--------------------------------------------------------------------------
S3E_MAIN_DECL void IwMain()
{
#ifdef EXAMPLE_DEBUG_ONLY
	// Test for Debug only examples
#endif
	onInit();
	while (1)
	{
		s3eDeviceYield(0);
		s3eKeyboardUpdate();
		bool result = onUpdate();
		if (
			(result == false) ||
			(s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN)
			||
			(s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN)
			||
			(s3eDeviceCheckQuitRequest())
			) {
			break;
		}
		onRender();
		s3eSurfaceShow();
	}
	onShutDown();
}
Esempio n. 12
0
void State::
init()
{
    Command* initCommand = onInit();
    if (0 != initCommand) {
        initCommand->execute();
    }
}
Esempio n. 13
0
World::World(GraphicsManager *gm) : grMananger(gm) {
    objects.push_back(Entity{grMananger->getBuffer(ObjectType::Cube),
                             grMananger->getShader(ShaderType::Standard),
                             grMananger,
                             0, 0, 0,
                             TextureType::Dice});
    onInit();
}
Esempio n. 14
0
void APIMod::init(CharString file){ // , CharString name, CharString language, CharString version
    this->file = file;
    loadProperties();


    onInit();
    inited=true;
}
Esempio n. 15
0
VoiceMessages::VoiceMessages() : _current(0),
_fader(new VoiceMessagesFader(&_faderThread)), _loader(new VoiceMessagesLoader(&_loaderThread)) {
	connect(this, SIGNAL(faderOnTimer()), _fader, SLOT(onTimer()));
	connect(this, SIGNAL(loaderOnStart(AudioData*)), _loader, SLOT(onStart(AudioData*)));
	connect(this, SIGNAL(loaderOnCancel(AudioData*)), _loader, SLOT(onCancel(AudioData*)));
	connect(&_faderThread, SIGNAL(started()), _fader, SLOT(onInit()));
	connect(&_loaderThread, SIGNAL(started()), _loader, SLOT(onInit()));
	connect(&_faderThread, SIGNAL(finished()), _fader, SLOT(deleteLater()));
	connect(&_loaderThread, SIGNAL(finished()), _loader, SLOT(deleteLater()));
	connect(_loader, SIGNAL(needToCheck()), _fader, SLOT(onTimer()));
	connect(_loader, SIGNAL(error(AudioData*)), this, SLOT(onError(AudioData*)));
	connect(_fader, SIGNAL(needToPreload(AudioData*)), _loader, SLOT(onLoad(AudioData*)));
	connect(_fader, SIGNAL(playPositionUpdated(AudioData*)), this, SIGNAL(updated(AudioData*)));
	connect(_fader, SIGNAL(audioStopped(AudioData*)), this, SIGNAL(stopped(AudioData*)));
	connect(_fader, SIGNAL(error(AudioData*)), this, SLOT(onError(AudioData*)));
	_loaderThread.start();
	_faderThread.start();
}
 void Solid::onChangeParent(Kernel::Object*)
 {
   InternalMessage("Physic","Ode::Solid::onChangeParent entering " +
                             Kernel::toString(getObject()->getIdentifier())) ;
   onClose() ;
   onInit() ;
   InternalMessage("Physic","Ode::Solid::onChangeParent leaving " +
                             Kernel::toString(getObject()->getIdentifier())) ;
 }
Esempio n. 17
0
bool CPPModule::init(const std::string& jsonParams) {
	JSONNode n = libjson::parse(jsonParams);
	std::map<std::string, std::string> tmpParams;
	JSONNode::iterator i = n.begin();
	for(; i!=n.end(); ++i) {
		tmpParams[(*i).name()] = (*i).as_string();
	}
	return onInit(tmpParams);
}
Esempio n. 18
0
void GuiComponent::init()
{
	onInit();

	for(unsigned int i = 0; i < mChildren.size(); i++)
	{
		mChildren.at(i)->init();
	}
}
Esempio n. 19
0
Font::Font(std::string path, int size)
{
	//register to receive init/deinit callbacks
	Renderer::registerComponent(this);

	mPath = path;
	mSize = size;

	onInit();
}
Esempio n. 20
0
 /// Constructor.
 CobFiducialsNode(ros::NodeHandle& nh)
     : sub_counter_(0),
       endless_counter_(0),
       color_image_8U3_(0)
 {
     camera_matrix_initialized_ = false;
     /// Void
     node_handle_ = nh;
     onInit();
 }
Esempio n. 21
0
/**
 * Creates a new drawer, and makes the graph with all the data needed
 * @param bhg BBHG to print
 * @param props properties to apply to all the items of the graph
 * (the Graph itself, Nodes, and Edges)
 * @param driver Driver to use to create the graph. The default is graphviz_driver
 */
BBHGDrawer::BBHGDrawer(BBHG *bhg, const PropList& props, display::Driver& driver): _made(false) {
    PropList general, nodes, edges;
    general.addProps(props);
    nodes.addProps(props);
    edges.addProps(props);
    onInit(general, nodes, edges);

    _graph = driver.newGraph(general, nodes, edges);

    _bhg = bhg;
}
Esempio n. 22
0
void MainWindow::onStart()
{
    if (!task_)
    {
        task_ = new DownloadTask(this);
        connect(task_, SIGNAL(inited()), this, SLOT(onInit()));
        connect(task_, SIGNAL(downloadProgress(qint64, qint64, qint64)), this, SLOT(onDownloadProgress(qint64, qint64, qint64)));
        connect(task_, SIGNAL(finished()), this, SLOT(onFinished()));
        task_->init("", "http://ermaopcassist.qiniudn.com/ErmaoPcAssist2.0.0.2.exe", &mgr_);
    }
    task_->start();
}
Esempio n. 23
0
struct basic_epoll_event *http_server::onWriteDone()
{
    if (!persistent)
        return this->close();
    else
    {
        // TCP_CORK is needed only when not closing the socket
        int option = 0;
        if (0 > setsockopt(fd, IPPROTO_TCP, TCP_CORK, &option, sizeof(option)))
            LOGGER_PERROR_STR("TCP_CORK release");
        return onInit();
    }
}
Esempio n. 24
0
bool NoobaPlugin::init()
{
    // TODO: Need to load previous configurations from QSettings
    qDebug() << _alias << " about to initialise " << Q_FUNC_INFO;
    initSignalSlots();
    bool ok =  _api->init();
    if(!ok)
        qDebug() << tr("plugin: '%1' initialisation failed!").arg(_alias) << Q_FUNC_INFO;
    else
        qDebug() << _alias << " initialised successfully " << Q_FUNC_INFO;
    emit onInit(this);
    return ok;
}
Esempio n. 25
0
    void App::init()
    {
        /* Check if main instance already exists */
        if (App::main_instance_)
        {
            throw Error ("Cannot create multiple apps at once.");
        }

        /* Initialize SDL */
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            throw Error ("Could not initialize SDL.");
        }

        /* Allow app to modify config */
        Window::Config config;
        onInit(config);

        /* Create new window with config */
        window_ = std::make_unique<Window>(config);

        /* Initialize GLEW with created window context */
        glewExperimental = true;
        if (glewInit() != GLEW_OK)
        {
            throw Error ("Failed to init GLEW.");
        }

        /* Flush errors caused by GLEW */
        while (glGetError());

        /* Initialize controllers */
        keyboard_   = std::make_unique<Keyboard>();
        mouse_      = std::make_unique<Mouse>();

        /* Register SDL event handlers */
        addEventHandler(getWindow());
        addEventHandler(getKeyboard());
        addEventHandler(getMouse());

        scene_ = std::make_unique<Scene>();

        renderer_ = std::make_unique<Renderer>(
                window_->getWidth(),
                window_->getHeight());

        App::main_instance_ = this;
        should_quit_ = false;
        
        onPostInit();
    }
Esempio n. 26
0
////////////////////////////////////////////////////////////////////////
/// Function:		Preload
/// Description:	Sets up the function pointers from the core,
///					maintains a module count and calls onInit() when called for the first time
/// Returns:		An enumeration type defined in PBPlugin.h
/// Author:			Paul Henderson
/// Date:			May 2009
////////////////////////////////////////////////////////////////////////
BOOL PBModule::Preload(PPBSTRUCT pPBStructure, PPBCORESTRUCT pPBCoreStructure)
{
	m_pCoreStructure = pPBCoreStructure;
	m_pCurrentPBstruct = pPBStructure;

	++m_iLoadCount;
		
	PPBINSTSTRUCT pInstStruct = new PBInstStruct;
	if(pInstStruct == NULL){
		Log(PB_LOG_ERROR,L"Mem allocation",L"Preload",__LINE__);
		return FALSE;
	}
	pInstStruct->instID			= pPBStructure->iTabID;
	pInstStruct->pWrappedObj	= NULL;
	pInstStruct->pNext			= NULL;

	if(m_pInstHead == NULL){
		pPBCoreStructure->pLoggingFunc(PB_LOG_INFO,L"First call",L"Preload",__LINE__,m_szModName);
		m_pInstHead = pInstStruct;
		if(!onInit(pPBStructure)){	///>let the derived class know about it by calling it's onInit()
			pPBCoreStructure->pLoggingFunc(PB_LOG_ERROR,L"Failed to initialise in the derived object",L"Preload",__LINE__,m_szModName);///>log error
			return FALSE;
		}
	
	}
	
	else{
		/**
		*		
		*	go through the linked list and look for a match
		*/
		PPBINSTSTRUCT pInst;
		for(pInst = m_pInstHead;pInst->pNext;pInst = pInstStruct->pNext)
		{
			if(pInst->instID == pPBStructure->iTabID){
				pPBCoreStructure->pLoggingFunc(PB_LOG_ERROR,L"Preload called twice same instance",L"Preload",__LINE__,m_szModName);
				delete pInstStruct;
				return FALSE;
			}
		}
		pInst->pNext = pInstStruct;
	}
	
	
	if(!onAttachInstance(pPBStructure,pInstStruct)){///>let the derived object know about a new PB app instance
		Log(PB_LOG_ERROR,L"Failed onAttachInstance in the derived object",L"Preload",__LINE__);///>log error	
		return FALSE;				///>error the derived function has failed
	}
	
	return TRUE;
}
Esempio n. 27
0
//---------------------------------------------------------------------
// Hlavni funkce konzolove aplikace
//---------------------------------------------------------------------
int main(int argc, char **argv)
{
	glutInit(&argc, argv);                      // inicializace knihovny GLUT
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);// nastaveni dvou barvovych bufferu a pameti hloubky
	glutInitWindowPosition(30, 30);             // pocatecni pozice leveho horniho rohu okna
	glutInitWindowSize(600, 600);               // pocatecni velikost okna
	glutCreateWindow("inpg3 - semestrálka, zadání èíslo 3.");// vytvoreni okna pro kresleni
	glutDisplayFunc(onDisplay);                 // registrace funkce volane pri prekreslovani okna
	glutReshapeFunc(onResize);                  // registrace funkce volane pri zmene velikosti okna
	glutKeyboardFunc(onKeyboard);               // registrace funkce volane pri stlaceni klavesy
	onInit();                                   // inicializace vykreslovani
	glutMainLoop();                             // nekonecna smycka, kde se volaji zaregistrovane funkce
	return 0;                                   // navratova hodnota vracena operacnimu systemu
}
Esempio n. 28
0
int Core::onExecute()
{
   if(onInit() == false)
      return -1;

   SDL_Event event;

   //seed random
   srand(time(0));
  
   //For controlling framerate
   int dt_frame = 0;
   int dt_current = 0;
   int dt_previous = 0;
 
   while(running_)
   {
      //Process events
      while(SDL_PollEvent(&event))
      {
         //Quit game event
         if(event.type == SDL_QUIT)
         {
            running_ = false;
         }
         //Process game events
         pGame_->onEvent(&event);
      }
      
      //Regulate framerate;
      dt_previous = dt_current;
      dt_current = pDelta_->getTicks();
      dt_frame = dt_current - dt_previous;
      if(dt_frame < (FRAME_RATE))
      {
         SDL_Delay(FRAME_RATE - dt_frame);
      }
      
      //Process game loop
      pGame_->onLoop(pDelta_->getTicks());
      //Render game world
      pGame_->onRender();
      //Swap buffers
      SDL_GL_SwapBuffers();
   }
   
   onCleanup();
   
   return 0;
}//End onExecute()
 void BaseTraitView::_init()
 {
   /*!
     We initialise only if the view point has been initialised.
   */
   if (m_viewpoint)
   {
     if (! m_initialised && m_viewpoint->isInitialised())
     {
       onInit() ;
       m_initialised = true ;        
     }
   }
 }
Esempio n. 30
0
//------------------------------------------------------------------------------
// Main game loop inside the onExecute() method
//------------------------------------------------------------------------------
int Client::onExecute() {
    if(onInit() == false) {
        return -1;
    }

    SDL_Event event;
	Uint32 fps = 60;
	Uint32 frametime = 1000 / fps;
	Uint32 starttime, exectime;

    while(running) {
		starttime = SDL_GetTicks();

		// start by checking for OpenGL error
		GLenum error;
		while ((error = glGetError()) != GL_NO_ERROR) {
			printf("Error: %s\n", gluErrorString(error));
		}

		// check for input events
        while(SDL_PollEvent(&event)) {
            onEvent(&event);
        }

		// act on input events
        onInput();

		// TODO more game state updates here,
		// like applying velocity, gravity, etc
		p1->onUpdate();
		if (follow) {
			setXView(p1->getX());
			setYView(p1->getY());
		}

		// draw the screen
        onRender();

		// sleep time to make fps
		exectime = SDL_GetTicks() - starttime;
		if (exectime < frametime) {
			//SDL_Delay(SDL_GetTicks() % frametime);
			SDL_Delay(frametime - exectime);
		}
    }

    onCleanup();

    return 0;
}