Esempio n. 1
0
void C3DView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	if (GetRenderer())
		GetRenderer()->Redraw();	
}
Esempio n. 2
0
DisconnectedScreen::DisconnectedScreen() {
	ConfigUtility& config = ConfigUtility::GetSingleton();

	//setup the utility objects
	//TODO: (1) resource tool, to prevent reloading like this
	image.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
	font = TTF_OpenFont(config["client.font"].c_str(), 12);

	//check that the font loaded
	if (!font) {
		std::ostringstream msg;
		msg << "Failed to load a font file; " << SDL_GetError();
		throw(std::runtime_error(msg.str()));
	}

	//setup the button
	backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
	backButton.SetText(GetRenderer(), font, WHITE, "Back");

	//set the button positions
	backButton.SetX(50);
	backButton.SetY(50);

	//set the disconnection message text
	textLine.SetX(50);
	textLine.SetY(30);
	textLine.SetText(GetRenderer(), font, WHITE, config["client.disconnectMessage"]);

	//full reset
	UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);

	//auto return
	startTick = std::chrono::steady_clock::now();
}
Esempio n. 3
0
vtkProp* RenderView3D::PickProp( int posX, int posY, double* pos_out )
{
  vtkCellPicker* picker = vtkCellPicker::SafeDownCast( this->GetRenderWindow()->GetInteractor()->GetPicker() );
  if ( !picker )
  {
    return NULL;
  }

  picker->InitializePickList();
  vtkPropCollection* props = GetRenderer()->GetViewProps();
  if ( props )
  {
    props->InitTraversal();
    vtkProp* prop = props->GetNextProp();
    while ( prop )
    {
      if ( vtkActor::SafeDownCast( prop ) )
      {
        picker->AddPickList( prop );
      }
      prop = props->GetNextProp();
    }
  }
  picker->Pick( posX, rect().height() - posY, 0, GetRenderer() );
  if ( pos_out )
  {
    picker->GetPickPosition( pos_out );
  }
  return picker->GetViewProp();
}
// Touch event handler.
bool COGActorPlayer::OnTouch (const OGVec2& _vPos, IOGTouchParam _param)
{
    if (_param != OG_TOUCH_DOWN)
        return false;

    if (m_bFinishLineFlight)
        return false;

    OGVec3 vP = GetRenderer()->UnprojectCoords((int)_vPos.x, (int)_vPos.y);
    OGVec3 vCam = GetRenderer()->GetCamera()->GetPosition();

    OGVec3 vDir = (vP - vCam).normalized();
    OGVec3 vPoint = FindIntersectionWithPlane(
        m_pPhysicalObject->GetPosition().y, 
        vCam, 
        vDir);
    m_vTarget = vPoint;

    m_OrientWorker.Reset();
    m_OrientWorker.SetTarget(vPoint);
    m_OrientWorker.Activate(true);

    m_CoolDown = 0;
    m_StraightenWorker.Activate(false);
    return true;
}
Esempio n. 5
0
void DrawTitle()
{
	GList *elem,*elem2;
	Button *ref;
	SDL_Rect src;
	Editor_Panel* panel;
	Label* label;
	int n,i,j;
	if(game->gameState == &StateTitle){
		if(g_list_length(MainEditorPanels) != 0){
		for(n = 0; n < g_list_length(MainEditorPanels);++n)
		{
			elem = g_list_nth(MainEditorPanels,n);
			panel = (Editor_Panel*)elem->data;
			for(i = 0; i < g_list_length(panel->buttons);++i)
			{
				elem2 = g_list_nth(panel->buttons,i);
				ref = (Button*)elem2->data;
				DrawSprite(ref->sprite,ref->rect.x,ref->rect.y,ref->frame,GetRenderer(),SDL_FLIP_NONE);
			}
			for(i = 0; i < g_list_length(panel->labels);++i)
			{
				elem2 = g_list_nth(panel->labels,i);
				label = (Label*)elem2->data;
				DrawSprite(label->sprite,label->rect.x,label->rect.y,0,GetRenderer(),SDL_FLIP_NONE);
			}

		}
		}
	}
}
bool SurfaceTextureBuffer::MakeCurrent(uint8 nFace)
{
	// Check whether the data is valid and whether there's a texture buffer
	if (m_cTextureBufferHandler.GetResource() && GetTextureBuffer()) {
		// Set target face
		if (GetTextureBuffer()->GetType() == PLRenderer::Resource::TypeTextureBufferCube)
			m_nFace = nFace;
		else
			m_nFace = 0;

		// Cleanup texture buffer handlers
		for (uint32 i=0; i<m_lstTextureBufferHandler.GetNumOfElements(); i++)
			delete m_lstTextureBufferHandler[i];
		m_lstTextureBufferHandler.Clear();

		// Add primary texture buffer handler
		PLRenderer::ResourceHandler *pTextureBufferHandler = new PLRenderer::ResourceHandler();
		pTextureBufferHandler->SetResource(m_cTextureBufferHandler.GetResource());
		m_lstTextureBufferHandler.Add(pTextureBufferHandler);

		// Frame buffer object used?
		if (m_pFrameBufferObject && m_cTextureBufferHandler.GetResource()) {
			m_pFrameBufferObject->SwitchTarget(static_cast<PLRenderer::TextureBuffer&>(*m_cTextureBufferHandler.GetResource()), 0, nFace);
			m_pFrameBufferObject->Bind();

			// Need rendering to depth only
			PLRenderer::TextureBuffer::EPixelFormat nFormat = GetTextureBuffer()->GetFormat();
			if (nFormat == PLRenderer::TextureBuffer::D16 || nFormat == PLRenderer::TextureBuffer::D24 || nFormat == PLRenderer::TextureBuffer::D32) {
				glDrawBuffer(GL_NONE);
				glReadBuffer(GL_NONE);
			} else {
				// Get extensions instance
				const Extensions &cExtensions = static_cast<Renderer&>(GetRenderer()).GetContext().GetExtensions();

				// Set draw buffers
				static const GLuint db[16] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT,
											   GL_COLOR_ATTACHMENT4_EXT, GL_COLOR_ATTACHMENT5_EXT, GL_COLOR_ATTACHMENT6_EXT, GL_COLOR_ATTACHMENT7_EXT,
											   GL_COLOR_ATTACHMENT8_EXT, GL_COLOR_ATTACHMENT9_EXT, GL_COLOR_ATTACHMENT10_EXT, GL_COLOR_ATTACHMENT11_EXT,
											   GL_COLOR_ATTACHMENT12_EXT, GL_COLOR_ATTACHMENT13_EXT, GL_COLOR_ATTACHMENT14_EXT, GL_COLOR_ATTACHMENT15_EXT};
				if (cExtensions.IsGL_ARB_draw_buffers())
					glDrawBuffersARB(m_nMaxColorTargets, db);
				else if (cExtensions.IsGL_ATI_draw_buffers())
					glDrawBuffersATI(m_nMaxColorTargets, db);
			}

		// Else...
		} // ... If there's no frame buffer, we can still 'render to texture' by only using glCopyTexSubImage2D() to
		  // copy the drawn stuff into a texture buffer. But this way, the current framebuffer content is 'overdrawn' and
		  // the texture buffer size we can render in is limited to the screen size.

		// Enable/disable multisample - "shouldn't" have an effect when render to texture, but safe is safe :D
		GetRenderer().SetRenderState(PLRenderer::RenderState::MultisampleEnable, !(GetFlags() & NoMultisampleAntialiasing));

		// Done
		return true;
	}

	// Error!
	return false;
}
Esempio n. 7
0
OptionsMenu::OptionsMenu() {
	ConfigUtility& config = ConfigUtility::GetSingleton();

	//setup the utility objects
	buttonImage.Load(GetRenderer(), config["dir.interface"] + "button_blue.png");
	font = TTF_OpenFont(config["client.font"].c_str(), 12);

	//check that the font loaded
	if (!font) {
		std::ostringstream msg;
		msg << "Failed to load a font file; " << SDL_GetError();
		throw(std::runtime_error(msg.str()));
	}

	//setup the button
	backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
	backButton.SetText(GetRenderer(), font, WHITE, "Back");

	//set the button positions
	backButton.SetX(50);
	backButton.SetY(50);

	//text line
	textLine.SetX(50);
	textLine.SetY(30);
	textLine.SetText(GetRenderer(), font, WHITE, "Am I making any progress?");
}
Esempio n. 8
0
int FLmitkComfortWidget::handle(int event) {
  switch(event) {
    case FL_MOUSEWHEEL:
      if (Fl::event_dy() > 0) {
  sliceCtrl->GetSlice()->Next();
      } else  {
  sliceCtrl->GetSlice()->Previous();
      }
      GetRenderer()->Render();
      draw();
      return 1;
      break;
    case FL_PUSH:
      m_LastX = Fl::event_x();
      m_LastY = Fl::event_y();
      return 1;
      break;
    case FL_DRAG:
      int dx = Fl::event_x() - m_LastX;
      int dy = Fl::event_y() - m_LastY;
      m_LastX = Fl::event_x();
      m_LastY = Fl::event_y();
      mitk::LevelWindow lvlWin;
      if (m_Node.IsNotNull() && m_Node->GetLevelWindow(lvlWin,GetRenderer())) {
  lvlWin.SetLevelWindow(lvlWin.GetLevel() + dy, lvlWin.GetWindow() + dx);
  m_Node->SetLevelWindow(lvlWin,GetRenderer());
  m_Node->SetLevelWindow(lvlWin,NULL);
  GetRenderer()->Render();
  draw();
      }
      return 1;
  }
  return FLmitkRenderWindow::handle(event);
}
Esempio n. 9
0
 BacteroidsState::~BacteroidsState()
 {
     GetRenderer().GetGraphics()->DestroyShaderProgram(m_playerShader);
     GetRenderer().GetGraphics()->DestroyShaderProgram(m_bacterShader);
     GetRenderer().GetGraphics()->DestroyShaderProgram(m_projectileShader);
     GetRenderer().GetGraphics()->DestroyShaderProgram(m_fontShader);
 }
	void VCloudSkySystem::update(const float& timeSinceLastFrame)
	{
		if (!mCreated)
		{
			return;
		}

		GetRenderer()->setShader(mSkydomeShader);

		if (mTimeMultiplier != 0)
		{
			float timemultiplied = timeSinceLastFrame * mTimeMultiplier;

			mTimeOffset += timemultiplied;

			mController->update(timemultiplied);

			if (mStarfield)
			{
				GetApp()->getRenderer()->setShaderConstant1f("uTime", mTimeOffset*0.5f);
			}
		}
				
		GetRenderer()->setShader(mSkydomeShader);
		GetApp()->getRenderer()->setShaderConstant3f("uLightDir", mController->getSunDirection().ToFloatPtr());
		
		mMoonManager->updateMoonPhase(mController->getMoonPhase());
		mCloudsManager->update();
		mVCloudsManager->update(timeSinceLastFrame);
	}
Esempio n. 11
0
	void CloudLayer::_updateInternalPassParameters()
	{
		GetRenderer()->setShader(mSkyX->mCloudShader);
		GetRenderer()->setShaderConstant1f("uExposure", mSkyX->getAtmosphereManager()->getOptions().Exposure);
		GetRenderer()->setShaderConstant1f("uTime", mSkyX->_getTimeOffset()*mOptions.TimeMultiplier);

		float point = (mSkyX->getController()->getSunDirection().y + 1.0f) / 2.0f;
		GetRenderer()->setShaderConstant3f("uSunColor", mSunGradient.getColor(point).ToFloatPtr());
		GetRenderer()->setShaderConstant3f("uAmbientLuminosity", mAmbientGradient.getColor(point).ToFloatPtr());
		
		//mCloudLayerPass->getFragmentProgramParameters()
		//	->setNamedConstant("uExposure", mSkyX->getAtmosphereManager()->getOptions().Exposure);
		//mCloudLayerPass->getFragmentProgramParameters()
		//	->setNamedConstant("uTime", mSkyX->_getTimeOffset()*mOptions.TimeMultiplier);
		/*
		mCloudLayerPass->getFragmentProgramParameters()
			->setNamedConstant("uSunPosition", -mSkyX->getAtmosphereManager()->getSunDirection()*mSkyX->getMeshManager()->getSkydomeRadius());
		
		noVec3 AmbientColor = noVec3::ZERO;

		noVec3 SunDir   = -mSkyX->getAtmosphereManager()->getSunDirection();
		float Ang = 0;
		for (int k = 0; k < 3; k++)
		{
			noVec2 Coords = noVec2(noMath::Cos(Ang), noMath::Sin(Ang));
			Ang += 2*noMath::PI/3;
			AmbientColor += mSkyX->getAtmosphereManager()->getColorAt(noVec3(Coords.x, mOptions.Height/mSkyX->getMeshManager()->getSkydomeRadius(), Coords.y).normalisedCopy());
		}

		AmbientColor /= 3;

		mCloudLayerPass->getFragmentProgramParameters()
			->setNamedConstant("uAmbientLuminosity", AmbientColor*0.75f);

		float Mult = 1.5f;

		mCloudLayerPass->getFragmentProgramParameters()
			->setNamedConstant("uSunColor", noVec3(
			     noMath::Clamp<float>(AmbientColor.x*Mult, 0, 1),
			     noMath::Clamp<float>(AmbientColor.y*Mult, 0, 1),
			     noMath::Clamp<float>(AmbientColor.z*Mult, 0, 1)));
		*/

		//noVec3 SunDir = mSkyX->getAtmosphereManager()->getSunDirection();
		//if (SunDir.y > 0.15f)
		//{
		//	SunDir = -SunDir;
		//}

	//	mCloudLayerPass->getFragmentProgramParameters()
	//		->setNamedConstant("uSunPosition", -SunDir*mSkyX->getMeshManager()->getSkydomeRadius());

		//float point = (mSkyX->getController()->getSunDirection().y + 1.0f) / 2.0f;

		/*mCloudLayerPass->getFragmentProgramParameters()
		->setNamedConstant("uSunColor", mSunGradient.getColor(point));
		mCloudLayerPass->getFragmentProgramParameters()
		->setNamedConstant("uAmbientLuminosity", mAmbientGradient.getColor(point));*/
	}
Esempio n. 12
0
void C3DView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if (GetRenderer())
	{
		GetRenderer()->OnMouseMove(nFlags, point.x, point.y);
		ChangeCursor();
	}
	CView::OnMouseMove(nFlags, point);
}
Esempio n. 13
0
void C3DView::OnRButtonUp(UINT nFlags, CPoint point) 
{
	if (GetRenderer())
	{
		GetRenderer()->OnRButtonUp(nFlags, point.x, point.y);
		ChangeCursor();
	}
	ReleaseCapture();
	CView::OnRButtonUp(nFlags, point);
}
Esempio n. 14
0
void C3DView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	if (GetRenderer())
	{
		GetRenderer()->OnRButtonDown(nFlags, point.x, point.y);
		ChangeCursor();
	}
	SetCapture();
	CView::OnRButtonDown(nFlags, point);
}
Esempio n. 15
0
void RenderFont(char *message,SDL_Rect &rect,TTF_Font *f,SDL_Color *fg)
{
    SDL_Surface * text;
    SDL_Texture * texture;
    text = TTF_RenderText_Solid(f, message , *fg);
    texture = SDL_CreateTextureFromSurface(GetRenderer(),text);
    SDL_QueryTexture(texture,NULL,NULL,&rect.w,&rect.h);
    SDL_RenderCopy(GetRenderer(),texture,NULL,&rect);

}
Esempio n. 16
0
bool SurfaceTextureBuffer::MakeCurrent(uint8 nFace)
{
	// Check whether the data is valid and whether there's a texture buffer
	if (m_cTextureBufferHandler.GetResource() && GetTextureBuffer()) {
		// Set target face
		if (GetTextureBuffer()->GetType() == PLRenderer::Resource::TypeTextureBufferCube)
			m_nFace = nFace;
		else
			m_nFace = 0;

		// Cleanup texture buffer handlers
		for (uint32 i=0; i<m_lstTextureBufferHandler.GetNumOfElements(); i++)
			delete m_lstTextureBufferHandler[i];
		m_lstTextureBufferHandler.Clear();

		// Add primary texture buffer handler
		PLRenderer::ResourceHandler *pTextureBufferHandler = new PLRenderer::ResourceHandler();
		pTextureBufferHandler->SetResource(m_cTextureBufferHandler.GetResource());
		m_lstTextureBufferHandler.Add(pTextureBufferHandler);

		// Frame buffer object used?
		if (m_pFrameBufferObject && m_cTextureBufferHandler.GetResource()) {
			m_pFrameBufferObject->SwitchTarget(static_cast<PLRenderer::TextureBuffer&>(*m_cTextureBufferHandler.GetResource()), 0, nFace);
			m_pFrameBufferObject->Bind();

			// Need rendering to depth only
			PLRenderer::TextureBuffer::EPixelFormat nFormat = GetTextureBuffer()->GetFormat();
			const Extensions &cExtensions = static_cast<Renderer&>(GetRenderer()).GetContext().GetExtensions();
			if (nFormat == PLRenderer::TextureBuffer::D16 || nFormat == PLRenderer::TextureBuffer::D24 || nFormat == PLRenderer::TextureBuffer::D32) {
				// "GL_NV_read_buffer"-extension available?
				if (cExtensions.IsGL_NV_read_buffer())
					glReadBufferNV(GL_NONE);
			} else {
				// "GL_ARB_draw_buffers" & "GL_NV_fbo_color_attachments" extensions available?
				if (cExtensions.IsGL_ARB_draw_buffers() && cExtensions.IsGL_NV_fbo_color_attachments()) {
					// Set draw buffers
					static const GLenum db[16] = { GL_COLOR_ATTACHMENT0_NV, GL_COLOR_ATTACHMENT1_NV, GL_COLOR_ATTACHMENT2_NV, GL_COLOR_ATTACHMENT3_NV,
												   GL_COLOR_ATTACHMENT4_NV, GL_COLOR_ATTACHMENT5_NV, GL_COLOR_ATTACHMENT6_NV, GL_COLOR_ATTACHMENT7_NV,
												   GL_COLOR_ATTACHMENT8_NV, GL_COLOR_ATTACHMENT9_NV, GL_COLOR_ATTACHMENT10_NV, GL_COLOR_ATTACHMENT11_NV,
												   GL_COLOR_ATTACHMENT12_NV, GL_COLOR_ATTACHMENT13_NV, GL_COLOR_ATTACHMENT14_NV, GL_COLOR_ATTACHMENT15_NV};
					glDrawBuffersARB(m_nMaxColorTargets, db);
				}
			}
		}

		// Enable/disable multisample - "shouldn't" have an effect when render to texture, but safe is safe :D
		GetRenderer().SetRenderState(PLRenderer::RenderState::MultisampleEnable, !(GetFlags() & NoMultisampleAntialiasing));

		// Done
		return true;
	}

	// Error!
	return false;
}
Esempio n. 17
0
//[-------------------------------------------------------]
//[ Private virtual PLRenderer::TextureBuffer functions   ]
//[-------------------------------------------------------]
bool TextureBuffer2DArray::MakeCurrent(uint32 nStage)
{
	// Check if there are renderer information
	if (GetRenderer().GetTextureBuffer(nStage) != this) {
		if (!GetRenderer().SetTextureBuffer(nStage, this))
			return true; // Done
	}

	// Done
	return true;
}
Esempio n. 18
0
RenderView3D::RenderView3D( QWidget* parent ) : RenderView( parent )
{
  this->GetRenderWindow()->GetInteractor()->SetDesiredUpdateRate(30);
  this->GetRenderWindow()->GetInteractor()->SetStillUpdateRate(0.01);

 GetRenderWindow()->SetAlphaBitPlanes(0);
 GetRenderWindow()->SetMultiSamples(0);
 GetRenderer()->SetUseDepthPeeling(true);
 GetRenderer()->SetMaximumNumberOfPeels(4);
 GetRenderer()->SetOcclusionRatio(0);

  m_bShowSliceFrames = true;
  m_bShowAxes = true;
  for ( int i = 0; i < 3; i++ )
  {
    m_actorSliceFrames[i] = vtkSmartPointer<vtkActor>::New();
    m_actorSliceFrames[i]->SetMapper( vtkSmartPointer<vtkPolyDataMapper>::New() );
    m_actorSliceFrames[i]->GetProperty()->SetRepresentationToWireframe();
    m_actorSliceFrames[i]->GetProperty()->SetDiffuse( 0.0 );
    m_actorSliceFrames[i]->GetProperty()->SetAmbient( 1.0 );
    m_bSliceVisibility[i] = true;

    m_actorSliceBoundingBox[i] = vtkSmartPointer<vtkActor>::New();
    m_cubeSliceBoundingBox[i] = vtkSmartPointer<vtkCubeSource>::New();
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection( m_cubeSliceBoundingBox[i]->GetOutputPort() );
    m_actorSliceBoundingBox[i]->SetMapper( mapper );
    mapper->Update();
    m_actorSliceBoundingBox[i]->GetProperty()->SetRepresentationToWireframe();
  }
  HighlightSliceFrame( -1 );

  m_cursor3D = new Cursor3D( this );
  m_interactorNavigate = new Interactor3DNavigate( this );
  m_interactorMeasure = new Interactor3DMeasure( this );
  m_interactorVolumeCrop = new Interactor3DVolumeCrop(this);
  connect(m_cursor3D, SIGNAL(Updated()), this, SLOT(RequestRedraw()));

  m_actorScalarBar->SetNumberOfLabels( 4 );

  m_actorAxesActor = vtkSmartPointer<vtkCubeAxesActor>::New();
  m_actorAxesActor->XAxisLabelVisibilityOn();
  m_actorAxesActor->YAxisLabelVisibilityOn();
  m_actorAxesActor->ZAxisLabelVisibilityOn();
  m_actorAxesActor->SetXTitle("");
  m_actorAxesActor->SetYTitle("");
  m_actorAxesActor->SetZTitle("");
  m_actorAxesActor->SetFlyModeToClosestTriad();
  m_actorAxesActor->SetCamera(m_renderer->GetActiveCamera());


  SetInteractionMode(IM_Navigate);
}
Esempio n. 19
0
void QmitkSliceWidget::InitWidget(mitk::SliceNavigationController::ViewDirection viewDirection)
{
  m_View = viewDirection;

  mitk::SliceNavigationController *controller = m_RenderWindow->GetSliceNavigationController();

  if (viewDirection == mitk::SliceNavigationController::Axial)
  {
    controller->SetViewDirection(mitk::SliceNavigationController::Axial);
  }
  else if (viewDirection == mitk::SliceNavigationController::Frontal)
  {
    controller->SetViewDirection(mitk::SliceNavigationController::Frontal);
  }
  // init sagittal view
  else
  {
    controller->SetViewDirection(mitk::SliceNavigationController::Sagittal);
  }

  if (m_SlicedGeometry.IsNull())
  {
    return;
  }

  mitk::BaseGeometry::Pointer geometry = static_cast<mitk::BaseGeometry *>(m_SlicedGeometry->Clone().GetPointer());

  const mitk::BoundingBox::Pointer boundingbox = m_DataStorage->ComputeVisibleBoundingBox(GetRenderer(), nullptr);

  if (boundingbox->GetPoints()->Size() > 0)
  {
    // let's see if we have data with a limited live-span ...
    mitk::TimeBounds timebounds = m_DataStorage->ComputeTimeBounds(GetRenderer(), nullptr);

    mitk::ProportionalTimeGeometry::Pointer timeGeometry = mitk::ProportionalTimeGeometry::New();
    timeGeometry->Initialize(geometry, 1);

    {
      timeGeometry->SetFirstTimePoint(timebounds[0]);
      timeGeometry->SetStepDuration(1.0);
    }

    if (timeGeometry->GetBoundingBoxInWorld()->GetDiagonalLength2() >= mitk::eps)
    {
      controller->SetInputWorldTimeGeometry(timeGeometry);
      controller->Update();
    }
  }

  GetRenderer()->GetCameraController()->Fit();
  mitk::RenderingManager::GetInstance()->RequestUpdate(GetRenderer()->GetRenderWindow());
}
Esempio n. 20
0
void Game::Init(const std::map<std::string, std::string>& options)
{
	//register filthy global (for lua api)
	p3::game = this;

	OS::NotifyLoadBegin();
	FileSystem::Init();
	FileSystem::userFiles.MakeDirectory(""); // ensure the config directory exists
	m_config.reset(new GameConfig(options));
	if (m_config->Int("RedirectStdio"))
		OS::RedirectStdio();
	KeyBindings::InitBindings();
	ModManager::Init();
	Lang::Resource res(Lang::GetResource("core", GetConfig()->String("Lang")));
	Lang::MakeCore(res);
	Uint32 sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
#if defined(DEBUG) || defined(_DEBUG)
	sdlInitFlags |= SDL_INIT_NOPARACHUTE;
#endif
	if (SDL_Init(sdlInitFlags) < 0)
		Error("SDL initialization failed: %s\n", SDL_GetError());

	m_rng.seed(time(0));

	Graphics::Settings vs = ReadVideoSettings(GetConfig());
	vs.title = "P3";
	m_renderer.reset(Graphics::Init(vs));

	EnumStrings::Init();

	Lua::Init();

	m_ui.Reset(new UI::Context(Lua::manager,
	                           GetRenderer(),
	                           GetRenderer()->GetWindow()->GetWidth(),
	                           GetRenderer()->GetWindow()->GetHeight()));

	InitLua();

	m_modelCache.reset(new ModelCache(GetRenderer()));

	//init some graphics
	LaserBoltGraphic::InitResources(GetRenderer());

	Galaxy::Init();

	m_console.reset(new LuaConsole(GetUI()));
	KeyBindings::toggleLuaConsole.onPress.connect(sigc::mem_fun(m_console.get(), &LuaConsole::Toggle));

	OS::NotifyLoadEnd();
}
Esempio n. 21
0
//-----------------------------------------------------------------------------
void AdScreen::Present(void) {
    int pitch;
    void* pixels;

    SDL_LockTexture(s_pTexture, NULL, &pixels, &pitch);

    SDL_ConvertPixels(
        s_pScreen->w,
        s_pScreen->h,
        s_pScreen->format->format,
        s_pScreen->pixels,
        s_pScreen->pitch,
        SDL_PIXELFORMAT_RGBA8888,
        pixels, pitch
    );

    SDL_UnlockTexture(s_pTexture);

    SDL_RenderCopy(GetRenderer(), s_pTexture, NULL, NULL);
    SDL_RenderPresent(GetRenderer());

    s_iFrames++;

    s_uiCurrentCount = SDL_GetPerformanceCounter();
    s_uiDiffCount    = (s_uiCurrentCount-s_uiLastCount);
    s_uiCountFreq    = SDL_GetPerformanceFrequency();

    s_fElapsedTime = ((float) s_uiDiffCount/(float) s_uiCountFreq);

    if((1.0f/60.0f)-s_fElapsedTime > 0) {
        // NOTE: without this there seems to be a more consistent framerate
        // but on older computers sometimes the vsync doesn't work right
        //SDL_Delay((uint32_t) (1000.0f*((1.0f/60.0f)-s_fElapsedTime)));

        s_fTotTime += 1.0f/60.0f;
    } else {
        s_fTotTime += s_fElapsedTime;
    }

    s_uiLastCount = s_uiCurrentCount;

    if(s_fTotTime >= 1.0f) {
        char strTitle[0x20] = "";
        sprintf(strTitle, "%s, FPS: %d", WINDOW_TITLE, s_iFrames);

        SDL_SetWindowTitle(GetWindow(), strTitle);

        s_fTotTime  = 0;
        s_iFrames = 0;
    }
}
Esempio n. 22
0
vtkRenderer * View::GetRenderer( int level )
{
    Q_ASSERT( level <= 2 );

    if( level == 0 )
        return GetRenderer();
    if( level == 1 )
        return GetOverlayRenderer();
    if( level == 2 )
        return GetOverlayRenderer2();

    // Just in case
    return GetRenderer();
}
Esempio n. 23
0
void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
{
    wxDouble rw = w/2;
    wxDouble rh = h/2;
    wxDouble xc = x + rw;
    wxDouble yc = y + rh;
    wxGraphicsMatrix m = GetRenderer()->CreateMatrix();
    m.Translate(xc,yc);
    m.Scale(rw/rh,1.0);
    wxGraphicsPath p = GetRenderer()->CreatePath();
    p.AddCircle(0,0,rh);
    p.Transform(m);
    AddPath(p.GetPathData());
}
//-----------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------
void Shader::SetConstantBuffer()
{
    if (m_vertexRegisterCount > 0)
    {
        GetRenderer()->GetContext()->UpdateSubresource( m_constantBufferToVS, 0, NULL, m_vertexConstantBuffer, 0, 0 );
        GetRenderer()->GetContext()->VSSetConstantBuffers(0, 1, &m_constantBufferToVS);
    }

    if (m_pixelRegisterCount > 0)
    {
        GetRenderer()->GetContext()->UpdateSubresource( m_constantBufferToPS, 0, NULL, m_pixelConstantBuffer, 0, 0 );
        GetRenderer()->GetContext()->PSSetConstantBuffers(0, 1, &m_constantBufferToPS);
    }
}
Esempio n. 25
0
void WindowWin32::Initialize()
{
    HINSTANCE hInstance = Win32::GetAppInstance();

    WinClassMaker wcm(hInstance, MY_WNDCLS_NAME, WndProc);
    wcm.Register();

    WinMaker wm(hInstance, MY_WNDCLS_NAME);
    wm.SetSize(m_iWidth, m_iHeight);
    m_hWnd = wm.Create(m_sTitle.c_str(), this);

    // init renderer
    if (GetRenderer().get())
        GetRenderer()->Initialize(this);
}
Esempio n. 26
0
//-----------------------------------------------------------------------------
bool AdScreen::Init(void) {
    s_pScreen = SDL_CreateRGBSurface(
                    0, s_iWinWidth, s_iWinHeight,
                    32, 0x00, 0x00, 0x00, 0x00
                );

    if(s_pScreen == NULL) {
        fprintf(stderr, SDL_GetError());
        return false;
    }

    s_pTexture = SDL_CreateTexture(
                     GetRenderer(),
                     SDL_PIXELFORMAT_RGBA8888,
                     SDL_TEXTUREACCESS_STREAMING,
                     s_pScreen->w,
                     s_pScreen->h
                 );

    if(s_pTexture == NULL) {
        fprintf(stderr, SDL_GetError());
        return false;
    }

    return true;
}
Esempio n. 27
0
/**
*  @brief
*    Sets a color render target
*/
void SurfaceTextureBuffer::SetColorRenderTarget(uint8 nColorIndex, PLRenderer::TextureBuffer *pTextureBuffer)
{
	// Check color index
	if (nColorIndex < m_nMaxColorTargets) {
		// Set color render target
		while (!m_lstTextureBufferHandler[nColorIndex]) {
			PLRenderer::ResourceHandler *pTextureBufferHandler = new PLRenderer::ResourceHandler();
			m_lstTextureBufferHandler.Add(pTextureBufferHandler);
		}
		PLRenderer::ResourceHandler *pTextureBufferHandler = m_lstTextureBufferHandler[nColorIndex];
		pTextureBufferHandler->SetResource(pTextureBuffer);

		// Check FBO
		if (m_pFrameBufferObject && pTextureBuffer) {
			m_pFrameBufferObject->Bind();
			m_pFrameBufferObject->SwitchTarget(*pTextureBuffer, nColorIndex);

			// "GL_ARB_draw_buffers" & "GL_NV_fbo_color_attachments" extensions available?
			const Extensions &cExtensions = static_cast<Renderer&>(GetRenderer()).GetContext().GetExtensions();
			if (cExtensions.IsGL_ARB_draw_buffers() && cExtensions.IsGL_NV_fbo_color_attachments()) {
				// Set draw buffers
				static const GLenum db[16] = { GL_COLOR_ATTACHMENT0_NV, GL_COLOR_ATTACHMENT1_NV, GL_COLOR_ATTACHMENT2_NV, GL_COLOR_ATTACHMENT3_NV,
											   GL_COLOR_ATTACHMENT4_NV, GL_COLOR_ATTACHMENT5_NV, GL_COLOR_ATTACHMENT6_NV, GL_COLOR_ATTACHMENT7_NV,
											   GL_COLOR_ATTACHMENT8_NV, GL_COLOR_ATTACHMENT9_NV, GL_COLOR_ATTACHMENT10_NV, GL_COLOR_ATTACHMENT11_NV,
											   GL_COLOR_ATTACHMENT12_NV, GL_COLOR_ATTACHMENT13_NV, GL_COLOR_ATTACHMENT14_NV, GL_COLOR_ATTACHMENT15_NV};
				glDrawBuffersARB(m_nMaxColorTargets, db);
			}
		}
	}
}
Esempio n. 28
0
/**
*  @brief
*    Destructor
*/
VertexBuffer::~VertexBuffer()
{
	Clear();

	// Update renderer statistics
	static_cast<PLRenderer::RendererBackend&>(GetRenderer()).GetWritableStatistics().nVertexBufferNum--;
}
Esempio n. 29
0
void *VertexBuffer::Lock(uint32 nFlag)
{
	// Check whether there's a vertex buffer
	if (!m_pData)
		return nullptr; // Error!

	// Check whether the vertex buffer is already locked
	m_nLockCount++;
	if (m_pLockedData)
		return m_pLockedData; // Return the locked data

	// Check if there's an vertex buffer or the data is already locked
	if (m_pLockedData || !m_pData)
		return nullptr; // Error!

	// Read only?
	m_bLockReadOnly = (nFlag == PLRenderer::Lock::ReadOnly);

	// Lock the vertex buffer
	static_cast<PLRenderer::RendererBackend&>(GetRenderer()).GetWritableStatistics().nVertexBufferLocks++;
	m_nLockStartTime = System::GetInstance()->GetMicroseconds();
	m_pLockedData = m_pData;

	// Return the vertex buffer data
	return m_pLockedData;
}
Esempio n. 30
0
bool VertexBuffer::Clear()
{
	if (!IsAllocated())
		return false; // Error!
	ForceUnlock();
	if (m_pD3D11Buffer) {
		m_pD3D11Buffer->Release();
		m_pD3D11Buffer = nullptr;
	}
	m_bLockReadOnly = m_bUpdateVBO = false;
	if (m_pData) {
		delete [] m_pData;
		m_pData = nullptr;
	} else {
		// Error!
		return false;
	}

	// Update renderer statistics
	static_cast<PLRenderer::RendererBackend&>(GetRenderer()).GetWritableStatistics().nVertexBufferMem -= m_nSize;

	// Init
	m_nElements = 0;
	m_nSize     = 0;
	m_nUsage    = PLRenderer::Usage::Unknown;
	MemoryManager::Set(m_nOffset, -1, sizeof(int)*NumOfSemantics*MaxPipelineChannels);

	// Done
	return true;
}