Example #1
0
VOID Render()
{
	SetupMatrix() ;

	OnFrameMove() ;

	g_pCamera->Update(0.1f, 1.0f) ;

	// Clear the back-buffer to a RED color
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		RenderTerrain() ;

		RenderTree() ;

		RenderTeapot() ;

		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #2
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr = S_OK;

    float ClearColor[4] = { 0,0,0,0 };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Render the scene
    {
        D3DXVECTOR4 vLightDir( -1,1,-1,1 );
        D3DXVec4Normalize( &vLightDir, &vLightDir );
        g_pvWorldLightDir->SetFloatVector( ( float* )&vLightDir );
        g_pfTime->SetFloat( ( float )fTime );
        g_pfElapsedTime->SetFloat( fElapsedTime );

        VisibilityCullTiles();

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Sky" );
        RenderSky( pd3dDevice );
        DXUT_EndPerfEvent();

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Terrain" );
        RenderTerrain( pd3dDevice );
        DXUT_EndPerfEvent();

        if( g_bRenderBalls )
        {
            DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Balls" );
            RenderBalls( pd3dDevice );
            DXUT_EndPerfEvent();
        }

        if( g_bRenderGrass )
        {
            DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Grass" );
            RenderGrass( pd3dDevice );
            DXUT_EndPerfEvent();
        }
		
        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        DXUT_EndPerfEvent();
    }
}
Example #3
0
void DirectxEngine::RenderSceneMap(const IScene& scene, float timer)
{
    m_data->sceneTarget.SetActive(m_data->context);

    RenderTerrain(scene);
    RenderShadows();
    RenderMeshes(scene);
    RenderWater(scene, timer);
    RenderEmitters(scene);
}
	RenderContextType SelectRenderContext(CoreState* state)
    {
        if (state->render_state->m_render_depth)
            return RenderDepth(state);
        else if (state->render_state->m_enable_terrain)
            return RenderTerrain(state);
        else if (state->render_state->m_enable_lighting)
            return RenderLighting(state);
        else	//	NO LIGHTING
            return RenderSolid(state);
		return RenderContextType::NoRender;
    }
void OBBMeshQuery::PerformTest()
{
	RenderTerrain();

	Matrix3x3 MX,MY,MZ;
	RotX(MX, mAngleX);
	RotY(MY, mAngleY);
	RotY(MZ, mAngleZ);
	mBox.mRot = MX * MY * MZ;

	DrawOBB(mBox);

	const Model* TM = GetTerrainModel();
	if(TM)
	{
		OBBCollider Collider;
		mSettings.SetupCollider(Collider);

		mProfiler.Start();
		bool Status = Collider.Collide(mCache, mBox, *TM, null, null);
		mProfiler.End();
		mProfiler.Accum();

		if(Status)
		{
			if(Collider.GetContactStatus())
			{
				udword NbTris = Collider.GetNbTouchedPrimitives();
				const udword* Indices = Collider.GetTouchedPrimitives();

				RenderTerrainTriangles(NbTris, Indices);
			}
		}
	}

	// Raycast hit
	if(mValidHit)
	{
		Point wp = mLocalHit + mBox.mCenter;
		DrawLine(wp, wp + Point(1.0f, 0.0f, 0.0f), Point(1,0,0), 1.0f);
		DrawLine(wp, wp + Point(0.0f, 1.0f, 0.0f), Point(0,1,0), 1.0f);
		DrawLine(wp, wp + Point(0.0f, 0.0f, 1.0f), Point(0,0,1), 1.0f);
	}

	char Buffer[4096];
	sprintf(Buffer, "OBB-mesh query = %5.1f us (%d cycles)\n", mProfiler.mMsTime, mProfiler.mCycles);
	GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
}
Example #6
0
void
TargetMapWindow::OnPaintBuffer(Canvas &canvas)
{
#ifdef ENABLE_OPENGL
  /* enable clipping */
  GLCanvasScissor scissor(canvas);
#endif

  // Calculate screen position of the aircraft
  const auto aircraft_pos = projection.GeoToScreen(Basic().location);

  // reset label over-write preventer
  label_block.reset();

  // Render terrain, groundline and topography
  RenderTerrain(canvas);
  RenderTopography(canvas);

  // Render airspace
  RenderAirspace(canvas);

#ifdef ENABLE_OPENGL
  /* desaturate the map background, to focus on the task */
  canvas.FadeToWhite(0x80);
#endif

  // Render task, waypoints
  DrawTask(canvas);
  DrawWaypoints(canvas);

  // Render the snail trail
  RenderTrail(canvas);

  // Render topography on top of airspace, to keep the text readable
  RenderTopographyLabels(canvas);

  // Finally, draw you!
  if (Basic().alive)
    AircraftRenderer::Draw(canvas, GetMapSettings(), aircraft_look,
                           Basic().attitude.heading - projection.GetScreenAngle(),
                           aircraft_pos);

  RenderMapScale(canvas, projection, GetClientRect(), overlay_look);
}
void CapsuleMeshQuery::PerformTest()
{
    RenderTerrain();

    mCapsule.mP0 = mP0 * mWorld;
    mCapsule.mP1 = mP1 * mWorld;
    mCapsule.mRadius = 1.0f;
    DrawCapsule(mWorld, mP0, mP1, 1.0f);

    const Model* TM = GetTerrainModel();
    if(TM)
    {
        LSSCollider Collider;

        mProfiler.Start();
        bool Status = Collider.Collide(mCache, mCapsule, *TM, null, null);
        mProfiler.End();
        mProfiler.Accum();

        if(Status)
        {
            if(Collider.GetContactStatus())
            {
                udword NbTris = Collider.GetNbTouchedPrimitives();
                const udword* Indices = Collider.GetTouchedPrimitives();

                RenderTerrainTriangles(NbTris, Indices);
            }
        }
    }

    // Raycast hit
    if(mValidHit)
    {
        Point wp = mLocalHit + (Point)mWorld.GetTrans();
        DrawLine(wp, wp + Point(1.0f, 0.0f, 0.0f), Point(1,0,0), 1.0f);
        DrawLine(wp, wp + Point(0.0f, 1.0f, 0.0f), Point(0,1,0), 1.0f);
        DrawLine(wp, wp + Point(0.0f, 0.0f, 1.0f), Point(0,0,1), 1.0f);
    }

    char Buffer[4096];
    sprintf(Buffer, "Capsule-mesh query = %5.1f us (%d cycles)\n", mProfiler.mMsTime, mProfiler.mCycles);
    GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
}
Example #8
0
void render()
{
	static Timer t;
	if(gScene && !gPauseSimulation)  //start the simulation
	{
		gTouchedTris.clear();
		gScene->simulate(t.elapsed_time());
		//printf("%f\n",t.elapsed_time());
		t.reset();
		gScene->flushStream();
		/*ASYNC: in here we can do computations which depend only on the old
	      state of the scene "actors". Writing to the scene is not allowed.
		  Write calls in here are skipped.
		*/
		gScene->fetchResults(NX_RIGID_BODY_FINISHED,true);
	}
	// Clear buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glColor4f(0.0,1.0,1.0,1.0);
	DrawSkyBox(5000.0f);
	//drawPlane(2000.0);
	 //Render all actors
	int nbActors = gScene->getNbActors();
	NxActor** actors = gScene->getActors();
	while(nbActors--)
	{
		NxActor* actor = *actors++;
		if(!actor->userData) continue;

		// Render actor
		glPushMatrix();
		float glMat[16];
		actor->getGlobalPose().getColumnMajor44(glMat);
		glMultMatrixf(glMat);
		NxVec3 color = static_cast<UserData*>(actor->userData)->color;
		glColor4f(color.x,color.y,color.z,1.0f);
		glutSolidCube((static_cast<UserData*>(actor->userData)->size)*2.0f);
		glPopMatrix();
	}
	RenderTerrain();
}
void RenderFrame()
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    glViewport(0, 0, g_windowWidth, g_windowHeight);
    glClearColor(0.3f, 0.5f, 0.9f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMultMatrixf(&g_camera.getProjectionMatrix()[0][0]);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glMultMatrixf(&g_camera.getViewMatrix()[0][0]);

    RenderTerrain();
    RenderText();
}
Example #10
0
void
TargetMapWindow::on_paint_buffer(Canvas &canvas)
{
#ifdef ENABLE_OPENGL
  /* enable clipping */
  GLCanvasScissor scissor(canvas);
#endif

  // Calculate screen position of the aircraft
  const RasterPoint aircraft_pos = projection.GeoToScreen(Basic().location);

  // reset label over-write preventer
  label_block.reset();

  // Render terrain, groundline and topography
  RenderTerrain(canvas);
  RenderTopography(canvas);

  // Render airspace
  RenderAirspace(canvas);

  // Render task, waypoints
  DrawTask(canvas);
  DrawWaypoints(canvas);

  // Render the snail trail
  RenderTrail(canvas);

  // Render topography on top of airspace, to keep the text readable
  RenderTopographyLabels(canvas);

  // Finally, draw you!
  if (Basic().connected)
    AircraftRenderer::Draw(canvas, SettingsMap(), aircraft_look,
                           Calculated().heading - projection.GetScreenAngle(),
                           aircraft_pos);
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void RenderToBackBuffer(Renderer* renderer, double fTime, float fElapsedTime, void* pUserContext)
{
	ID3D11DeviceContext* pContext =  GetApp()->GetContext();
	
	// Something's wrong in the shader and the tri size is out by a factor of 2.  Why?!?
	g_pTriSizeVar->SetInt(2 * g_tessellatedTriWidth);

	const bool debugDrawPatches = false;
	g_DebugShowPatchesVar->SetBool(debugDrawPatches);

	const bool debugDrawTiles = false;
	g_DebugShowTilesVar->SetBool(debugDrawTiles);

	const float wireAlpha = 0.01f * (float)80;

	// Below 1.0, we fade the lines out with blending; above 1, we increase line thickness.
	if (wireAlpha < 1)
	{
		g_WireAlphaVar->SetFloat(wireAlpha);
		g_WireWidthVar->SetFloat(1);
	}
	else
	{
		g_WireAlphaVar->SetFloat(1);
		g_WireWidthVar->SetFloat(wireAlpha);
	}

	g_DetailNoiseVar->SetFloat(0.001f * (float)g_DetailNoiseScale);

	float samplesapcing = WORLD_SCALE * g_pTileRings[g_nRings-1]->outerWidth() / (float) COARSE_HEIGHT_MAP_SIZE;
	g_SampleSpacingVar->SetFloat(samplesapcing);

	// If the settings dialog is being shown, then render it instead of rendering the app's scene		

	BaseCamera* pCam = GetApp()->ActiveCam_;
	D3DXMATRIX mProj;
	D3DXMATRIX mView;

	const unsigned int size16 = sizeof(float) * 16;		 
	memcpy(&mView, pCam->getViewMatrix(), size16);
	memcpy(&mProj, pCam->getProjectionMatrix(), size16);


	SetViewport(pContext, g_BackBufferVP);

	D3DXMATRIX mViewCopy = mView;
	mViewCopy._41 = mViewCopy._42 = mViewCopy._43 = 0;
	D3DXMATRIX mWVP = StarWorldMatrix() * mViewCopy * mProj;
	if (!g_CheckForCracks)
		g_Skybox.D3D11Render(&mWVP, pContext);

	RenderStars(pContext, mViewCopy, mProj, g_ScreenSize);

	int vec[3] = { g_RidgeOctaves, g_fBmOctaves, g_TexTwistOctaves };
	g_pFractalOctavesTVar->SetIntVector(vec);

	// I'm still trying to figure out if the detail scale can be derived from any combo of ridge + twist.
	// I don't think this works well (nor does ridge+twist+fBm).  By contrast the relationship with fBm is
	// straightforward.  The -4 is a fudge factor that accounts for the frequency of the coarsest ocatve
	// in the pre-rendered detail map.
	const float DETAIL_UV_SCALE = powf(2.0f, std::max(g_RidgeOctaves, g_TexTwistOctaves) + g_fBmOctaves - 4.0f);
	g_DetailUVVar->SetFloatVector(D3DXVECTOR2(DETAIL_UV_SCALE, 1.0f/DETAIL_UV_SCALE));

	SetUVOffset(g_pUVOffsetTVar);

	/*ID3D11Query* pFreeQuery = FindFreeQuery();
	if (pFreeQuery)
		pContext->Begin(pFreeQuery);*/
		
	RenderTerrain(pContext, mProj, g_BackBufferVP);

	//if (pFreeQuery)
	//	pContext->End(pFreeQuery);

	//for (int i=0; i!=N_QUERIES; ++i)
	//{
	//	if (!g_FreePipelineQueries[i] && g_PipelineQueries[i])	// in use & exists
	//	{
	//		D3D11_QUERY_DATA_PIPELINE_STATISTICS stats;
	//		if (S_OK == pContext->GetData(g_PipelineQueries[i], &stats, sizeof(stats), D3D11_ASYNC_GETDATA_DONOTFLUSH))
	//		{
	//			g_PrimitivesRendered = stats.CInvocations;
	//			g_FreePipelineQueries[i] = g_PipelineQueries[i];	// Put back on free list.
	//		}
	//	}
	//}		
}
Example #12
0
void
MapWindow::Render(Canvas &canvas, const PixelRect &rc)
{ 
  const NMEAInfo &basic = Basic();

  // reset label over-write preventer
  label_block.reset();

  render_projection = visible_projection;

  if (!render_projection.IsValid()) {
    canvas.ClearWhite();
    return;
  }

  // Calculate screen position of the aircraft
  RasterPoint aircraft_pos{0,0};
  if (basic.location_available)
      aircraft_pos = render_projection.GeoToScreen(basic.location);

  // Render terrain, groundline and topography
  draw_sw.Mark("RenderTerrain");
  RenderTerrain(canvas);

  draw_sw.Mark("RenderTopography");
  RenderTopography(canvas);

  draw_sw.Mark("RenderFinalGlideShading");
  RenderFinalGlideShading(canvas);

  // Render track bearing (ground track)
  draw_sw.Mark("DrawTrackBearing");
  DrawTrackBearing(canvas, aircraft_pos);

  // Render airspace
  draw_sw.Mark("RenderAirspace");
  RenderAirspace(canvas);

  // Render task, waypoints
  draw_sw.Mark("DrawContest");
  DrawContest(canvas);

  draw_sw.Mark("DrawTask");
  DrawTask(canvas);

  draw_sw.Mark("DrawWaypoints");
  DrawWaypoints(canvas);

  draw_sw.Mark("DrawNOAAStations");
  RenderNOAAStations(canvas);

  draw_sw.Mark("RenderMisc1");
  // Render weather/terrain max/min values
  DrawTaskOffTrackIndicator(canvas);

  // Render the snail trail
  if (basic.location_available)
    RenderTrail(canvas, aircraft_pos);

  RenderMarkers(canvas);

  // Render estimate of thermal location
  DrawThermalEstimate(canvas);

  // Render topography on top of airspace, to keep the text readable
  draw_sw.Mark("RenderTopographyLabels");
  RenderTopographyLabels(canvas);

  // Render glide through terrain range
  draw_sw.Mark("RenderGlide");
  RenderGlide(canvas);

  draw_sw.Mark("RenderMisc2");

  DrawBestCruiseTrack(canvas, aircraft_pos);

  airspace_renderer.DrawIntersections(canvas, render_projection);

  // Draw wind vector at aircraft
  if (basic.location_available)
    DrawWind(canvas, aircraft_pos, rc);

  // Draw traffic

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  DrawSkyLinesTraffic(canvas);
#endif

  DrawTeammate(canvas);

  if (basic.location_available)
    DrawFLARMTraffic(canvas, aircraft_pos);

  // Finally, draw you!
  if (basic.location_available)
    AircraftRenderer::Draw(canvas, GetMapSettings(), look.aircraft,
                           basic.attitude.heading - render_projection.GetScreenAngle(),
                           aircraft_pos);

  // Render compass
  DrawCompass(canvas, rc);
}
Example #13
0
void
MapWindow::Render(Canvas &canvas, const PixelRect &rc)
{ 
  render_projection = visible_projection;

  // Calculate screen position of the aircraft
  const RasterPoint aircraft_pos =
      render_projection.GeoToScreen(Basic().Location);

  // reset label over-write preventer
  label_block.reset();

  // Render terrain, groundline and topography
  RenderTerrain(canvas);
  RenderTopography(canvas);
  RenderFinalGlideShading(canvas);

  // Render track bearing (ground track)
  DrawTrackBearing(canvas, aircraft_pos);

  // Render airspace
  RenderAirspace(canvas);

  // Render task, waypoints
  DrawTask(canvas);
  DrawWaypoints(canvas);

  // Render weather/terrain max/min values
  if (!m_background.DrawSpotHeights(canvas, label_block))
    DrawTaskOffTrackIndicator(canvas);

  // Render the snail trail
  RenderTrail(canvas, aircraft_pos);

  RenderMarks(canvas);

  // Render estimate of thermal location
  DrawThermalEstimate(canvas);

  // Render topography on top of airspace, to keep the text readable
  RenderTopographyLabels(canvas);

  // Render glide through terrain range
  RenderGlide(canvas);

  DrawBestCruiseTrack(canvas, aircraft_pos);

  DrawAirspaceIntersections(canvas);

  // Draw wind vector at aircraft
  DrawWind(canvas, aircraft_pos, rc);

  // Draw traffic
  DrawTeammate(canvas);
  DrawFLARMTraffic(canvas, aircraft_pos);

  // Finally, draw you!
  if (Basic().Connected)
    Graphics::DrawAircraft(canvas, settings_map,
                           Calculated().Heading - render_projection.GetScreenAngle(),
                           aircraft_pos);

  // Render compass
  DrawCompass(canvas, rc);
}
Example #14
0
void
MapWindow::Render(Canvas &canvas, const PixelRect &rc)
{
  const NMEAInfo &basic = Basic();

  // reset label over-write preventer
  label_block.reset();

  render_projection = visible_projection;

  if (!render_projection.IsValid()) {
    canvas.ClearWhite();
    return;
  }

  // Calculate screen position of the aircraft
  PixelPoint aircraft_pos{0,0};
  if (basic.location_available)
      aircraft_pos = render_projection.GeoToScreen(basic.location);

  // General layout principles:
  // - lower elevation drawn on bottom layers
  // - increasing elevation drawn above
  // - increasing importance drawn above
  // - attempt to not obscure text

  //////////////////////////////////////////////// items on ground

  // Render terrain, groundline and topography
  draw_sw.Mark("RenderTerrain");
  RenderTerrain(canvas);

  draw_sw.Mark("RenderRasp");
  RenderRasp(canvas);

  draw_sw.Mark("RenderTopography");
  RenderTopography(canvas);

  draw_sw.Mark("RenderOverlays");
  RenderOverlays(canvas);

  draw_sw.Mark("DrawNOAAStations");
  RenderNOAAStations(canvas);

  //////////////////////////////////////////////// glide range info

  draw_sw.Mark("RenderFinalGlideShading");
  RenderFinalGlideShading(canvas);

  //////////////////////////////////////////////// airspace

  // Render airspace
  draw_sw.Mark("RenderAirspace");
  RenderAirspace(canvas);

  //////////////////////////////////////////////// task

  // Render task, waypoints
  draw_sw.Mark("DrawContest");
  DrawContest(canvas);

  draw_sw.Mark("DrawTask");
  DrawTask(canvas);

  draw_sw.Mark("DrawWaypoints");
  DrawWaypoints(canvas);

  //////////////////////////////////////////////// aircraft level items
  // Render the snail trail
  if (basic.location_available)
    RenderTrail(canvas, aircraft_pos);

  DrawWaves(canvas);

  // Render estimate of thermal location
  DrawThermalEstimate(canvas);

  //////////////////////////////////////////////// text items
  // Render topography on top of airspace, to keep the text readable
  draw_sw.Mark("RenderTopographyLabels");
  RenderTopographyLabels(canvas);

  //////////////////////////////////////////////// navigation overlays
  // Render glide through terrain range
  draw_sw.Mark("RenderGlide");
  RenderGlide(canvas);

  draw_sw.Mark("RenderMisc1");
  // Render weather/terrain max/min values
  DrawTaskOffTrackIndicator(canvas);

  // Render track bearing (projected track ground/air relative)
  draw_sw.Mark("DrawTrackBearing");
  RenderTrackBearing(canvas, aircraft_pos);

  draw_sw.Mark("RenderMisc2");
  DrawBestCruiseTrack(canvas, aircraft_pos);

  // Draw wind vector at aircraft
  if (basic.location_available)
    DrawWind(canvas, aircraft_pos, rc);

  // Render compass
  DrawCompass(canvas, rc);

  //////////////////////////////////////////////// traffic
  // Draw traffic

#ifdef HAVE_SKYLINES_TRACKING
  DrawSkyLinesTraffic(canvas);
#endif

  DrawTeammate(canvas);

  if (basic.location_available)
    DrawFLARMTraffic(canvas, aircraft_pos);

  //////////////////////////////////////////////// own aircraft
  // Finally, draw you!
  if (basic.location_available)
    AircraftRenderer::Draw(canvas, GetMapSettings(), look.aircraft,
                           basic.attitude.heading - render_projection.GetScreenAngle(),
                           aircraft_pos);

  //////////////////////////////////////////////// important overlays
  // Draw intersections on top of aircraft
  airspace_renderer.DrawIntersections(canvas, render_projection);
}