Ejemplo n.º 1
0
/**
 * Enables drawing of the logo.
 * If you want to disable it, call the Disable() function.
 */
void mitk::ManufacturerLogo::Enable()
{
  if(m_IsEnabled)
    return;

  if(m_RenderWindow != NULL)
  {
    if(itksys::SystemTools::FileExists(m_FileName.c_str()) && !m_ForceShowMBIDepartmentLogo)
    {
      m_PngReader->Update();
      m_Actor->SetInput(m_PngReader->GetOutput());
    }
    else // either logo file not found or logo renderer is forced to show the MBI logo
    {
      m_VtkImageImport->SetDataScalarTypeToUnsignedChar();
      m_VtkImageImport->SetNumberOfScalarComponents(mbiLogo_NumberOfScalars);
      m_VtkImageImport->SetWholeExtent(0,mbiLogo_Width-1,0,mbiLogo_Height-1,0,1-1);
      m_VtkImageImport->SetDataExtentToWholeExtent();

      // flip mbi logo around y axis and change color order
      m_ImageData = new char[mbiLogo_Height*mbiLogo_Width*mbiLogo_NumberOfScalars];

      unsigned int column, row;
      char * dest   = m_ImageData;
      char * source = (char*) &mbiLogo_Data[0];;
      char r, g, b, a;
      for (column = 0; column < mbiLogo_Height; column++)
        for (row = 0; row < mbiLogo_Width; row++)
        {   //change r with b
            b = *source++;
            g = *source++;
            r = *source++;
            a = *source++;

            *dest++ = r;
            *dest++ = g;
            *dest++ = b;
            *dest++ = a;
          }

      m_VtkImageImport->SetImportVoidPointer(m_ImageData);
      m_VtkImageImport->Modified();
      m_VtkImageImport->Update();

      m_Actor->SetInput(m_VtkImageImport->GetOutput());
    }

    m_Actor->SetOpacity(m_Opacity);

    m_Renderer->AddActor( m_Actor );
    m_Renderer->InteractiveOff();

    SetupCamera();
    SetupPosition();

    mitk::VtkLayerController::GetInstance(m_RenderWindow)->InsertForegroundRenderer(m_Renderer,false);

    m_IsEnabled = true;
  }
}
Ejemplo n.º 2
0
//
// Load Cameras
// - basically a constructor for
// the camera objects
// reset variables all to zero, etc
//
void LoadCameras(void)
{

	int index = 0;
	int i  = 0;
	current_camera = 0;

	for (index = 0; index < MAX_CAMERAS; index++)
	{
		for (i = 0; i < 3; i++)
		{
			driver_camera[index]->angle[i] = 0.0f;
			driver_camera[index]->position[i] = 0.0f;
			driver_camera[index]->rotation[i] = 0.0f;
		} // end of the for 


		driver_camera[index]->id  = index;
		driver_camera[index]->type = CAMERA_STATIC;

		driver_camera[index]->centerx = 0.0f;
		driver_camera[index]->centery = 0.0f;
		driver_camera[index]->centerz = 0.0f;

		driver_camera[index]->zoom_factor = 3.2f;

	} // end of the functino

	// perform camera specific operations
	SetupCamera();


} // end of the function
Ejemplo n.º 3
0
void RenderCallback()
{
    // Clear buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	ProcessCameraKeys();
	SetupCamera();

    if (gScene && !bPause)
	{
		GetPhysicsResults();
        ProcessInputs();
		StartPhysics();
	}

    // Display scene
 	RenderActors(bShadows);

	if (bForceMode)
		DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0));
	else
		DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1));
	gForceVec = NxVec3(0,0,0);

	// Render HUD
	hud.Render();

    glFlush();
    glutSwapBuffers();
}
Ejemplo n.º 4
0
void Render()
{
	if(g_pD3DDevice==NULL) return;

	//Clear the back buffer to a black color
	g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	//Begin the scene
	g_pD3DDevice->BeginScene();

	SetupRotation();
	SetupCamera();
	SetupPerspective();

	//Rendering triangles
	int triCount=0;
	g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(CUSTOMVERTEX));
	g_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
	triCount+=g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	char msg[256];
	sprintf(msg, "每桢渲染的三角形数:%d", triCount);
	g_pFont->DrawText(msg, 5, 5, D3DCOLOR_XRGB(0, 255, 0));

	//End the scene
	g_pD3DDevice->EndScene();

	//Flip
	g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
Ejemplo n.º 5
0
	GameManager::GameManager(irr::IrrlichtDevice* p_device, irr::core::dimension2du p_resolution)
	{
		Utility::Logger* logger = Utility::Logger::GetInstance();

		m_device = p_device;
		m_resolution = p_resolution;
		m_isLookingForPencilCoords = false;
		if (m_device != NULL)
		{
			m_sceneManager = p_device->getSceneManager();
			m_videoDriver = p_device->getVideoDriver();
			SetupCamera();

			// Create a root scene node
			m_sceneManager->addEmptySceneNode(NULL, C_EMPTY_ROOT_SCENENODE);
			
			m_gameStatus = GameStatus::GAME_STARTED;
			m_player1 = PlayerType::TYPE_DEFENDER;
			m_playground = new Playground(this, m_sceneManager);
			m_gui = new Gui(m_device->getGUIEnvironment());
			m_eventHandler = new EventHandler(this, m_device, m_gui, m_playground);
			m_deltaTimer = new DeltaTimer(p_device->getTimer());

			m_device->setWindowCaption(L"KB06: Game");
			m_device->getCursorControl()->setVisible(true);		

			logger->Log(Utility::Logger::LOG_MESSAGE, "Starting game: Successful Started", __LINE__, __FILE__);
		}
		else
		{
			logger->Log(Utility::Logger::LOG_ERROR, "Starting game: Failed", __LINE__, __FILE__);
		}
	}
Ejemplo n.º 6
0
void GameScene::Load()
{
	// Link resources IDs with its resource pointers
	sht::utility::ResourceManager * resource_manager = sht::utility::ResourceManager::GetInstance();

	text_shader_ = dynamic_cast<sht::graphics::Shader *>(resource_manager->GetResource(text_shader_id_));
	gui_shader_ = dynamic_cast<sht::graphics::Shader *>(resource_manager->GetResource(gui_shader_id_));
	object_shader_ = dynamic_cast<sht::graphics::Shader *>(resource_manager->GetResource(object_shader_id_));
	ball_shader_ = dynamic_cast<sht::graphics::Shader *>(resource_manager->GetResource(ball_shader_id_));
	ghost_shader_ = dynamic_cast<sht::graphics::Shader *>(resource_manager->GetResource(ghost_shader_id_));
	font_ = dynamic_cast<sht::graphics::Font *>(resource_manager->GetResource(font_id_));
	ball_mesh_ = dynamic_cast<sht::graphics::ComplexMesh *>(resource_manager->GetResource(ball_mesh_id_));
	maze_mesh_ = dynamic_cast<sht::graphics::ComplexMesh *>(resource_manager->GetResource(maze_mesh_id_));

	// Create text objects
	fps_text_ = sht::graphics::DynamicText::Create(renderer_, 30);
	status_text_ = sht::graphics::DynamicText::Create(renderer_, 64);
	SetStatus(L"start");

	// Create physics
	physics_ = new sht::physics::Engine(20 /* max sub steps */, 0.002f /* fixed time step */);
	//physics_->SetGravity(vec3(0.0f, -9800.0f, 0.0f));

	// Setup physics objects
	{
		ball_ = physics_->AddSphere(vec3(0.0f, 0.0f, 0.0f), 0.150f, ball_size_);
		ball_->SetFriction(0.28f);
		ball_->SetRollingFriction(0.2f);
		ball_->SetSpinningFriction(0.5f);
		ball_->SetRestitution(0.98f);
	}
	{
		sht::graphics::MeshVerticesEnumerator enumerator(maze_mesh_);
		sht::physics::Object * object = physics_->AddMesh(vec3(0.0f, 0.0f, 0.0f), 0.0f, &enumerator);
		object->SetFriction(0.71f);
		object->SetRestitution(0.5f);
	}

	// Create meshes that have been loaded earlier
	ball_mesh_->AddFormat(sht::graphics::VertexAttribute(sht::graphics::VertexAttribute::kVertex, 3));
	ball_mesh_->AddFormat(sht::graphics::VertexAttribute(sht::graphics::VertexAttribute::kNormal, 3));
	ball_mesh_->AddFormat(sht::graphics::VertexAttribute(sht::graphics::VertexAttribute::kTexcoord, 2));
	ball_mesh_->MakeRenderable();
	maze_mesh_->AddFormat(sht::graphics::VertexAttribute(sht::graphics::VertexAttribute::kVertex, 3));
	maze_mesh_->AddFormat(sht::graphics::VertexAttribute(sht::graphics::VertexAttribute::kNormal, 3));
	maze_mesh_->MakeRenderable();

	SetupCamera();

	CreateMenu();

	PrepareBeginning();
	RequestRackRemove(); // later can be moved after table look overview

	BindShaderConstants();
}
Ejemplo n.º 7
0
HRESULT InitApp()
{	
	/// 카메라 행렬설정
	SetupCamera();
	CreateFont();
	InitFPS();
	SetDefaultStates();

	return S_OK;
}
Ejemplo n.º 8
0
void GameLocal::Init()
{
	SetupCamera();
	LoadAllModel();

	_defaultSprite = new Sprite;
	_defaultSprite->SetLabel("...");
	_defaultSprite->SetPosition(0.f, 400.f, 0.f);
	renderSys->AddSprite(_defaultSprite);
}
void ClothRender::Render()
{
    CVirtualClothTryOnDoc* doc = GetActiveDocument();//有了doc就有了绘制需要的数据文件
    if (!doc) return;

    SetupCamera(doc->m_pCamera3D);
    SetupRender();

    //下面可以测试绘制一些具体的图形
    GLDrawTriangle();
}
Ejemplo n.º 10
0
void AppRender( float frametime, float mouseDeltaX, float mouseDeltaY )
{
	static float fps = 0;

	if ( frametime > 0 )
	{
		fps = (fps * 0.9) + (0.1f/frametime);
	}

	AngleVectors( g_Camera.angles, &g_Camera.forward, &g_Camera.right, &g_Camera.up );
	FPSControls( frametime, mouseDeltaX, mouseDeltaY, g_Camera.position, g_Camera.angles );
	SetupCamera( g_Camera.position, g_Camera.angles );

	for ( int i = 0; i < MAX_KEY_EVENTS; i++ )
	{
		if ( g_KeyEvents.list[i] < 0 )
			break;
		switch( g_KeyEvents.list[i] )
		{
		case ' ':
			TracerCreate( g_Camera.position, g_Camera.forward );
			break;
		}
		g_KeyEvents.list[i] = -1;
	}
	// Clear the list
	g_KeyEvents.index = 0;

	BspRender( g_Camera.position );
	TracerDraw();

	// draw 2D elements
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
	
    glOrtho( 0, WinData.width, WinData.height, 0, -100, 100 );

    // set up a projection matrix to fill the client window
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
	glDepthMask( 0 );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_CULL_FACE );

	char fpsText[256];
	sprintf( fpsText, "FPS: %.0f  Texture: %s, POLYS: %4d", fps, g_LastTexture, g_PolyCount );
	font.Print( fpsText, 0, 0, 255, 255, 255 );

	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
	glDepthMask( 1 );
}
Ejemplo n.º 11
0
//virtual
void COpenGL_3D::OnSize(int cx, int cy)
{
	m_WindowWidth = cx;
	m_WindowHeight = cy;
	MakeGLContextCurrent();

	// Set OpenGL perspective, viewport and mode
	SetupCamera();
	
	glDrawBuffer(GL_BACK);
	OnEvent_SizeChanged(cx, cy);
	MakeGLContextNotCurrent();
}
Ejemplo n.º 12
0
void RenderCallback()
{
	// Clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	ProcessCameraKeys();
	SetupCamera();

	UpdateEmitterPosition();

	if (gScene && !bPause)
	{
		GetPhysicsResults();
		ProcessInputs();
		StartPhysics();
	}

	// Display scene
	RenderActors(bShadows);

	RenderFluid();

	if (bForceMode)
		DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0));
	else
		DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1));
	gForceVec = NxVec3(0,0,0);

	if (bEmitterWireframe)
	{
		NxMat34 fluidEmitterMat = fluidEmitter->getGlobalPose();
		NxVec3 fluidEmitterPos, fluidEmitterDir;
		fluidEmitterPos = fluidEmitterMat.t;
		fluidEmitterMat.M.getColumn(2,fluidEmitterDir);

		DrawArrow(fluidEmitterPos, fluidEmitterPos + fluidEmitterDir, NxVec3(0,0,1)); 
		DrawEllipse(20, fluidEmitter->getGlobalPose(), NxVec3(0.5,0,0.5), fluidEmitter->getDimensionX(), fluidEmitter->getDimensionY());
	}

	if (!bPause)
	{
		if (gDeltaTime < 10)  gTotalTime += gDeltaTime;
	}

	// Render HUD
	hud.Render();

	glFlush();
	glutSwapBuffers();
}
Ejemplo n.º 13
0
void Stage01::InitBackground()
{
	auto engine = STGEngine::GetInstance();
	auto background = engine->GetGameScene()->GetBackgroundLayer();

	SetupCamera();
	SetupFog();

	background->SetSkyBox(sky);
	background->EnableLighting(true);
	background->SetAmbientLight(Vector4f(0.3f, 0.3f, 0.3f, 1.0f));
	background->AddLight(Ptr<DirectionalLight>::New(Vector3f(1.8f, 1.8f, 1.8f), Vector3f(1.0f, -1.0f, 0.0f)).Get());

	InitBackgroundObjects();
}
Ejemplo n.º 14
0
/** 
 * start the CameraTask 
 **/
void StartCamera()	
{	 
	/* read a configuration file and send it to the camera	 */
	char *imageName = "166StartPic.png";

	//camera166 = AxisCamera::getInstance();
	camera166 = &AxisCamera::GetInstance();
	if ( 0 == camera166) {
		DPRINTF( LOG_DEBUG,"Failed to spawn camera task; exiting. Error code %s", 
				GetVisionErrorText(GetLastVisionError()) );	
	} else {
        SetupCamera(resolution, rotation);
		TakeSnapshot(imageName);
	}
}
void ScenePreviewControl::Update(float32 timeElapsed)
{
    UI3DView::Update(timeElapsed);
    
    if(needSetCamera)
    {
        needSetCamera = false;
        SetupCamera();
    }
    
    if(cameraController)
    {
        cameraController->Update(timeElapsed);
    }
}
Ejemplo n.º 16
0
void Camera::Update(const double& deltaTime)
{
	float speed = 1.f;

	if (aKey)
		sub(eyePosition, right, speed);

	if (dKey)
		add(eyePosition, right, speed);

	if (wKey)
		add(eyePosition, forward, speed);

	if (sKey)
		sub(eyePosition, forward, speed);

	SetupCamera();
}
Ejemplo n.º 17
0
void SpreadFilter::Enable()
{
  mCameraActor = CameraActor::New();
  mCameraActor.SetParentOrigin(ParentOrigin::CENTER);

  // create actor to render input with applied emboss effect
  mActorForInput = ImageActor::New( mInputImage );
  mActorForInput.SetParentOrigin( ParentOrigin::CENTER );
  mActorForInput.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
  mActorForInput.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) );

  // create internal offscreen for result of horizontal pass
  mImageForHorz = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Image::Unused );

  // create an actor to render mImageForHorz for vertical blur pass
  mActorForHorz = ImageActor::New( mImageForHorz );
  mActorForHorz.SetParentOrigin( ParentOrigin::CENTER );
  mActorForHorz.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
  mActorForHorz.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) );

  mRootActor.Add( mActorForInput );
  mRootActor.Add( mActorForHorz );
  mRootActor.Add( mCameraActor );

  std::ostringstream fragmentSource;
  if( mDebugRender )
  {
    fragmentSource << "#define DEBUG_RENDER\n";
  }
  fragmentSource << SPREAD_FRAGMENT_SOURCE;

  mShaderForHorz = ShaderEffect::New( "", fragmentSource.str() );
  mActorForInput.SetShaderEffect( mShaderForHorz );
  mShaderForHorz.SetUniform( "uSpread", mSpread );
  mShaderForHorz.SetUniform( "uTexScale", Vector2( 1.0f / mTargetSize.width, 0.0f ) );

  mShaderForVert = ShaderEffect::New( "", fragmentSource.str() );
  mActorForHorz.SetShaderEffect( mShaderForVert );
  mShaderForVert.SetUniform( "uSpread", mSpread );
  mShaderForVert.SetUniform( "uTexScale", Vector2( 0.0f, 1.0f / mTargetSize.height ) );

  SetupCamera();
  CreateRenderTasks();
}
Ejemplo n.º 18
0
void DrawScene(void)
{
    if (frames_drawn == 0)
    {
        /* start timing */
        glFinish();
        gettimeofday(&t0, NULL);
    }

    /* clear the draw buffer */
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    /* set the model-view matrix */
    SetupCamera();

    /* draw an outline of where the volume resides */
    DrawVolumeAxes();

    /* draw the volume in the chosen mode */
    DrawVolumeUsingCurrentDisplayMode();

    /* FPS timer code */

    frames_drawn++;

    if (frames_drawn == 30)
    {
        glFinish();
        gettimeofday(&t1, NULL);

        /* calculate time used for 30 frames */
        double diff = (t1.tv_sec + t1.tv_usec/1000000.0) - (t0.tv_sec + t0.tv_usec/1000000.0);

        if (display_fps_counter)
            printf("%.1f fps (%f secs for %d frames)\n", frames_drawn/diff, diff, frames_drawn);

        frames_drawn = 0;
    }

    /* finally, swap the draw buffers to make them appear on screen */
    glutSwapBuffers();
}
Ejemplo n.º 19
0
void GameLoader::Render()
{
	static int currentHit = 0;
    if(m_pD3DDevice == NULL)
    {
        return;
    }

    m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    m_pD3DDevice->BeginScene();

	SetupCamera();
	CheckBulletCollide(currentHit);

	floor->Render();
	platform->Render();
	tank->Render();

	char textString[32];
	sprintf (textString, "Score = %d", currentHit);

	RECT rect = {0, 0, 640, 480};
	m_pFont->DrawTextA(
			NULL,
			textString, 
			-1, 
			&rect,            
			DT_TOP | DT_LEFT, 
			0xffffffff);      

	for (std::list<CBullet*>::iterator it = bulletList.begin(); it != bulletList.end(); ++it)
	{
		(*it)->Render();
	}
	for (std::list<CEnemy*>::iterator it = enemyList.begin(); it != enemyList.end(); ++it)
	{
		(*it)->Render();
	}

    m_pD3DDevice->EndScene();
    m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
    if ( FAILED( InitTexture() ) )
    {
        return E_FAIL;
    }
    if ( FAILED( InitVB() ) )
    {
        return E_FAIL;
    }
    if ( FAILED( InitIB() ) )
    {
        return E_FAIL;
    }
    SetupCamera();

    // 최초의 마우스 위치 보관
    POINT	pt;
    GetCursorPos( &pt );
    g_dwMouseX = pt.x;
    g_dwMouseY = pt.y;
    return S_OK;
}
Ejemplo n.º 21
0
//virtual
void COpenGL_2D::Redraw()
{
	if (m_WindowHeight <= 0)
		return; // not initialized yet
	
	MakeGLContextCurrent();
	unsigned char *pcBackColor = GetBackgroundColor();
	glClearColor(pcBackColor[0]/255.f, pcBackColor[1]/255.f, pcBackColor[2]/255.f, 0.f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDrawBuffer(GL_BACK);
	SetupCamera();
	StoreModelViewMatrix();  // store MODELVIEW matrix (user can forget to restore it inside OnRenderScene)
	OnRenderScene();
	RestoreModelViewMatrix();
	if (IsInZoomRectangleMode() && m_bLDragging)
	{
		glPushAttrib(GL_ENABLE_BIT); // we will disable depth test therefore it must be restored
		glColor4ubv(GetZoomRectangleColor());
		glDisable(GL_DEPTH_TEST);
		double x1 = ScreenToWorldX(m_LButtonPressedAtX);
		double x2 = ScreenToWorldX(m_MouseCurrentPosX);
		double y1 = ScreenToWorldY(m_LButtonPressedAtY);
		double y2 = ScreenToWorldY(m_MouseCurrentPosY);
		glBegin(GL_LINE_LOOP);
			glVertex2d(x1, y1);
			glVertex2d(x2, y1);
			glVertex2d(x2, y2);
			glVertex2d(x1, y2);
		glEnd();
		glPopAttrib();
	}
	
	glFinish();
	SwapBuffers(m_hDC);
	MakeGLContextNotCurrent();
}
Ejemplo n.º 22
0
void RenderCallback()
{
    // Clear buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    ProcessCameraKeys();
	SetupCamera();

    if (gScene && !bPause)
	{
		GetPhysicsResults();
        ProcessInputs();
		StartPhysics();
	}

    // Display scene
 	RenderActors(bShadows);

	// Display kernel Info
	if (gForceField)
	{
		if (gForceField->getForceFieldKernel() == gCustomKernel)
		{
			hud.SetDisplayString(2, "Using CustomKernel", 0.14f, 0.92f);
		}
		else if (gForceField->getForceFieldKernel() == gLinearKernel)
		{
			hud.SetDisplayString(2, "Using LinearKernel", 0.14f, 0.92f);
		}
	}
	
	// Render the HUD
	hud.Render();

    glFlush();
    glutSwapBuffers();
}
Ejemplo n.º 23
0
void RenderCallback()
{
    if (gScene && !bPause)
	{
		StartPhysics();	
		GetPhysicsResults();
	}

    // Clear buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	ProcessInputs();
	ProcessCameraKeys();
	SetupCamera();

 	RenderActors(bShadows);

    // Render all the cloths in the scene
	for (MyCloth **cloth = gCloths.begin(); cloth != gCloths.end(); cloth++)
	{
		glColor4f(1.0f, 0.0f, 0.0f,1.0f);
		(*cloth)->draw(bShadows);
	}

	if (bForceMode)
		DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0));
	else
		DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1));
	gForceVec = NxVec3(0,0,0);

	// Render HUD
	hud.Render();

    glFlush();
    glutSwapBuffers();
}
Ejemplo n.º 24
0
void RenderEntities(void)
{
	int i;
	entity_t* entity;
	matrix_t inv_modelMatrix;
	vec4_t modelSpaceLightPos;
	vec4_t modelSpaceCameraPos;
	matrix_t tmp;
	
	
	renderer.isRenderingShadow = ((renderer.props & PROP_SHADOW) == PROP_SHADOW) ;
	if (renderer.isRenderingShadow)
	{
		glCullFace(GL_FRONT);
		glBindFramebuffer(GL_FRAMEBUFFER,shadowFBOId);
		glClearColor(1.0,1.0,1.0,1.0);
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(0.0,0.0,0.0,1.0);
		SRC_UseShader(&shaders[SHADOW_GENERATOR_SHADER]);
		glEnableVertexAttribArray(currentShader->vars[SHADER_ATT_VERTEX] );
		glViewport(0, 0, renderWidth*shadowMapRation, renderHeight*shadowMapRation);
		
		//Setup perspective and camera
		gluPerspective(light.fov, camera.aspect,camera.zNear, camera.zFar, projectionMatrix);
		gluLookAt(light.position, light.lookAt, light.upVector, modelViewMatrix);
	
		entity = map;
		for(i=0; i < num_map_entities; i++,entity++)
		{		
			matrix_multiply(modelViewMatrix,entity->matrix, tmp);
			matrix_multiply(projectionMatrix,tmp, modelViewProjectionMatrix);
			glUniformMatrix4fv(currentShader->vars[SHADER_MVT_MATRIX]   ,1,GL_FALSE, modelViewProjectionMatrix);
			
			if (entity->type == ENTITY_OBJ)
				RenderEntitiesOBJ(entity->model);
			else
				RenderEntitiesMD5(entity->model);
			
			//Also need to cache the PVM matrix in entity
			matrixCopy(modelViewProjectionMatrix,entity->cachePVMShadow);
		}
		
		glViewport(0, 0, renderWidth, renderHeight);
		glCullFace(GL_BACK);
		
		renderer.isRenderingShadow = 0;
		
		glBindFramebuffer(GL_FRAMEBUFFER,renderer.mainFramebufferId);
	}
	
	
	
	//Setup perspective and camera
	SetupCamera();
	
	entity = map;
	
	for(i=0; i < num_map_entities; i++,entity++)
	{
		//if (entity->type != ENTITY_OBJ)
		//	continue;
		
		SRC_BindUberShader(entity->material->prop);
		
		matrix_multiply(modelViewMatrix,entity->matrix, tmp);
		matrix_multiply(projectionMatrix,tmp, modelViewProjectionMatrix);
		glUniformMatrix4fv(currentShader->vars[SHADER_MVT_MATRIX]   ,1,GL_FALSE,modelViewProjectionMatrix);
		
		ComputeInvModelMatrix(entity->matrix, inv_modelMatrix);
		
		matrix_transform_vec4t(inv_modelMatrix, light.position, modelSpaceLightPos);
		glUniform3fv(currentShader->vars[SHADER_UNI_LIGHT_POS],1,modelSpaceLightPos);
		
		matrix_transform_vec4t(inv_modelMatrix, camera.position, modelSpaceCameraPos);
		glUniform3fv(currentShader->vars[SHADER_UNI_CAMERA_POS],1,modelSpaceCameraPos);

		
		
		if (renderer.props & PROP_SHADOW == PROP_SHADOW)
			glUniformMatrix4fv(currentShader->vars[SHADER_LIGHTPOV_MVT_MATRIX], 1, GL_FALSE,entity->cachePVMShadow);
		
		
		SetTextures(entity->material);
		
		if (entity->material->hasAlpha )
		{
			if (!renderer.isBlending)
			{
				renderer.isBlending = 1;
				glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				STATS_AddBlendingSwitch();
			}
		}
		else
		{
			if (renderer.isBlending)
			{
				renderer.isBlending = 0;
				glDisable(GL_BLEND);
				STATS_AddBlendingSwitch();
			}
		}
		
		glUniform1f(currentShader->vars[SHADER_UNI_MATERIAL_SHININESS], entity->material->shininess);
		glUniform3fv(currentShader->vars[SHADER_UNI_MAT_COL_SPECULAR],1,entity->material->specularColor);
		
		
		if (entity->type == ENTITY_OBJ)
			RenderEntitiesOBJ(entity->model);
		else
			RenderEntitiesMD5(entity->model);
		
		
	}
	
}
Ejemplo n.º 25
0
//virtual
void COpenGL_3D::OnCameraDirChanged()
{
	SetupCamera();
}
Ejemplo n.º 26
0
void displayCallback()
{
	akj::ResetCubeDrawCount();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if(gUseFBO)
	{
		if(gWidth != gPostFXFrameBuffer->mWidth || gHeight != gPostFXFrameBuffer->mHeight)
		{
			gPostFXFrameBuffer->InitBuffers(gWidth, gHeight, GL_SRGB8_ALPHA8);
			//rebind to the normal back buffer
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
		}
		glEnable(GL_BLEND);
		glBlendEquation(GL_FUNC_ADD);
		glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
		RenderBackground();
		glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);

		//flame effects need to know about the time 
		gCompositingShader->BindUniformToFloat("my_time", gTime);

		glPolygonMode(GL_FRONT, GL_FILL);
		gCompositingShader->Use();
		// clear the color buffer
		// set up camera: we want a quad matched up to the viewport
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		//drawcube gives a -0.5 - 0.5 range, so mult by 2
		glScalef(2.0, 2.0, 1.0);
		glTranslatef( 0.0, 0.0, -0.8);
		akj::glDrawRect2D();
		akj::glCheckAllErrors(__FILE__,__LINE__);
		glClear( GL_DEPTH_BUFFER_BIT );
	}
	else
	{
		RenderBackground();
	}
	glClear( GL_DEPTH_BUFFER_BIT );
	glDisable(GL_BLEND);
	SetupCamera();
	RenderRabbit();

	if(gUseFBO)
	{
		if(gClearFBO)
		{
			glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
			gClearFBO = false;
		}
		glActiveTexture(GL_TEXTURE0 + gPostFXFrameBuffer->GetBoundTextureUnit());
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, gWidth, gHeight);

	}

	glutSwapBuffers();
	if (gDump) {               // save images to file
		dumpPPM();
	}
	//printf("number of cubes this frame = %d\n", akj::GetCubeDrawCount());
	
}
Ejemplo n.º 27
0
void
DrawGLScene(void)
{
    float   tx, tz;

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    // set camera based on previous mouse input
    SetupCamera();

    // Set the light position. We do that after setting up the
    // camera so that the light position will keep its world position
    // and rotate along with the scene.
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    // Draw the different objects

    if (show_polygons_as_lines)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glDisable(GL_TEXTURE_2D);
    }
    else
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

        if (show_textures)
        {
            glEnable(GL_ALPHA_TEST);
            glAlphaFunc(GL_GREATER, 0.5);
            glEnable(GL_TEXTURE_2D);
        }
        else
            glDisable(GL_TEXTURE_2D);
    }

    DrawPolylist(polylistHouse);
    DrawPolylist(polylistGround1);
    DrawPolylist(polylistGround2);
    DrawPolylist(polylistRoad);

    // Draw a number of trees around the house.
    // They are all identical, but differ in location and Y-rotation.

    // Re-seed the random generator, so we always get the same sequence
    // back from rand_float() below, for different runs of the program.
    srand(95497452);

    for (int t = 0; t < 12; t++)
    {
        glPushMatrix();

        tx = 10 * (rand_float()-0.5) + object_positions[0].x;
        tz = 3 * rand_float() + 2.0 + object_positions[0].z;
        glTranslatef(tx, 0, tz);

        glRotatef(rand_float()*360.0, 0, 1, 0);
        glScalef(1, 1 + (rand_float()-0.5)*0.6, 1);

        DrawPolylist(polylistTreeStem);
        for (int i = 0; i < 5; i++) {
            DrawPolylist(polylistTreeLeafs);
            glRotatef(72.0, 0, 1, 0);
        }

        glPopMatrix();
    }

    // Draw the skydome with lighting turned off

    glPushAttrib(GL_LIGHTING_BIT);
    glDisable(GL_LIGHTING);
    DrawPolylist(polylistSkydome);
    glPopAttrib();

    glutSwapBuffers();
}
Ejemplo n.º 28
0
  EarthViewer(const Vec2<int>& size, const float scale, const bool oblong, Touch& touch, Keyinp& keyinp, const std::string& path, const std::string& lang) :
    touch_(touch),
    keyinp_(keyinp),
    size_(size.x / scale, size.y / scale),
    params_(path + "devdata/params.json"),
    scale_(scale),
    aspect_((float)size.x / (float)size.y),
    camera_(Camera::PERSPECTIVE),
    cockpit_(Camera::ORTHOGONAL),
    localize_(lang, path),
    earth_(params_.value().get<picojson::object>()["earth"].get<picojson::object>(), path, camera_),
    rotate_mix_(),
    place_index_()
  {
    DOUT << "EarthViewer()" << std::endl;

    picojson::object& params = params_.value().get<picojson::object>();

    camera_.oblong(oblong);
    SetupCamera(camera_, params["camera"].get<picojson::object>(), aspect_);
    cockpit_.setSize(size.x / scale, size.y / scale);

    {
      picojson::array& array = params["lights"].get<picojson::array>();
      for (picojson::array::iterator it = array.begin(); it != array.end(); ++it)
      {
        Light light;
        SetupLight(light, it->get<picojson::object>());
        lights_.push_back(light);
      }
      earth_.light(lights_);
    }

    env_.touch       = &touch_;
    env_.keyinp      = &keyinp_;
    env_.path        = &path;
    env_.savePath    = &path;
    env_.size        = &size_;
    env_.scale       = scale_;
    env_.params      = &params_;
    env_.task        = &task_;
    env_.camera      = &camera_;
    env_.cockpit     = &cockpit_;
    env_.earth       = &earth_;
    env_.earthLight  = &lights_[0];
    env_.fonts       = &fonts_;
    env_.texMng      = &texMng_;
    env_.localize    = &localize_;

    env_.earth_texture = 0;
    earth_.texture(env_.earth_texture);
    earth_.setRotSpeed(0);

    {
      const std::string& file = params["game"].get<picojson::object>()["places"].get<std::string>();
      Json places = Json(path + file);
      places_ = places.value().get<picojson::object>();
      for (picojson::object::iterator it = places_.begin(); it != places_.end(); ++it)
      {
        place_names_.push_back(&it->first);
      }
    }

    task_.add<Control>(TASK_PRIO_SYS, env_);
    task_.add<Game2DSetup>(TASK_PRIO_2D_TOPPRIO, env_);
    task_.add<GameWorld>(TASK_PRIO_3D_TOPPRIO, env_);
    env_.task->add<PlaceDisp>(TASK_PRIO_2D, env_);
    // task_.add<Equator>(TASK_PRIO_3D, env_);
    task_.add<TouchEft>(TASK_PRIO_3D, env_);
  }