//------------------------------------
void ofxRemoteCameraClient::update(){
	updateFPS();
	if(!changeRequested){
		if(newData){
			lock();
			
			/*swapping buffers*/
			unsigned char *tmp=pixels;
			pixels=auxPixels;
			auxPixels=tmp;
			/******************/
			
			if(useTexture){
				if ( texture.getTextureData().glType != getGLCode(requestedImageType)){
					texture.clear();
					texture.allocate(camWidth,camHeight, getGLCode(requestedImageType));
				}
				texture.loadData((unsigned char*)pixels,requestedWidth,requestedHeight, getGLCode(requestedImageType));
			}
			frameNew=true;
			newData=false;
			unlock();
		}
		changeRequested=tmpImageType!=requestedImageType || compressionQuality!=tmpCompressionQuality || tmpW!=requestedWidth || requestedHeight!= tmpH;	
	}
}
Esempio n. 2
0
void ModelViewApp::update(float dt)
{
	updateFPS(dt);

	m_rot += dt;
	if (m_rot > glm::pi<float>()*2.0f) m_rot -= glm::pi<float>()*2.0f;
}
Esempio n. 3
0
void frame(void)
{
	updateFPS();
	
	if (g_IsRotatingX)
	{
		static double phase = 0;
		phase += g_PhaseDelta / 4;
		g_vu.rotx = phase;
	}
	if (g_IsRotatingY)
	{
		static double phase = 0;
		phase += g_PhaseDelta / 4;
		g_vu.roty = phase;
	}
	if (g_IsRotatingZ)
	{
		static double phase = 0;
		phase += g_PhaseDelta / 4;
		g_vu.rotz = phase;
	}
	if (g_IsZooming)
	{
		static double phase = 0;
		phase += g_PhaseDelta / 4;
		g_fu.Zoom = INITIAL_ZOOM - 1 + (cos(phase)+1)/2;
	}
	
	render();
}
Esempio n. 4
0
void PhysicHandler::update() {
    if (game_mode&GAME_MENU) {
        reset_time=true;
    } else if (game_mode&GAME_PAUSED ) {
        reset_time=true;
        updatePaused();
    } else if (game_mode&GAME_PLAY) {
        if (reset_time) {
            Dfps=Dframes=currentfps=dt=0;
            minfps=1000;
        } else {
            dt=(SDL_GetTicks()-tcurrent);
            updateFPS();
        }
        reset_time=false;
        tcurrent=SDL_GetTicks();
        updateGame();
    } else if (game_mode&GAME_EDIT_NOANIM) {
    } else if (game_mode&GAME_EDIT) {
        if (reset_time) {
            dt=0;
        } else {
            dt=(SDL_GetTicks()-tcurrent);
        }
        reset_time=false;
        tcurrent=SDL_GetTicks();
        updateEdit();
    } else {
    }
}
Esempio n. 5
0
void CaptureThread::run()
{
    while(1)
    {
        /////////////////////////////////
        // Stop thread if stopped=TRUE //
        /////////////////////////////////
        stoppedMutex.lock();
        if (stopped)
        {
            stopped=false;
            stoppedMutex.unlock();
            break;
        }
        stoppedMutex.unlock();
        /////////////////////////////////
        /////////////////////////////////
        // Save capture time
        captureTime=t.elapsed();
        // Start timer (used to calculate capture rate)
        t.start();
        // Capture and add frame to buffer
        cap>>grabbedFrame;
        imageBuffer->addFrame(grabbedFrame);
        // Update statistics
        updateFPS(captureTime);
    }
    qDebug() << "Stopping capture thread...";
} // run()
Esempio n. 6
0
// the function the thread will run when it is called
void ProcessingThread::run()
{
    while(1)
    {
        /////////////////////////////////
        // Stop thread if stopped=TRUE //
        /////////////////////////////////
        stoppedMutex.lock();
        if (stopped)
        {
            stopped=false;
            stoppedMutex.unlock();
            break;
        }
        stoppedMutex.unlock();
        /////////////////////////////////
        /////////////////////////////////

        // Save processing time
        processingTime=t.elapsed();
        // Start timer (used to calculate processing rate)
        t.start();
        // Get frame from queue
        Mat currentFrame=imageBuffer->getFrame();
        // Make copy of current frame (processing will be performed on this copy)
        currentFrame.copyTo(currentFrameCopy);
        // Set ROI of currentFrameCopy
        currentFrameCopy.locateROI(frameSize,framePoint);
        currentFrameCopy.adjustROI(-currentROI.y,-(frameSize.height-currentROI.height-currentROI.y),
                                   -currentROI.x,-(frameSize.width-currentROI.width-currentROI.x));

        updateMembersMutex.lock();

        updateMembersMutex.unlock();

        // Update statistics
        updateFPS(processingTime);
        currentSizeOfBuffer=imageBuffer->getSizeOfImageBuffer();

        if (decideToProcess()){
            writeHistory();

            // set the black level
            if (SetBlackFlag == 1){
                blackVal = setBlackCalib(currentFrame);
                SetBlackFlag = 0;
            }

            process(&currentFrame);
        }
        draw_on_image(GameState.table, &currentFrameCopy);
        frame=MatToQImage(currentFrameCopy);

        emit newFrame(frame);
        //printTest();

        //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    }
    qDebug() << "Stopping processing thread...";
}
Esempio n. 7
0
	bool BaseManager::HgeFrameFunc()
	{
		captureInput();
		updateFPS();
		drawOneFrame();
		return false;
	}
Esempio n. 8
0
//the game loop, calls all of the supplemental
//methods of the application to continuously
//update and maintain the functionality of the
//game
void Application::gameLoop()
{
    while(gameRunning)
    {
        handleEnvironment();

        updateMonsters();

        handleEvents();

        updatePlayer();

        handleArrows();

        handlePhysics();

        delta.start();

        checkBoundaries();
        updateFPS();
        updatePoints();
        drawSurface();

        if(finished)
        {
            showFinal();
        }

    }
}
void MyProcessing::run () {
	long long prevFrameNum, curFrameNum;
	prevFrameNum = -1;
	curFrameNum = 0;

    while(1)
    {
        ////////////////////////////////
        // Stop thread if doStop=TRUE //
        ////////////////////////////////
        doStopMutex.lock();
        if(doStop)
        {
            doStop=false;
            doStopMutex.unlock();
            break;
        }
        doStopMutex.unlock();
        /////////////////////////////////
        /////////////////////////////////

        int idx = rb->curRead();
        FrameData *d = rb->getPointer(idx);
        curFrameNum = d->frameNumber;
        if (prevFrameNum < curFrameNum) {
        	// Save processing time
        	processingTime=t.elapsed();
        	// Start timer (used to calculate processing rate)
        	t.start();

        	processingMutex.lock();
        	//rb->lockRead();
        	pluginStack->process(d);

        	Mat currentFrame = d->frame.clone();
        	//cout << "frame number : " << d->frameNumber << endl;

        	//rb->unlockRead();
            // Convert Mat to QImage
            frame=MatToQImage(currentFrame);
            processingMutex.unlock();

            // Inform GUI thread of new frame (QImage)
            emit newFrame(frame);

            // Update statistics
            updateFPS(processingTime);
            statsData.nFramesProcessed++;
            // Inform GUI of updated statistics
            emit updateStatisticsInGUI(statsData);
        }//if

        // With "true" it jumps directly ahead to the most recent data available. This means that we can possibly skip bins.
        rb->nextRead(true);
        prevFrameNum=curFrameNum;
    }
    //qDebug() << "Stopping processing thread...";

}
Esempio n. 10
0
void CaptureThread::run()
{
    LOGFUNC("CaptureThread::run");

    while(1)
    {
        ////////////////////////////////
        // Stop thread if doStop=TRUE //
        ////////////////////////////////
        doStopMutex.lock();
        if(doStop)
        {
            doStop=false;
            doStopMutex.unlock();
            break;
        }
        doStopMutex.unlock();
        //////////////////////////////////////
        // Stop capturing if doPause = TRUE //
        //////////////////////////////////////
        doPauseMutex.lock();
        if(doPause){
             pauseCondition.wait(&doPauseMutex);
         }
         doPauseMutex.unlock();

        // Save capture time
        captureTime=t.elapsed();
        // Start timer (used to calculate capture rate)
        t.start();

        // Synchronize with other streams (if enabled for this stream)
        sharedImageBuffer->sync(CameraDevice->deviceNumber);

        mCaptureFrameMutex.lock();
        // Capture fraCameraDeviceme (if available)
        if(!CameraDevice->grabFrame(&mGrabbedFrame))continue;

        if(imageNeeded){
            if(imageToCapture!=NULL)
                *imageToCapture = mGrabbedFrame.copy();
            imageNeeded = false;
        }
        // Add frame to buffer
        if(mGrabbedFrame.width()!=0 && mGrabbedFrame.height()!=0){
            sharedImageBuffer->getByDeviceNumber(CameraDevice->deviceNumber)->add(mGrabbedFrame, dropFrameIfBufferFull);
        }
        else{
            LOG_D("Invalid frame");
        }
        mCaptureFrameMutex.unlock();

        // Update statistics
        updateFPS(captureTime);
        statsData.nFramesProcessed++;
        // Inform GUI of updated statistics
        emit updateStatisticsInGUI(statsData);
    }
}
Esempio n. 11
0
void WorldEditor::render( int skip )
{

	viewportScreen.Render( camView.Object() , TRUE , TRUE );

	float fps = updateFPS();

	TMessageShow msgShow( m_world );
	msgShow.start();
	msgShow.push( "Fps: %6.2f", fps );
	{
		Vec3D pos = camControl.getPosition();
		Vec3D dir = camControl.getViewDir();
		msgShow.push( "Cam pos = ( %.1f %.1f %.1f ) viewDir = ( %.2f %.2f %.2f )" ,
			pos.x() , pos.y() , pos.z() , dir.x() , dir.y() , dir.z() );
	}


	g_devLog.show( msgShow );

	//if ( EditData* data = m_objEdit.getSelectEditData())
	//{
	//	if ( TActor* actor = TActor::upCast( data->entity ) )
	//	{
	//		Vec3D  pos = actor->getPosition();
	//		msgShow.push( "Hit pos = ( %.1f %.1f %.1f ) " ,
	//			pos.x() , pos.y() ,pos.z()  );
	//		actor->getFlyActor().GetWorldPosition( pos );
	//		msgShow.push( "Hit pos = ( %.1f %.1f %.1f ) " ,
	//			pos.x() , pos.y() ,pos.z()  );
	//	}
	//}
	
	if ( m_player )
	{
		Vec3D dir = m_player->getFaceDir();
		msgShow.push( "viewDir = ( %.2f %.2f %.2f )" , dir.x() , dir.y() , dir.z() );
		m_player->getFlyActor().GetDirection( dir , NULL );
		msgShow.push( "viewDir = ( %.2f %.2f %.2f )" , dir.x() , dir.y() , dir.z() );
		FnObject obj; obj.Object( m_player->getFlyActor().GetBaseObject() );
		msgShow.push( "viewDir = ( %.2f %.2f %.2f )" , dir.x() , dir.y() , dir.z() );
	}

	if ( m_Mode == MODE_RUN )
	{
		TProfileIterator* profIter = TProfileManager::createIterator();

		profIter->getCurNode()->showAllChild( true );
		showProfileInfo( profIter , msgShow , NULL );
		TProfileManager::releaseIterator( profIter );
	}



	msgShow.finish();

	m_world.SwapBuffers();
}
Esempio n. 12
0
int Camera::update(float timeDelta) {
    bool anim_done = false;
    cameraMatrix.identity();
    if (!anim) {
        Matrix4 lookMat = cashew::gluLookAt(0.0f, 0.0f, 0.0f - distance, 0.0f,
                                            0.0f, 0.0f, 0.0, 1.0, 0.0);
        Matrix4 trans;
        trans.translate(-camCenter.x, -camCenter.y, -camCenter.z);
        cameraMatrix = lookMat * rotate.getMatrix() * trans;
        animTime = 0;
    } else {
        animTime += timeDelta;
        float alpha = animTime / ANIM_TIME_MS;
        if (animTime >= ANIM_TIME_MS) {
            anim_done = true;
            animTime = 0;
            anim = false;
            if (rotChange)
                rotate = rotateTo;
            if (distChange)
                distance = distanceTo;
            if (centerChange)
                camCenter = camCenterTo;

            rotChange = false;
            centerChange = false;
            distChange = false;

            Controller::rotate = Quaternion::toEuler(rotate);

            Matrix4 lookMat = cashew::gluLookAt(
                0.0f, 0.0f, 0.0f - distance, 0.0f, 0.0f, 0.0f, 0.0, 1.0, 0.0);
            Matrix4 trans;
            trans.translate(-camCenter.x, -camCenter.y, -camCenter.z);
            cameraMatrix = lookMat * rotate.getMatrix() * trans;
        } else {
            float distanceTmp = distance * (1 - alpha) + distanceTo * alpha;
            rotate_slerp = Quaternion();
            if (rotChange)
                rotate_slerp = Quaternion::slerp(rotate, rotateTo, alpha);
            Vector3 camCenterTmp =
                camCenter * (1 - alpha) + camCenterTo * alpha;
            Matrix4 lookMat =
                cashew::gluLookAt(0.0f, 0.0f, 0.0f - distanceTmp, 0.0f, 0.0f,
                                  0.0f, 0.0, 1.0, 0.0);
            Matrix4 trans;
            trans.translate(-camCenterTmp.x, -camCenterTmp.y, -camCenterTmp.z);
            cameraMatrix = lookMat * rotate_slerp.getMatrix() * trans;
        }
    }
    modelView = cameraMatrix;
    updateFPS(timeDelta);
    if (anim_done)
        return UPDATE_ANIM_DONE;
    else
        return UPDATE_OK;
}
Esempio n. 13
0
void DrawWidget::updateScene()
{
    double physicsTime = 0;
    if(!paused)
        physicsTime = sceneManager.update(0.025f*timeRate);
    camera.update();
    update();
    emit updateFPS(physicsTime, 1./renderer.getFPS());
}
Esempio n. 14
0
	//-------------------------------------------------------------------------------
	void GameApp::updateFrame()
	{	
		//processSystemEvents();
		updateSimulation();
		updateDisplay();		
		updateFPS();

		ProfileSystem::getInstance()->clearFrameData();
	}
Esempio n. 15
0
void graphicsDraw(){
	SDL_SetRenderDrawColor(gfx.renderer, 0, 0, 0, 255);
	SDL_RenderClear(gfx.renderer);

	if(show_fps == 1)
		updateFPS();
	drawUnits();

	SDL_RenderPresent(gfx.renderer);
}
Esempio n. 16
0
//----------------------------------------------------------------------------//
void CEGuiBaseApplication::renderSingleFrame(const float elapsed)
{
    CEGUI::System& gui_system(CEGUI::System::getSingleton());

    gui_system.injectTimePulse(elapsed);
    d_sampleApp->update(static_cast<float>(elapsed));

    updateFPS(elapsed);
    updateLogo(elapsed);

    beginRendering(elapsed);

    CEGUI::Renderer* gui_renderer(gui_system.getRenderer());
    gui_renderer->beginRendering();

    d_sampleApp->renderGUIContexts();

    gui_renderer->endRendering();
    CEGUI::WindowManager::getSingleton().cleanDeadPool();

    endRendering();
}
Esempio n. 17
0
	void BaseManager::run()
	{
		MSG msg;
		while (true)
		{
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			if (mExit)
				break;
			else if (msg.message == WM_QUIT)
				break;

			captureInput();
			updateFPS();
			drawOneFrame();

			if (GetActiveWindow() != hWnd)
				::Sleep(50);
		}
	}
Esempio n. 18
0
void Game::run() {
  if (!initialized) {
    return;
  }
  
  instance = newInstance;
  newInstance = nullptr;
  Assets::clean();
  
  Thread updateThread([]() {
    lastUpdate = Time::get();
    
    while (!metallicar::quit && instance) {
      bool updated = false;
      
      updateTimeElapsed();
      while (timeElapsedGreaterThanStep()) {
        updated = true;
        
        renderingBackBuffer->clear();
        Input::pollEvents();
        instance->update();
        instance->render();
        
        if (newInstance) { // change instance
          delete instance;
          instance = newInstance;
          newInstance = nullptr;
          Assets::clean();
        }
      }
      
      if (updated) { // swap rendering buffers
        renderingBuffersLock.mutexlock();
        map<double, list<function<void()>>>* tmp = renderingFrontBuffer;
        renderingFrontBuffer = renderingBackBuffer;
        renderingBackBuffer = tmp;
        renderingBuffersLock.unlock();
      }
      
      Thread::sleep(1);
    }
  });
  updateThread.start();
  
  Thread audioCleanupThread([]() {
    while (!metallicar::quit && instance) {
      Audio::clean();
      Thread::sleep(500);
    }
  });
  audioCleanupThread.start();
  
  // main thread (I/O)
  while (!metallicar::quit && instance) {
    updateFPS();
    
    Input::pollWindowEvents();
    
    // copy front buffer
    renderingBuffersLock.mutexlock();
    map<double, list<function<void()>>> renderers(*renderingFrontBuffer);
    renderingBuffersLock.unlock();
    
    // render
    Graphics::prepareFrame();
    for (auto& kv : renderers) {
      for (auto& renderer : kv.second) {
        renderer();
      }
    }
    Graphics::finalizeFrame();
    
    Window::update();
  }
  
  updateThread.join();
  audioCleanupThread.join();
}
Esempio n. 19
0
void PatternBase::FPSIncrementSin() {
    int val =map(sin8_C(FPSIncrementer++),0,255,13,20);
    updateFPS(val);}
Esempio n. 20
0
void ProcessingThread::run()
{
    while(1)
    {
        /////////////////////////////////
        // Stop thread if stopped=TRUE //
        /////////////////////////////////
        stoppedMutex.lock();
        if (stopped)
        {
            stopped=false;
            stoppedMutex.unlock();
            break;
        }
        stoppedMutex.unlock();
        /////////////////////////////////
        /////////////////////////////////

        // Save processing time
        processingTime=t.elapsed();
        // Start timer (used to calculate processing rate)
        t.start();

        // Get frame from queue, store in currentFrame, set ROI
        currentFrame=Mat(imageBuffer->getFrame(),currentROI);

        updateMembersMutex.lock();
        ///////////////////
        // PERFORM TASKS //
        ///////////////////
        // Note: ROI changes will take effect on next frame
        if(resetROIFlag)
            resetROI();
        else if(setROIFlag)
            setROI();
        ////////////////////////////////////
        // PERFORM IMAGE PROCESSING BELOW //
        ////////////////////////////////////
        // Grayscale conversion
        if(grayscaleOn)
            cvtColor(currentFrame,currentFrameGrayscale,CV_BGR2GRAY);
        // Smooth (in-place operations)
        if(smoothOn)
        {
            if(grayscaleOn)
            {
                switch(smoothType)
                {
                    // BLUR
                    case 0:
                        blur(currentFrameGrayscale,currentFrameGrayscale,Size(smoothParam1,smoothParam2));
                        break;
                    // GAUSSIAN
                    case 1:
                        GaussianBlur(currentFrameGrayscale,currentFrameGrayscale,Size(smoothParam1,smoothParam2),smoothParam3,smoothParam4);
                        break;
                    // MEDIAN
                    case 2:
                        medianBlur(currentFrameGrayscale,currentFrameGrayscale,smoothParam1);
                        break;
                }
            }
            else
            {
                switch(smoothType)
                {
                    // BLUR
                    case 0:
                        blur(currentFrame,currentFrame,Size(smoothParam1,smoothParam2));
                        break;
                    // GAUSSIAN
                    case 1:
                        GaussianBlur(currentFrame,currentFrame,Size(smoothParam1,smoothParam2),smoothParam3,smoothParam4);
                        break;
                    // MEDIAN
                    case 2:
                        medianBlur(currentFrame,currentFrame,smoothParam1);
                        break;
                }
            }
        }
        // Dilate
        if(dilateOn)
        {
            if(grayscaleOn)
                dilate(currentFrameGrayscale,currentFrameGrayscale,Mat(),Point(-1,-1),dilateNumberOfIterations);
            else
                dilate(currentFrame,currentFrame,Mat(),Point(-1,-1),dilateNumberOfIterations);
        }
        // Erode
        if(erodeOn)
        {
            if(grayscaleOn)
                erode(currentFrameGrayscale,currentFrameGrayscale,Mat(),Point(-1,-1),erodeNumberOfIterations);
            else
                erode(currentFrame,currentFrame,Mat(),Point(-1,-1),erodeNumberOfIterations);
        }
        // Flip
        if(flipOn)
        {
            if(grayscaleOn)
                flip(currentFrameGrayscale,currentFrameGrayscale,flipCode);
            else
                flip(currentFrame,currentFrame,flipCode);
        }
        // Canny edge detection
        if(cannyOn)
        {
            // Frame must be converted to grayscale first if grayscale conversion is OFF
            if(!grayscaleOn)
                cvtColor(currentFrame,currentFrameGrayscale,CV_BGR2GRAY);

            Canny(currentFrameGrayscale,currentFrameGrayscale,
                  cannyThreshold1,cannyThreshold2,
                  cannyApertureSize,cannyL2gradient);
        }
        ////////////////////////////////////
        // PERFORM IMAGE PROCESSING ABOVE //
        ////////////////////////////////////

        // Convert Mat to QImage: Show grayscale frame [if either Grayscale or Canny processing modes are ON]
        if(grayscaleOn||cannyOn)
            frame=MatToQImage(currentFrameGrayscale);
        // Convert Mat to QImage: Show BGR frame
        else
            frame=MatToQImage(currentFrame);
        updateMembersMutex.unlock();

        // Update statistics
        updateFPS(processingTime);
        currentSizeOfBuffer=imageBuffer->getSizeOfImageBuffer();
        // Inform GUI thread of new frame (QImage)
        emit newFrame(frame);
    }
    qDebug() << "Stopping processing thread...";
}
//----------------------------------------------------------------------------//
bool CEGuiD3D10BaseApplication::execute(CEGuiSample* sampleApp)
{
    sampleApp->initialiseSample();

    float clear_colour[4] = { 0.0f, 0.0f, 0.0f, 1.0f };

    //
    //  This is basically a modified Win32 message pump
    //
    bool idle;

    while (Win32AppHelper::doWin32Events(idle))
    {
        if (idle)
        {
            CEGUI::System& guiSystem = CEGUI::System::getSingleton();

            // do time based updates
            DWORD thisTime = GetTickCount();
            float elapsed = static_cast<float>(thisTime - d_lastFrameTime);
            d_lastFrameTime = thisTime;
            // inject the time pulse
            guiSystem.injectTimePulse(elapsed / 1000.0f);

            updateFPS();
            char fpsbuff[16];
            sprintf(fpsbuff, "FPS: %d", d_FPS);

            Win32AppHelper::doDirectInputEvents(pimpl->d_directInput);

            // get render target view
            // this is a bit wasteful, but done like this for now since the
            // resize code can change the view from under us.
            ID3D10RenderTargetView* rtview;
            pimpl->d_device->OMGetRenderTargets(1, &rtview, 0);

            // clear display
            pimpl->d_device->ClearRenderTargetView(rtview, clear_colour);

            // main CEGUI rendering call
            guiSystem.renderGUI();

            // render FPS:
            CEGUI::Font* fnt = guiSystem.getDefaultFont();
            if (fnt)
            {
                guiSystem.getRenderer()->setQueueingEnabled(false);
                fnt->drawText(fpsbuff, CEGUI::Vector3(0, 0, 0),
                              guiSystem.getRenderer()->getRect());
            }

            pimpl->d_swapChain->Present(0, 0);
            rtview->Release();
        }

        // check if the application is quitting, and break the loop next time
        // around if so.
        if (isQuitting())
            PostQuitMessage(0);
    }

    return true;
}
Esempio n. 22
0
void frame(void)
{
	updateFPS();
	
	render();
}
Esempio n. 23
0
void doFrame()
{
    if(Input::IsKeyDown(SDLK_LCTRL) && Input::IsPressed(SDLK_q))
    {
        if(connected)
        {
            MAKE_MSG(quit_msg,msg,QUIT_MSG);
            nc.send((unsigned char *)&msg,sizeof(quit_msg),SEND_GUARANTEED);
        }
        else
            done=1;
    }
    if ((Input::IsKeyDown(SDLK_LALT) || Input::IsKeyDown(SDLK_RALT)) && Input::IsPressed(SDLK_RETURN))
    {
        fullscreen = !fullscreen;
        Renderer::SetFullscreen(fullscreen);
        // The next block of code is stupid nonsense crap because it is already setup.
        // There is no reason to reload EVERYTHING just because we are going to fullscreen.
        /*initializeSystem();
        Renderer::Clear();
        Renderer::LoadIdentity();
        //load images and sounds
        char pnum[32];
        int i;
        soundMax=-1;
        bodyMax=-1;
        hairMax=-1;
        clothesMax=-1;
        monsterMax=-1;
        for(i=0;i<255;i++)
        {
        	if(soundMax==-1)
        	{
        		sprintf(pnum,"data/sounds/%d.wav",i);
        		if(!sounds.Load(i,pnum))
        			soundMax=i;
        	}
        	if(bodyMax==-1)
        	{
        		sprintf(pnum,"data/body/%d.png",i);
        		if(!pBody[i].Load(pnum))
        			bodyMax=i;
        	}
        	if(hairMax==-1)
        	{
        		sprintf(pnum,"data/hair/%d.png",i);
        		if(!pHair[i].Load(pnum))
        			hairMax=i;
        	}
        	if(clothesMax==-1)
        	{
        		sprintf(pnum,"data/clothes/%d.png",i);
        		if(!pClothes[i].Load(pnum))
        			clothesMax=i;
        	}
        	if(monsterMax==-1 && i>0)
        	{
        		sprintf(pnum,"data/monsters/%d.png",i);
        		if(!pMonster[i].Load(pnum))
        			monsterMax=i;
        	}
        }
        tiledata.Load("data/misc/tiledata.png");
        effdata.Load("data/misc/effects.png");
        itemdata.Load("data/misc/items.png");
        loading.Load("data/misc/loading.png");
        skin.Load("data/misc/skin0.png");

        //load fonts
        font.Load("data/misc/font.png");
        TEXTDRAWER.Initialize(font.img);
        TEXTDRAWER.setColor(0,0,0,1);
        //create effects,terminal,dialog boxes
        eff.create(MAX_EFFECTS);
        bar.create(MAX_HPBAR);
        term.create(255,11);

        //	setupDialogs();
        loadEffectsMap();
        updateFPS();*/

        //render images
        doGameGraphics();
    }
    if(Input::IsPressed(SDLK_F5))//change skins
    {
        guiskin++;
        char name[256];
        sprintf(name,"data/misc/skin%d.png",guiskin);
        FILE *f=fopen(name,"r");
        if(f==NULL)
        {
            guiskin=0;
            sprintf(name,"data/misc/skin%d.png",guiskin);
            skin.Load(name);
        }
        else
        {
            fclose(f);
            f=0;
            skin.Load(name);
        }
    }
    if(Input::IsPressed(SDLK_ESCAPE))
    {
        target=-1;
        mtarget_id=-1;
        MAKE_MSG(trgt_msg,tr,TRGT_MSG);
        tr.index=mtarget_id;
        nc.send((unsigned char *)&tr,sizeof(trgt_msg),SEND_GUARANTEED);
        ptarget_id=-1;
        chatting=0;
        Input::ResetString();
    }
    if(connected && dialog==-1 && Input::IsPressed(SDLK_RETURN) && !Input::IsKeyDown(SDLK_LALT) && !Input::IsKeyDown(SDLK_RALT))
    {
        if(chatting)
        {
            if(strlen(Input::GetString())==0)
                chatting=0;
        }
        else
            chatting=1;
    }
    if(connected && me > -1 && MYGUY.access > 5)
    {
        if(Input::IsPressed(SDLK_F1))
        {
            target=-1;
            if(mode==1) mode=0;
            else mode=1;
        }
        if(Input::IsPressed(SDLK_F11)) //debug
        {

            if(debug==1) debug=0;
            else debug=1;
        }
    }
    if(me > -1 && !chatting && dialog==-1 && MYGUY.hp>0 && (strcmp(world[MYGUY.p.map].name,"_EMPTY_")!=0 || mode==1))
        doGameInput();
    else if((ptarget_id!=-1&&MYGUY.front()==player[ptarget_id].p)&& attackTimer.tick(50))
        attack();
    if(dialog==-1 && chatting && Input::StringInput(240))
    {
        if(parse(Input::GetString()))
        {
            if(me > -1)
            {
                //sprintf(temp,"%s:%s",MYGUY.name, Input::GetString());
                //term.newLine("Here is a very long sentence i am using to test with will you please split it up correctly at the spaces so it will wrap around, thank you very much sir...");
                //term.newLine(Input::GetString());
                //balloon.add(Input::GetString(),me);
                MAKE_MSG(chat_msg,reply,CHAT_MSG);
                reply.size=strlen(Input::GetString())+1;//+1 for null
                char buf[256];
                char *InputString = Input::GetString();
                memcpy(&buf,(void *)&reply,sizeof(chat_msg));//store header
                memcpy(buf+sizeof(chat_msg),(void *)&InputString,reply.size);//store string
                nc.send((unsigned char *)&buf,sizeof(chat_msg)+reply.size,SEND_GUARANTEED);
                chatting=0;
            }
        }
        else if(me > -1)
        {
            chatting=0;
        }
        Input::ResetString();
    }
    updateFPS();
    //render images
    Renderer::Clear();
    Renderer::LoadIdentity();
    doGameGraphics();

    /*TEXTDRAWER.setColor(1,1,1,1);//draw bottleneck stats
    for(int i=0;i<4;i++)
    	TEXTDRAWER.PrintText(10,50+i*20,"%d) %d",i,bottle.times[i]);
    TEXTDRAWER.defaultColor();*/

    if(mode==1)
    {
        doMapDialog();
        int r=mapDialog.modified();
        if(r>-1)
            mapEvent(r);
    }
    //if(keyDown[SDLK_HOME])
    //	term.renderAll(0,200);
    //else
    term.render(0,480,246-chat_scroll,9);
    if(dialog!=-1)
    {
        vDialog[dialog].draw();
        if(dialog==4)//draw sprites
        {
            if(animTimer.tick(400))
                animSel=abs(animSel-1);
            TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162,"%d",bodySel);
            TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162+35,"%d",clothesSel);
            TEXTDRAWER.PrintTextf(vDialog[4].x+160,vDialog[4].y+162+70,"%d",hairSel);
            drawChar(vDialog[4].x+10,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,0,animSel,4);
            drawChar(vDialog[4].x+90,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,1,animSel,4);
            drawChar(vDialog[4].x+170,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,2,animSel,4);
            drawChar(vDialog[4].x+250,vDialog[4].y+10,-1,bodySel,clothesSel,hairSel,3,animSel,4);
        }
        else if(dialog==6)
        {
            if(animTimer.tick(400))
                animSel=abs(animSel-1);
            for(int i=0; i<4; i++)if(slot[i].lvl>0)
                {
                    TEXTDRAWER.PrintTextf(vDialog[6].x+16+128*i,vDialog[6].y+162,"%s",slot[i].name);
                    TEXTDRAWER.PrintTextf(vDialog[6].x+16+128*i,vDialog[6].y+162+16,"Level %d",slot[i].lvl);
                    drawChar(vDialog[6].x+10+128*i,vDialog[6].y+10,slot[i].sprite,slot[i].body,slot[i].clothes,slot[i].hair,0,animSel,4);
                    TEXTDRAWER.PrintTextf(vDialog[6].x+28+128*i,vDialog[6].y+196,"Use");
                }
                else TEXTDRAWER.PrintTextf(vDialog[6].x+28+128*i,vDialog[6].y+196,"New");
        }
        int r=vDialog[dialog].modified();
        if(r!=-1)
            dialogEvent(r);
    }
    else
    {
        if(me>-1 && strcmp(world[MYGUY.p.map].name,"_EMPTY_")==0)
        {
            loading.blitFast(150,150,float(Input::MouseX())/640.0f,float(Input::MouseY())/480.0f);
        }
        if(chatting)
        {
            char temp[256];
            int x=0,len;
            sprintf(temp,"Send:%s_",Input::GetString());
            len=pWidth(temp);
            if(len>636)
                x=636-len;
            TEXTDRAWER.setColor(1,1,1,1);
            TEXTDRAWER.PrintText(x,585,temp);
            TEXTDRAWER.defaultColor();
        }
    }
    //cursor
    skin.blit(Input::MouseX(),Input::MouseY(),64,0,32,32,1,1);
    Renderer::Swap();
}
void ProcessingThread::run()
{
    qDebug() << "Starting processing thread...";
    while(1)
    {
        ////////////////////////// /////// 
        // Stop thread if doStop=TRUE // 
        ////////////////////////// /////// 
        doStopMutex.lock();
        if(doStop)
        {
            doStop=false;
            doStopMutex.unlock();
            break;
        }
        doStopMutex.unlock();
        ////////////////////////// ////////
        ////////////////////////// ////////

        // Save processing time
        processingTime=t.elapsed();
        // Start timer (used to calculate processing rate)
        t.start();

        processingMutex.lock();
        // Get frame from queue, store in currentFrame, set ROI
        currentFrame=Mat(sharedImageBuffer->getByDeviceNumber(deviceNumber)->get().clone(), currentROI);

        ////////////////////////// ///////// // 
        // PERFORM IMAGE PROCESSING BELOW // 
        ////////////////////////// ///////// // 

        // Grayscale conversion (in-place operation)
       if(imgProcFlags.grayscaleOn && (currentFrame.channels() == 3 || currentFrame.channels() == 4)) {
           cvtColor(currentFrame, currentFrame, CV_BGR2GRAY, 1);
       }

       // Save the original Frame after grayscale conversion, so VideoWriter works correct
       if(emitOriginal || captureOriginal)
           originalFrame = currentFrame.clone();

       // Fill Buffer that is processed by Magnificator
       fillProcessingBuffer();

       if (processingBufferFilled()) {
           if(imgProcFlags.colorMagnifyOn)
           {
               magnificator.colorMagnify();
               currentFrame = magnificator.getFrameLast();
           }
           else if(imgProcFlags.laplaceMagnifyOn)

           {
               magnificator.laplaceMagnify();
               currentFrame = magnificator.getFrameLast();
           }
           else if(imgProcFlags.waveletMagnifyOn)
           {
               magnificator.waveletMagnify();
               currentFrame = magnificator.getFrameLast();
           }
           else
               processingBuffer.erase(processingBuffer.begin());
       }

        ////////////////////////// ///////// // 
        // PERFORM IMAGE PROCESSING ABOVE // 
        ////////////////////////// ///////// // 

        // Convert Mat to QImage
        frame=MatToQImage(currentFrame);

        processingMutex.unlock();

        // Save the Stream
        if(doRecord) { 
            if(output.isOpened()) { 
                if(captureOriginal) {

                    processingMutex.lock();
                    // Combine original and processed frame
                    combinedFrame = combineFrames(currentFrame,originalFrame);
                    processingMutex.unlock();

                    output.write(combinedFrame);
                }
                else {
                    output.write(currentFrame);
                }

                framesWritten++;
                emit frameWritten(framesWritten);
            }
        }

        // Emit the original image before converting to grayscale
       if(emitOriginal)
           emit origFrame(MatToQImage(originalFrame));
        // Inform GUI thread of new frame (QImage)
        // emit newFrame(frame);
        emit newFrame(MatToQImage(currentFrame));

        // Update statistics
        updateFPS(processingTime);
        statsData.nFramesProcessed++;
        // Inform GUI of updated statistics
        emit updateStatisticsInGUI(statsData);
    }
    qDebug() << "Stopping processing thread...";
}
Esempio n. 25
0
int main()
{
	GLFWwindow* window;
	struct DemoData data;
	struct NVGcontext* vg = NULL;
	struct FPScounter fps;
	double prevt = 0;

	if (!glfwInit()) {
		printf("Failed to init GLFW.");
		return -1;
	}

	initFPS(&fps);

	glfwSetErrorCallback(errorcb);

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL);
	if (!window) {
		glfwTerminate();
		return -1;
	}

	glfwSetKeyCallback(window, key);

	glfwMakeContextCurrent(window);
#ifdef NANOVG_GLEW
	glewExperimental = GL_TRUE;
    if(glewInit() != GLEW_OK) {
		printf("Could not init glew.\n");
		return -1;
	}
#endif

	vg = nvgCreateGL3(512,512);
	if (vg == NULL) {
		printf("Could not init nanovg.\n");
		return -1;
	}

	if (loadDemoData(vg, &data) == -1)
		return -1;

	glfwSwapInterval(0);

	glfwSetTime(0);
	prevt = glfwGetTime();

	while (!glfwWindowShouldClose(window))
	{
		double mx, my, t, dt;
		int width, height;

		t = glfwGetTime();
		dt = t - prevt;
		prevt = t;
		updateFPS(&fps, dt);

		glfwGetCursorPos(window, &mx, &my);
		glfwGetFramebufferSize(window, &width, &height);

		// Update and render
		glViewport(0, 0, width, height);
		glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_CULL_FACE);
		glDisable(GL_DEPTH_TEST);

		nvgBeginFrame(vg, width, height);

		renderDemo(vg, mx,my, width,height, t, blowup, &data);
		renderFPS(vg, 5,5, &fps);

		glEnable(GL_DEPTH_TEST);

		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	freeDemoData(vg, &data);

	nvgDeleteGL3(vg);

	glfwTerminate();
	return 0;
}
Esempio n. 26
0
QWidget*
GUIBuilder::addCanvas(model::gui::Canvas *root, QWidget *parent )
{
    QWidget* wrapper = NULL;

    if( m_root_context == NULL ) {
        throw std::runtime_error( "Only GL jobs can create canvases." );
    }

    if( m_controller->perfMode() || m_controller->renderListMode() ) {
        wrapper = new QWidget( parent );

        QWidget* row = new QWidget( wrapper );
        QHBoxLayout* row_layout = new QHBoxLayout( row );
        row->setLayout( row_layout );
        row->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        row_layout->setContentsMargins( 0, 0, 0, 0 );

        tinia::qtcontroller::impl::Canvas * canvas = new tinia::qtcontroller::impl::Canvas( static_cast<jobcontroller::OpenGLJob*>(m_job),
                                      root->key(),
                                      root->viewerType(),
                                      root->scripts(),
                                      m_model,
                                      wrapper,
                                      m_root_context,
                                      true );
        canvas->setMinimumSize(640, 360);
        canvas->setMaximumSize(2000, 2000);
        canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

        if( m_controller->renderListMode() ) {
            QComboBox* mode = new QComboBox( row );
            mode->addItem( "Native Rendering" );
            mode->addItem( "Render List" );
            row->layout()->addWidget( mode );
            QObject::connect( mode, SIGNAL(currentIndexChanged(int)),
                              canvas, SLOT(setRenderMode(int)) );
        }
        if( m_controller->perfMode() ) {
            QLabel* fps_label = new QLabel( row );
            fps_label->setText( "fps" );
            QObject::connect( canvas, SIGNAL(updateFPS(QString)), fps_label, SLOT(setText(QString)));
            row->layout()->addWidget(fps_label);
        }
        row_layout->addStretch( 1 );

        QVBoxLayout* wrapper_layout = new QVBoxLayout(wrapper);
        wrapper->setLayout( wrapper_layout );
        wrapper_layout->setSpacing( 0 );
        wrapper_layout->setContentsMargins( 0, 0, 0, 0 );

        wrapper->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        wrapper->layout()->addWidget(canvas );
        wrapper->layout()->addWidget( row );
    }
    else {
        tinia::qtcontroller::impl::Canvas * canvas = new tinia::qtcontroller::impl::Canvas( static_cast<jobcontroller::OpenGLJob*>(m_job),
                                      root->key(),
                                                                                            root->viewerType(),
                                                                                            root->scripts(),
                                      m_model,
                                      parent,
                                      m_root_context,
                                      false );
        canvas->setMinimumSize(640, 360);
        canvas->setMaximumSize(2000, 2000);
        canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        wrapper = canvas;
    }
    return wrapper;
}
Esempio n. 27
0
	void MyGUIRenderClick::run()
	{		
		//captureInput();
		updateFPS();
		drawOneFrame();			
	}