Пример #1
0
// ----------------------------------------------------------------------------
RendererOGL::RendererOGL(WindowSDL *window, const Graphics::Settings &vs)
: Renderer(window, window->GetWidth(), window->GetHeight())
, m_numLights(0)
, m_numDirLights(0)
//the range is very large due to a "logarithmic z-buffer" trick used
//http://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html
//http://www.gamedev.net/blog/73/entry-2006307-tip-of-the-day-logarithmic-zbuffer-artifacts-fix/
, m_minZNear(0.0001f)
, m_maxZFar(10000000.0f)
, m_useCompressedTextures(false)
, m_invLogZfarPlus1(0.f)
, m_activeRenderTarget(0)
, m_activeRenderState(nullptr)
, m_matrixMode(MatrixMode::MODELVIEW)
{
	if (!initted) {
		initted = true;

		if (!ogl_LoadFunctions())
			Error(
				"Pioneer can not run on your graphics card as it does not appear to support OpenGL 3.3\n"
				"Please check to see if your GPU driver vendor has an updated driver - or that drivers are installed correctly."
			);

		if (ogl_ext_EXT_texture_compression_s3tc == ogl_LOAD_FAILED)
			Error(
				"OpenGL extension GL_EXT_texture_compression_s3tc not supported.\n"
				"Pioneer can not run on your graphics card as it does not support compressed (DXTn/S3TC) format textures."
			);
	}

	m_viewportStack.push(Viewport());

	const bool useDXTnTextures = vs.useTextureCompression;
	m_useCompressedTextures = useDXTnTextures;

	const bool useAnisotropicFiltering = vs.useAnisotropicFiltering;
	m_useAnisotropicFiltering = useAnisotropicFiltering;

	//XXX bunch of fixed function states here!
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glDepthRange(0.0,1.0);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
	glEnable(GL_PROGRAM_POINT_SIZE);

	glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
	glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_NICEST);

	SetMatrixMode(MatrixMode::MODELVIEW);

	m_modelViewStack.push(matrix4x4f::Identity());
	m_projectionStack.push(matrix4x4f::Identity());

	SetClearColor(Color4f(0.f, 0.f, 0.f, 0.f));
	SetViewport(0, 0, m_width, m_height);

	if (vs.enableDebugMessages)
		GLDebug::Enable();

	// check enum PrimitiveType matches OpenGL values
	assert(POINTS == GL_POINTS);
	assert(LINE_SINGLE == GL_LINES);
	assert(LINE_LOOP == GL_LINE_LOOP);
	assert(LINE_STRIP == GL_LINE_STRIP);
	assert(TRIANGLES == GL_TRIANGLES);
	assert(TRIANGLE_STRIP == GL_TRIANGLE_STRIP);
	assert(TRIANGLE_FAN == GL_TRIANGLE_FAN);
}
Пример #2
0
bool Game::Init()
{
	//Load game assets here...
	
	if (!AssetLoader.LoadFont("./Assets/Fonts/georgia_64.font", MousePosText)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Font.shader", MousePosText)) return false;

	if (!AssetLoader.LoadFont("./Assets/Fonts/georgia_64.font", HealthText)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Font.shader", HealthText)) return false;

	if (!AssetLoader.LoadFont("./Assets/Fonts/georgia_64.font", GoldText)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Font.shader", GoldText)) return false;

	if (!AssetLoader.LoadSprite("./Assets/Textures/BloonsBGPSD.png", GameBG)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader", GameBG)) return false;

	if (!AssetLoader.LoadSprite("./Assets/Textures/GnomeRed.png", Tower1)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader", Tower1)) return false;

	if (!AssetLoader.LoadSprite("./Assets/Textures/GnomeBlue.png", Tower2)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader", Tower2)) return false;

	if (!AssetLoader.LoadSprite("./Assets/Textures/DisplaySquare.png", Square1)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader", Square1)) return false;

	if (!AssetLoader.LoadSprite("./Assets/Textures/DisplaySquare.png", Square2)) return false;
	if (!AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader", Square2)) return false;
	
	GameBG.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	GameBG.Transform.Position = vec3(0, 0, 0);

	SpriteTexture = AssetLoader.LoadTexture("./Assets/Textures/Alien.png");
	SpriteShader = AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader");

	TowerRed = AssetLoader.LoadTexture("./Assets/Textures/GnomeRed.png");
	TowerShader = AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader");
	
	TowerBlue = AssetLoader.LoadTexture("./Assets/Textures/GnomeBlue.png");
	
	ProjTexture = AssetLoader.LoadTexture("./Assets/Textures/shroomProjectile.png");
	ProjShader = AssetLoader.LoadShader("./Assets/Shaders/Default/Sprite.shader");
	
	
	if (!SpriteTexture) return false;
	if (!SpriteShader) return false;

	GameGrid.Generate();
	GameGrid.SetPathOccupied("./Assets/TextFiles/pathCoords.txt");

	//Setup Font Properties
	MousePosText.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	MousePosText.GetComponent<Text>()->ScaleX = 0.5f;
	MousePosText.GetComponent<Text>()->ScaleY = 0.5f;
	MousePosText.Transform.Position = vec3(50, 50, 1);

	HealthText.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	HealthText.GetComponent<Text>()->ScaleX = 0.25f;
	HealthText.GetComponent<Text>()->ScaleY = 0.25f;
	HealthText.Transform.Position = vec3(108, 675, 1);
	HealthText.GetComponent<Text>()->String = "Lives Left: " + std::to_string(PlayerHealth);

	GoldText.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	GoldText.GetComponent<Text>()->ScaleX = 0.25f;
	GoldText.GetComponent<Text>()->ScaleY = 0.25f;
	GoldText.Transform.Position = vec3(108, 645, 1);
	GoldText.GetComponent<Text>()->String = "Gold: " + std::to_string(PlayerGold);
	
	//Setup Entity Properties
	Path AlienPath;
	AlienPath.AddNode(vec2(802, 720));
	AlienPath.AddNode(vec2(810, 652));
	AlienPath.AddNode(vec2(1058, 648));
	AlienPath.AddNode(vec2(1079, 220));
	AlienPath.AddNode(vec2(734, 250));
	AlienPath.AddNode(vec2(608, 512));
	AlienPath.AddNode(vec2(349, 493));
	AlienPath.AddNode(vec2(348, 143));
	AlienPath.AddNode(vec2(0, 117));
	
	Tower1.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	Tower1.GetComponent<Sprite>()->SetCenteredX(true);
	Tower1.GetComponent<Sprite>()->SetCenteredY(true);
	Tower1.Transform.Scale = (vec3(50, 50, 1));
	Tower1.Transform.Position = vec3(400, 660, 1);

	Square1.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	Square1.GetComponent<Sprite>()->SetCenteredX(true);
	Square1.GetComponent<Sprite>()->SetCenteredY(true);
	Square1.Transform.Scale = (vec3(53, 53, 1));
	Square1.AddComponent<Collider>(vec2(53, 53), UIELEMENT);
	Square1.Transform.Position = vec3(400, 660, 0.3);
	Square1.AddComponent<Purchasable>(100, TOWERRED);

	Tower2.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	Tower2.GetComponent<Sprite>()->SetCenteredX(true);
	Tower2.GetComponent<Sprite>()->SetCenteredY(true);
	Tower2.Transform.Scale = (vec3(50, 50, 1));
	Tower2.Transform.Position = vec3(531, 660, 1);
	
	Square2.GetComponent<Material>()->SetBlendMode(BlendFunc::Linear);
	Square2.GetComponent<Sprite>()->SetCenteredX(true);
	Square2.GetComponent<Sprite>()->SetCenteredY(true);
	Square2.Transform.Scale = (vec3(53, 53, 1));
	Square2.AddComponent<Collider>(vec2(53, 53), UIELEMENT);
	Square2.Transform.Position = vec3(531, 660, 0.3);
	Square2.AddComponent<Purchasable>(200, TOWERBLUE);
	
	UI.push_back(&Square1);
	UI.push_back(&Square2);

	//Add to be rendered.
	MainGroup.AddEntity(GameBG);
	MainGroup.AddEntity(MousePosText);
	MainGroup.AddEntity(GoldText);
	MainGroup.AddEntity(HealthText);
	MainGroup.AddEntity(Square1);
	MainGroup.AddEntity(Square2);
	MainGroup.AddEntity(Tower1);
	MainGroup.AddEntity(Tower2);
	MakeAlienWave(30, 20, AlienPath);

	//Setup Camera 
	MainCamera.AddComponent<Camera>()->SetOrthograpic(Console::GetScreenHeight(), 0, 0, Console::GetScreenWidth(), -1, 1000);
	MainCamera.Transform.Position = vec3(0.0f, 0.0f, 0.0f);
	
	//Setup up renderer
	MainRenderPass.SetCamera(MainCamera);
	MainRenderPass.SetGroup(MainGroup);
	
	//Setup background color
	//SetClearColor(0.35f, 0.7f, 0.9f, 0.0f); //cornflower blue
	SetClearColor(0,0,0, 1);
	return true;
}
Пример #3
0
CRender::CRender(uint uiInstIdx):
CInstancedObj(uiInstIdx),
_fFovAngle(60.f), _fZNear(0.25f), _fZFar(1000.f)
{
	_pCoreRenderer = Core()->pCoreRenderer();

	bool b_supported;

	std::string flist = "Core Renderer supported features\n\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_BUILTIN_FSCREEN_MODE, b_supported);
	flist += std::string("Hardware FScreen: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_BUILTIN_STATE_FILTER, b_supported);
	flist += std::string("Builtin State Filter: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_MULTISAMPLING, b_supported);
	flist += std::string("Multisampling: ") + (b_supported ? "Yes" : "No") + "\n\t";
	
	_pCoreRenderer->IsFeatureSupported(CRDF_VSYNC, b_supported);
	flist += std::string("VSync: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRDF_PROGRAMMABLE_PIPELINE, b_supported);
	flist += std::string("Programmable pipeline: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_BGRA_DATA_FORMAT, b_supported);
	flist += std::string("BGRA textures: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_TEXTURE_COMPRESSION, b_supported);
	flist += std::string("Texture compression: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_NON_POWER_OF_TWO_TEXTURES, b_supported);
	flist += std::string("Non power of two textures: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_DEPTH_TEXTURES, b_supported);
	flist += std::string("Depth textures: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_TEXTURE_ANISOTROPY, b_supported);
	flist += std::string("Texture anisotropy: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_TEXTURE_MIPMAP_GENERATION, b_supported);
	flist += std::string("Hardware mipmap generation: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRDF_TEXTURE_MIRRORED_REPEAT, b_supported);
	flist += std::string("Texture mirrored repeat: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRDF_TEXTURE_MIRROR_CLAMP, b_supported);
	flist += std::string("Texture mirror clamp: ") + (b_supported ? "Yes" : "No") + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRDF_GEOMETRY_BUFFER, b_supported);
	flist += std::string("Geometry buffer: ") + (b_supported ? "Yes" : "No") + "\n\t";

	LOG(flist, LT_INFO);

	std::string mlist = "Core Renderer device metrics\n\n\t";

	_pCoreRenderer->GetDeviceMetric(CRMT_MAX_TEXTURE_RESOLUTION, _iMaxTexResolution);
	mlist += "Maximum texture resolution: " + IntToStr(_iMaxTexResolution) + "X" + IntToStr(_iMaxTexResolution) + "\n\t";

	_pCoreRenderer->IsFeatureSupported(CRSF_TEXTURE_ANISOTROPY, b_supported);
	if (b_supported)
	{
		_pCoreRenderer->GetDeviceMetric(CRMT_MAX_ANISOTROPY_LEVEL, _iMaxAnisotropy);
		mlist += "Maximum anisotropy level: " + IntToStr(_iMaxAnisotropy) + "X" + "\n\t";
	}

	_pCoreRenderer->GetDeviceMetric(CRMT_MAX_LIGHTS_PER_PASS, _iMaxLight);

	_pCoreRenderer->GetDeviceMetric(CRMT_MAX_TEXTURE_LAYERS, _iMaxTexUnits);
	mlist += "Maximum multitexturing layer: " + IntToStr(_iMaxTexUnits) + "\n\t";

	LOG(mlist, LT_INFO);

	SetClearColor(TColor4(0x64646400));

	_pRender2D = new CRender2D(InstIdx());

	LOG("Render subsystem initialized.", LT_INFO);
}