当前位置: 首页>>代码示例>>C++>>正文


C++ TextureManager::Init方法代码示例

本文整理汇总了C++中TextureManager::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureManager::Init方法的具体用法?C++ TextureManager::Init怎么用?C++ TextureManager::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextureManager的用法示例。


在下文中一共展示了TextureManager::Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
	srand(time(NULL));

	GARandomSeed();

	bool gameIsRunning = false;

	// SDL
	SDL_Window* window = nullptr;
	SDL_Event sdlEvent;
	SDL_Renderer* renderer = nullptr;

	TextureManager* textureManager = nullptr;
	MyB2DebugDraw* debugDraw = nullptr;
	MyB2ContactListener* contactListener = nullptr;

	// Fonts
	TTF_Font* font = nullptr;

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		return -1;
	}

	window = SDL_CreateWindow("GA Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
	if (!window)
	{
		return -1;
	}

	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

	if (!renderer)
	{
		return -1;
	}

	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);

	// Initialize SDL PNG loading
	int imgFlags = IMG_INIT_PNG;
	if (!(IMG_Init(imgFlags) & imgFlags))
	{
		printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
		return -1;
	}

	// Initialize SDL ttf
	if (TTF_Init() == -1)
	{
		printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError());
		return -1;
	}

	// Open ttf font
	font = TTF_OpenFont((dir_fonts + "OpenSans-Regular.ttf").c_str(), 12);

	textureManager = TextureManager::GetInstance();
	textureManager->Init(renderer, dir_assets);

	// Game variables
	//float dt = 1.0f / 10.0f;
	double dt_fixed = 1.0 / 60.0;
	float t = 0.0f;
	auto currentTime = std::chrono::system_clock::now();

	debugDraw = new MyB2DebugDraw(renderer);

	debugDraw->SetFlags(b2Draw::e_shapeBit
		//| b2Draw::e_aabbBit
		| b2Draw::e_jointBit
		| b2Draw::e_centerOfMassBit);

	contactListener = new MyB2ContactListener();

	// Box2D
	b2Vec2 gravity(0.0f, 0.0f);
	b2World* box2Dworld = new b2World(gravity);
	//box2Dworld->SetDebugDraw(debugDraw);
	box2Dworld->SetContactListener(contactListener);

	Game* game = new Game(window, renderer, WINDOW_WIDTH, WINDOW_HEIGHT, box2Dworld, textureManager, font);
	game->Init(dir_assets, dir_fonts, dir_textures, dt_fixed);
	gameIsRunning = true;

	vec2 curMouseClickPos;

	while (gameIsRunning)
	{
		while (SDL_PollEvent(&sdlEvent) != 0)
		{
			if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) 
			{
				SDL_GetMouseState(&curMouseClickPos.x, &curMouseClickPos.y);
			}

			if (sdlEvent.type == SDL_QUIT)
			{
				gameIsRunning = false;
//.........这里部分代码省略.........
开发者ID:hyzor,项目名称:ML_Project,代码行数:101,代码来源:main.cpp

示例2: Init

bool Projekt::Init()
{
	CSplashWnd splash;
	splash.SetImage(Gdiplus::Image::FromFile(L"Data\\Textures\\test.jpg"));
	splash.Show();
	splash.SetProgressBarColor(0x00000000);
	splash.SetAutoProgress(0, 100, 50);

	if (!D3D11App::Init())
		return false;

	// Read game settings
	if (!Settings::GetInstance()->ReadFile("Data\\Settings.txt"))
		return false;

	// Initialize effects, input layouts and texture manager
	Effects::InitAll(mDirect3D->GetDevice());
	InputLayouts::InitAll(mDirect3D->GetDevice());
	mTextureMgr.Init(mDirect3D->GetDevice());
	RenderStates::InitAll(mDirect3D->GetDevice());

	// Initialize models
	GenericHandler::GetInstance()->Initialize(mDirect3D->GetDevice(), &mTextureMgr);
	Python->Initialize();


	//Create and initialize the GUI
	Gui->Init(mDirect3D->GetDevice());

	Network::GetInstance()->Initialize();
	Network::GetInstance()->Start();

	//init soundmodule
	this->soundModule = new SoundModule();
	this->soundModule->initialize(this->mhMainWnd, this->mDirectInput);

	
	// Create game
	mGame = new Game(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), &mTextureMgr, soundModule);

	// Set if window is fullscreen or not
	D3D11App::SetFullscreen(Settings::GetInstance()->GetData().IsFullscreen);

	// Resize window after we've created our Game object
	D3D11App::SetResolution(Settings::GetInstance()->GetData().Width,
		Settings::GetInstance()->GetData().Height);

	// Create sky
	mSky = new Sky(mDirect3D->GetDevice(), L"Data\\Textures\\SkyBox_Space.dds", 5000.0f);

	// Create shadow map
	mShadowMap = new ShadowMap(mDirect3D->GetDevice(), 2048, 2048);

	// Create frustum culling
	mFrustumCulling = new FrustumCulling();

	//--------------------------------------------------------
	// Compute scene bounding box
	//--------------------------------------------------------
// 	XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity);
// 	XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity);
// 
// 	// Get vertex positions from all models
// 	for (UINT i = 0; i < mGenericInstances.size(); ++i)
// 	{
// 		for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j)
// 		{
// 			XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position;
// 
// 			minPt.x = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.y = MathHelper::getMin(minPt.x, vPos.x);
// 			minPt.z = MathHelper::getMin(minPt.x, vPos.x);
// 
// 			maxPt.x = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.y = MathHelper::getMax(maxPt.x, vPos.x);
// 			maxPt.z = MathHelper::getMax(maxPt.x, vPos.x);
// 		}
// 	}
// 
// 	// Sphere center is at half of these new dimensions
// 	mSceneBounds.Center = XMFLOAT3(	0.5f*(minPt.x + maxPt.x),
// 		0.5f*(minPt.y + maxPt.y),
// 		0.5f*(minPt.z + maxPt.z));
// 
// 	// Calculate the sphere radius
// 	XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x),
// 		0.5f*(maxPt.y - minPt.y),
// 		0.5f*(maxPt.z - minPt.z));
// 
// 	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);
	splash.Hide();
	D3D11App::ShowWindow();
	OnResize();

	return true;
}
开发者ID:hyzor,项目名称:GameProject,代码行数:96,代码来源:main.cpp


注:本文中的TextureManager::Init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。