예제 #1
0
void TSRModel::LoadFromMesh( TSRModel* _pModel, TSRIndexedMesh* _pIndexedMesh, TSRBBox& _boundBox )
{
    _pModel->m_uiGeometriesCount = 1;
    _pModel->m_pGeometries = new TSRModelGeometry[ 1 ];
	_pModel->m_BoundBox = _boundBox;

    TSRModelGeometry* pGeometry = _pModel->m_pGeometries;

    pGeometry->m_uiShaderFlags = _pIndexedMesh->m_pVertexDeclaration->CalculateShaderFlags();
    pGeometry->m_pMesh = _pIndexedMesh;
    pGeometry->m_uiTriangleSetsCount = 1;
    pGeometry->m_pTriangleSets = new TSRModelGeometryTriangleSet[ 1 ];
	pGeometry->m_Bounds = _boundBox;
	//pGeometry->m_uiRasterizerStateId = 1;

    TSRModelGeometryTriangleSet* pTriangleSet = pGeometry->m_pTriangleSets;

    pTriangleSet->m_uiStartIndex = 0;
    pTriangleSet->m_uiIndexCount = _pIndexedMesh->GetIndexCount();
	if ( _pIndexedMesh->GetIndexCount() == 0 )
	{
		pTriangleSet->m_uiIndexCount = _pIndexedMesh->GetVertexBuffer()->m_uiVertexCount;
	}
    pTriangleSet->m_renderMode = TWISTER_RENDERMODE_TRIANGLES;
    pTriangleSet->m_uiMaterialIndex = 0;
    
    _pModel->m_uiTexturesCount = 2;
    _pModel->m_ppTextures = new TSRTexture*[ 2 ];
    _pModel->m_pModelTextures = new TSRModelTexture[ _pModel->m_uiTexturesCount ];
    /// white and default normal are always first 2 textures..
    _pModel->m_ppTextures[ 0 ] = TextureManager()->GetWhite();
    _pModel->m_ppTextures[ 1 ] = TextureManager()->GetDefaultNormal();

    _pModel->m_uiMaterialsCount = 1;
    _pModel->m_pMaterials = new TSRModelMaterial[ 1 ];

    TSRModelMaterial* pModelMaterial = _pModel->m_pMaterials;
    pModelMaterial->m_fTransparency = 1.0f;

    _pModel->m_uiRenderNodesCount = 1;
    _pModel->m_pRenderNodes = new TSRModelRenderNode[ 1 ];
    _pModel->m_pRenderNodes[ 0 ].m_WorldTransform.MakeIdent();
    _pModel->m_pRenderNodes[ 0 ].m_uiGeometriesCount = 1;
    _pModel->m_pRenderNodes[ 0 ].m_pGeometriesIndices = new int[ 1 ];
    _pModel->m_pRenderNodes[ 0 ].m_pGeometriesIndices[ 0 ] = 0;
	
    _pModel->m_RootNode.m_iRenderNodeIndex = 0;
    _pModel->m_RootNode.m_LocalTransform.MakeIdent();

    _pModel->m_uiEffectsCount = 1;
    _pModel->m_ppEffects = new TSREffect*[ 1 ];
    _pModel->m_ppEffects[ 0 ] = EffectManager()->Aquire( "supershader.fx" );

    snprintf( _pModel->m_RootNode.m_Name, 32, "OBJ_RootNode" );
}
예제 #2
0
void cBSPDemoCallbacks::OnDrawInterface()
{
    Graphics()->SetDepthStencilState(Graphics()->m_DepthTestDisabledWriteEnabled);
    Graphics()->SetBlendState( Graphics()->m_BlendAdditiveColor );
    Graphics()->Begin2D();
    TSRGUISubSystem::Update( 0.0f );
	TSRText::SetColor( TSRColor3( 1.0f, 1.0f, 0.0f ) );
	
	TSRText::Printf( 30, 130, "%d textures remaining ", TextureManager()->GetQueueLength() );
	TSRText::Printf( 30, 110, "Press L to add a light in your position" );
	TSRText::Printf( 30, 90, "Press K to remove it" );
	TSRText::SetColor( TSRColor3( 1.0f, 0.0f, 0.0f ) );
    
	TSRText::Printf( 30, 30, "%d fps", TSRSystem()->CalculateFPS() );
    TSRText::Printf( 30, 50, "Use mouse to rotate the camera" );
    TSRText::Printf( 30, 70, "Use the arrows to move around the place" );
    Graphics()->SetBlendState( Graphics()->m_BlendDisabled );
    TSRText::SetColor( TSRColor3( 1.0f, 1.0f, 1.0f ) );
    if ( m_pNearestDoor )
    {
        TSRText::Printf( 30, 130, "Press space to open" );
    }
    Graphics()->SetBlendState( Graphics()->m_BlendDisabled );
    Graphics()->End2D();
    Graphics()->SetBlendState( Graphics()->m_BlendDisabled );

}
예제 #3
0
TSRLightingManager::TSRLightingManager() : m_LightingKey( 0 )
{
    m_ProjectedTextures[ 0 ].BindToName( "ProjectorTexture" );
    m_ProjectedTextures[ 1 ].BindToName( "ProjectorTexture" );
    m_ProjectedTextures[ 2 ].BindToName( "ProjectorTexture" );
    m_ProjectedTextures[ 3 ].BindToName( "ProjectorTexture" );

    m_SpotShadowTexture.BindToName( "SpotsShadowMapAtlas" );

    m_Projectors[ 0 ].BindToName( "Projector0", sizeof( TSRProjectorShaderData ) );
    m_Projectors[ 1 ].BindToName( "Projector1", sizeof( TSRProjectorShaderData ) );
    m_Projectors[ 2 ].BindToName( "Projector2", sizeof( TSRProjectorShaderData ) );
    m_Projectors[ 3 ].BindToName( "Projector3", sizeof( TSRProjectorShaderData ) );

    m_AmbientColor.Assign( 0.05f, 0.05f, 0.05f, 1.0f );
    m_AmbientLightColor.BindToName( "AmbientLightColor" );
    m_AmbientLightColor.Set( m_AmbientColor );

    m_EffectsDisabledMask = 0;
	m_EffectsEnabledMask = 0;

    m_pDefaultSpotTexture = TextureManager()->Aquire( "textures/spotlight.dds" );


#if defined( WIN32 ) || defined ( WIN64 )
   // #ifndef OPENGL_RENDERER
    m_pMainLightShader = new TSRShaderEffect( "MainLight.fx" );
    m_pMainLightAndShadowShader = new TSRShaderEffect( "MainLight.fx", TWISTER_SHADER_FLAG_SHADOWMAP );
    m_pDirectionalLightShader = new TSRShaderEffect( "DirectionalLight.fx" );
    m_pPointLightShader = new TSRShaderEffect( "PointLight.fx" );
    m_pSpotLightShader  = new TSRShaderEffect( "SpotLight.fx" );
//    #endif
#endif
}
예제 #4
0
	// /////////////////////////////////////////////////////////////////
	//
	// /////////////////////////////////////////////////////////////////
	bool Pool3dGame::VInitOpenGL()
	{
		bool result = true;

        GF_LOG_DEB("Initializing the GLEW library");
#if TARGET_OS_MAC
        glewExperimental = GL_TRUE;
#endif
		GLenum res = glewInit();
		if (GLEW_OK != res)
		{
			// Problem: glewInit failed, something is seriously wrong.
            GF_LOG_ERR(string("Failed to initialize the GLEW library: ") + string(reinterpret_cast<const char *>(glewGetErrorString(res))));
			result = false;
		}
		if(result)
		{
            GF_LOG_DEB(string("Using GLEW version: ") + string(reinterpret_cast<const char *>(glewGetString(GLEW_VERSION))));
		}

		// Check for required OpenGL extensions here and set application wide flags if certain features are available.
		// TODO: check for other extensions.
#ifdef GLEW_EXT_texture_filter_anisotropic
		m_isAnisotropicExtPresent = true;
#endif

		// Perform any global OpenGL initialization here.
		if(result)
		{
			// Set the color buffer clear value.
			glClearColor(GameHalloran::g_gcLightGray.GetX(), GameHalloran::g_gcLightGray.GetY(), GameHalloran::g_gcLightGray.GetZ(), GameHalloran::g_gcLightGray.GetW());

			// Enable depth testing.
			glEnable(GL_DEPTH_TEST);

			// Set the alpha blending function.
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			// Turn on anitaliasing for lines
			glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

			// Cull all back facing triangles.
			glCullFace(GL_BACK);

			// Set the triangle winding.
			glFrontFace(GL_CCW);

			// Initialize the TextureManager last once all other OpenGL initialization is done.
			m_texManagerPtr.reset(GCC_NEW TextureManager(10, 1024*1024*20));
			m_texManagerPtr->SetTextureFilterMode(TextureManager::eAnisotropic);
			m_texManagerPtr->SetAnisotropicLinearLevel(1.0f);
            
            GameMain::SetupTextureAtlasManager(std::string("atlases") + ZipFile::ZIP_PATH_SEPERATOR + std::string("atlasDictionary.xml"));
		}

		return (result);
	}
예제 #5
0
void Sprite::DrawOn(SDL_Renderer * ren, int x, int y ) {
	TextureLocation tl = TextureManager().getSingleton()->getTexture(location);
	SDL_Rect outRect;
	outRect.x = x;
	outRect.y = y;
	outRect.w = visRect.w;
	outRect.h = visRect.h;
	SDL_Rect sRect = getSubRect(tl.lrect, visRect);
	SDL_RenderCopy(ren, tl.texture, &sRect, &outRect);
}
예제 #6
0
Manager::Manager( const char* name, int width, int height, Engine::WindowMode wm ):
RTTI_CLASS_DEFINE( Manager ),
m_engine( 0 ),
m_game( 0 ),
m_pushState( 0 ),
m_progressState( 0 ),
m_progressStateDefault( 0 ),
m_popState( false ),
m_changeState( false ),
m_loading( false ),
m_states( 0 ),
m_scenes( 0 ),
m_materials( 0 ),
m_effects( 0 ),
m_fonts( 0 ),
m_textures( 0 ),
m_canvases( 0 ),
m_assets( 0 ),
m_assetsLoading( 0 ),
m_actors( 0 ),
m_controls( 0 ),
m_collisions( 0 ),
m_audio( 0 )
{
	m_engine = xnew Engine();
	m_engine->initiation( name, width, height, wm );
	m_states = xnew Stack< IState >();
	m_scenes = xnew SceneManager();
	m_materials = xnew MaterialManager();
	m_effects = xnew EffectManager();
	m_fonts = xnew FontManager();
	m_textures = xnew TextureManager();
	m_canvases = xnew CanvasManager();
	m_assets = xnew AssetManager();
	m_assetsLoading = xnew AssetManager();
	m_actors = xnew Stack< ActorManager >();
	m_controls = xnew Stack< ControlManager >();
	m_collisions = xnew Stack< CollisionManager >();
	m_audio = xnew AudioManager();

	Global::use().engine = m_engine;
	Global::use().scenes = m_scenes;
	Global::use().materials = m_materials;
	Global::use().effects = m_effects;
	Global::use().fonts = m_fonts;
	Global::use().textures = m_textures;
	Global::use().canvases = m_canvases;
	Global::use().assets = m_assets;
	Global::use().assetsLoading = m_assetsLoading;
	Global::use().actors = 0;
	Global::use().controls = 0;
	Global::use().collisions = 0;
	Global::use().audio = m_audio;
}
예제 #7
0
void RenderAxis( float _fLength )
{
    TSRMaterial material;
    material.m_vDiffuseColor.Assign( 1.0f, 1.0f, 1.0f, 1.0f );
    material.m_vSpecularColor.Assign( 0.24f, 0.2f, 0.22f, 1.0f );
    material.m_vSpecularPowerBumpiness.Assign( 1024.0f, 1.0f );

    TSRGlobalConstants.SetMaterial( material );
    TSRGlobalConstants.m_DiffuseTexture.Set( *TextureManager()->GetWhite() );

    TSRGlobalConstants.PushMatrix();
    TSRGlobalConstants.Scale( _fLength, _fLength, _fLength );
    Graphics()->m_pTexturedVertexColorShader->Activate();
    g_pUnitAxis->Render();
    TSRGlobalConstants.PopMatrix();
}
예제 #8
0
    bool TestApp::VInitOpenGL()
    {
        bool result = true;

        GF_LOG_DEB("Initializing the GLEW library");

#if defined(TARGET_OS_MAC)
        glewExperimental = GL_TRUE;
#endif
        GLenum res = glewInit();
        if(GLEW_OK != res) {
            GF_LOG_ERR(string("Failed to initialize the GLEW library: ") + string(reinterpret_cast<const char *>(glewGetErrorString(res))));
            result = false;
        }
        if(result) {
            GF_LOG_DEB(string("Using GLEW version: ") + string(reinterpret_cast<const char *>(glewGetString(GLEW_VERSION))));
        }

#ifdef GLEW_EXT_texture_filter_anisotropic
        m_isAnisotropicExtPresent = true;
#endif

        if(result) {
            glClearColor(GameHalloran::g_gcBlue.GetX()
                         , GameHalloran::g_gcBlue.GetY()
                         , GameHalloran::g_gcBlue.GetZ()
                         , GameHalloran::g_gcBlue.GetW());
            glEnable(GL_DEPTH_TEST);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
            glCullFace(GL_BACK);
            glFrontFace(GL_CCW);

            m_texManagerPtr.reset(GCC_NEW TextureManager(10, 1024 * 1024 * 20));
            m_texManagerPtr->SetTextureFilterMode(TextureManager::eAnisotropic);
            m_texManagerPtr->SetAnisotropicLinearLevel(1.0f);

            GameMain::SetupTextureAtlasManager(std::string("atlases") + ZipFile::ZIP_PATH_SEPERATOR + std::string("atlasDictionary.xml"));
        }

        return (result);
    }
예제 #9
0
Sprite::Sprite(AtlasLocation al, int numFrames, CLEngine * cle): clLoaded(0) {
	location = al;
	TextureLocation tl = TextureManager().getSingleton()->getTexture(location);

	tw = tl.lrect.w;
	th = tl.lrect.h;

	visRect.x = 0;
	visRect.y = 0;
	visRect.w = tw/numFrames;
	visRect.h = th;	

	if( cle != NULL ) {
		TextureProperty tp = getTexId(tl.texture);
		int err;
		clObj = clCreateFromGLTexture2D(cle->getContext(), CL_MEM_READ_WRITE, tp.ttype, 0, tp.tid, &clLoaded);
		if( clLoaded < 0 ) { fprintf(stderr, "%i\n", clLoaded); perror("Could not create texture buffer."); exit(1); }
	} else {
		clObj = 0;
	}
}
예제 #10
0
/// constructor
VDSMesh::VDSMesh(): TSRMesh( *g_VDSVertexDecl ), m_pDiffuseTexture( TextureManager()->GetWhite() ), m_pNormalTexture( TextureManager()->GetDefaultNormal() ), m_pModelInstance( NULL )
{

}
예제 #11
0
void TSRModel::LoadModel( TSRModel* pModel, const char* _pFileName )
{
    /// new : if this is a .obj file, we create a dummy model  around its mesh
    string strFilename = _pFileName;

    string strExtension = strFilename.substr( strlen( _pFileName ) - 3, strlen( _pFileName ) );

    if ( strExtension == "obj" )
    {
        LoadFromOBJ( pModel, _pFileName );
        return;
    }

	TSRFileStream* fptr = TSRFileSystem::OpenFileStream( _pFileName, "rb" );

	// first read the version
	unsigned int uiVersion = 0;

	fread( &uiVersion, sizeof( unsigned int ), 1, fptr );

	// read geometries
	fread( &pModel->m_uiGeometriesCount, sizeof( unsigned int ), 1, fptr );
	if ( pModel->m_uiGeometriesCount > 0 )
	{
		pModel->m_pGeometries = new TSRModelGeometry[ pModel->m_uiGeometriesCount ];
	}
	for ( unsigned int i = 0; i < pModel->m_uiGeometriesCount; i++ )
	{
		LoadGeometry( pModel->m_pGeometries + i, fptr );
	}

	/// read skinned geometries
	fread( &pModel->m_uiSkinnedGeometriesCount, sizeof( unsigned int ), 1, fptr );
	if ( pModel->m_uiSkinnedGeometriesCount )
	{
		pModel->m_pSkinnedGeometries = new TSRModelSkinnedGeometry[ pModel->m_uiSkinnedGeometriesCount ];
	}
	for ( unsigned int i = 0; i < pModel->m_uiSkinnedGeometriesCount; i++ )
	{
		LoadSkinnedGeometry( pModel->m_pSkinnedGeometries + i, fptr );
	}


	/// read effects 
	fread( &pModel->m_uiEffectsCount, sizeof( unsigned int ), 1, fptr );

	if ( pModel->m_uiEffectsCount > 0 )
	{
		pModel->m_ppEffects = new TSREffect* [ pModel->m_uiEffectsCount ];
		for ( unsigned int i = 0; i < pModel->m_uiEffectsCount; i++ )
		{
			char effectName[ 16 ];
			fread( effectName, 16, 1, fptr );
			pModel->m_ppEffects[ i ] = EffectManager()->Aquire( effectName );
		}
	}

	/// read textures
	fread( &pModel->m_uiTexturesCount, sizeof( unsigned int ), 1, fptr );
	pModel->m_uiTexturesCount += 2;
	pModel->m_pModelTextures = new TSRModelTexture[ pModel->m_uiTexturesCount ];
	pModel->m_ppTextures = new TSRTexture*[ pModel->m_uiTexturesCount ];


	if ( pModel->m_uiTexturesCount > 2 )
	{
		fread( &pModel->m_pModelTextures[ 2 ], sizeof( TSRModelTexture ), pModel->m_uiTexturesCount - 2, fptr );
	}


	/// read materials
	fread( &pModel->m_uiMaterialsCount, sizeof( unsigned int ), 1, fptr );
	
	// always add one default material 
	pModel->m_pMaterials = new TSRModelMaterial[ pModel->m_uiMaterialsCount ];
	if ( pModel->m_uiMaterialsCount > 0 )
	{
		fread( pModel->m_pMaterials, sizeof( TSRModelMaterial ), pModel->m_uiMaterialsCount, fptr );
	}

	snprintf( pModel->m_RootNode.m_Name, 32, "RootNode" );

	// read the root node transform
	fread( &pModel->m_RootNode.m_LocalTransform, sizeof( TSRMatrix4 ), 1, fptr );

	// read number of nodes under root
	fread( &pModel->m_RootNode.m_uiChildrenCount, sizeof( unsigned int ), 1, fptr );

	// allocate them
	pModel->m_RootNode.m_pChildren = new TSRModelNode[ pModel->m_RootNode.m_uiChildrenCount ];
	for ( unsigned int i = 0; i < pModel->m_RootNode.m_uiChildrenCount; i++ )
	{
		ReadModelNodesRec( pModel->m_RootNode.m_pChildren + i, fptr );
	}

	// read the whole model aabb..
	fread( &pModel->m_BoundBox, sizeof( TSRBBox ), 1, fptr );

	// read number of render nodes.
	fread( &pModel->m_uiRenderNodesCount, sizeof( unsigned int ), 1, fptr );

	if ( pModel->m_uiRenderNodesCount > 0 )
	{
		pModel->m_pRenderNodes = new TSRModelRenderNode[ pModel->m_uiRenderNodesCount ];
	}

	for ( unsigned int i = 0; i < pModel->m_uiRenderNodesCount; i++ )
	{
		// allocate a new render node
		TSRModelRenderNode*  pNewRenderNode = pModel->m_pRenderNodes + i ;

		// read it without the trailing pointer (world transform and the number of geometry instances)
		fread( pNewRenderNode, sizeof( TSRMatrix4 ) + sizeof( int ), 1, fptr );

		// allocate  geometry indices
		pNewRenderNode->m_pGeometriesIndices = new int[ pNewRenderNode->m_uiGeometriesCount ];

		// read them
		fread( pNewRenderNode->m_pGeometriesIndices, pNewRenderNode->m_uiGeometriesCount * sizeof( int ), 1, fptr );
	}

	/// read skinned nodes
	fread( &pModel->m_uiSkinnedNodesCount, sizeof( unsigned int ), 1, fptr );

	if ( pModel->m_uiSkinnedNodesCount >  0 )
	{
		pModel->m_pSkinnedNodes = new TSRModelRenderNode[ pModel->m_uiSkinnedNodesCount ];
	}

	for ( unsigned int i = 0; i < pModel->m_uiSkinnedNodesCount; i++ )
	{
		// allocate a new skinned node
		TSRModelRenderNode*  pNewSkinnedNode = pModel->m_pSkinnedNodes + i ;

		// read it without the trailing pointer (world transform and the number of geometry instances)
		fread( pNewSkinnedNode, sizeof( TSRMatrix4 ) + sizeof( int ), 1, fptr );

		// allocate  geometry indices
		pNewSkinnedNode->m_pGeometriesIndices = new int[ pNewSkinnedNode->m_uiGeometriesCount ];

		// read them
		fread( pNewSkinnedNode->m_pGeometriesIndices, pNewSkinnedNode->m_uiGeometriesCount * sizeof( int ), 1, fptr );
	}

	// read the animations
	fread( &pModel->m_AnimationsCount, sizeof( unsigned int ), 1, fptr );

	// allocate the animations
	if ( pModel->m_AnimationsCount > 0 )
	{
		pModel->m_pAnimations = new TSRModelAnimation[ pModel->m_AnimationsCount ];

		for ( unsigned int i = 0; i < pModel->m_AnimationsCount; i++ )
		{
			LoadAnimation( pModel->m_pAnimations + i, fptr );
		}
	}

	// read lights 
	fread( &pModel->m_uiLightsCount, sizeof( unsigned int ), 1, fptr );

	// allocate lights and read them in one go..
	if ( pModel->m_uiLightsCount > 0 )
	{
		pModel->m_pLights = new TSRModelLight[ pModel->m_uiLightsCount ];
		fread( pModel->m_pLights, sizeof( TSRModelLight ), pModel->m_uiLightsCount, fptr );
	}

	/// read number of light nodes
	fread( &pModel->m_uiLightNodesCount, sizeof( unsigned int ), 1, fptr );

	if ( pModel->m_uiLightNodesCount > 0 )
	{
		pModel->m_pLightNodesIndices = new unsigned int[ pModel->m_uiLightNodesCount ];
		fread( pModel->m_pLightNodesIndices, sizeof( unsigned int ), pModel->m_uiLightNodesCount, fptr );
	}
	/// read number of bones and create the skeleton matrix data 
	fread( &pModel->m_uiBonesCount, sizeof( unsigned int ), 1, fptr );

	fclose( fptr );


    /// white and default normal are always first 2 textures..
    pModel->m_ppTextures[ 0 ] = TextureManager()->GetWhite();
    pModel->m_ppTextures[ 1 ] = TextureManager()->GetDefaultNormal();

    // change the current working directory according to the file's path, so textures can be read properly
    string fullPath = _pFileName;
    int iSlashPosition = ( int ) fullPath.find_last_of( "/" );
    string textureFileNameHeader = "";

	if ( iSlashPosition == -1 )
	{
		iSlashPosition = ( int ) fullPath.find_last_of( "\\" );
	}

    if ( iSlashPosition > -1 )
    {
        textureFileNameHeader = fullPath.substr( 0, iSlashPosition + 1 );
    }

    string textureFileName;

    // change directory if needed before getting the textures..
    for ( unsigned int i = 2; i < pModel->m_uiTexturesCount; i++ )
    {
        textureFileName = textureFileNameHeader + pModel->m_pModelTextures[ i ].m_Name;
        pModel->m_ppTextures[ i ] = TextureManager()->Aquire( textureFileName.c_str() );
    }
}