/* load 6 images into an OpenGL cube map */
GLuint LoadCubeMap(std::vector<std::string> file_locations)
{
	//TODO: create variable arguments for SOIL flags

	if(file_locations.size() != 6)
	{
		std::cout << "Must pass 6 images to LoadCubeMap" << std::endl;
		return 0;
	}

	GLuint tex_cube = SOIL_load_OGL_cubemap
		(
			file_locations[0].c_str(),
			file_locations[1].c_str(),
			file_locations[2].c_str(),
			file_locations[3].c_str(),
			file_locations[4].c_str(),
			file_locations[5].c_str(),
			SOIL_LOAD_RGB,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_MIPMAPS
		);

	if(tex_cube == 0)
	{
		std::cout << "Error loading images" << std::endl;
		return 0;
	}
	else
	{
		return tex_cube;
	}
}
Beispiel #2
0
	void  TextureManager::LoadCubeMap(string forward,string backward,string top, string bottom, string right, string left)
	{
		
		int textureID=_count+1;// need to assign each texture to each texture unit
		_count++;

		glActiveTexture(GL_TEXTURE0+textureID);
		cout<<"Loading Environment Map...";

		GLuint tex_cube = SOIL_load_OGL_cubemap(
			forward.c_str(),//right   //note this is is in reverse order for left and right?
			backward.c_str(),//left
			top.c_str(),//top
			bottom.c_str(),//bottom
			right.c_str(),//forward
			left.c_str(),//backward
			SOIL_LOAD_RGB,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_MIPMAPS
			);
		if (tex_cube<=0) cout<<"--Error: can't load environment Map texture\n";
		else cout<<"Done\n";

		glBindTexture(GL_TEXTURE_CUBE_MAP, tex_cube);
		// Typical cube map settings
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		
		_cubeMapID=textureID;
	}
Beispiel #3
0
GLuint TextureUtils::loadTextureCube(const char* PosXFilename,
    const char* NegXFilename,
    const char* PosYFilename,
    const char* NegYFilename,
    const char* PosZFilename,
    const char* NegZFilename)
{
    GLuint texture = SOIL_load_OGL_cubemap(
        ResourcesUtils::getResourcePathforFile(PosXFilename),
        ResourcesUtils::getResourcePathforFile(NegXFilename),
        ResourcesUtils::getResourcePathforFile(PosYFilename),
        ResourcesUtils::getResourcePathforFile(NegYFilename),
        ResourcesUtils::getResourcePathforFile(PosZFilename),
        ResourcesUtils::getResourcePathforFile(NegZFilename),
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_MIPMAPS// | SOIL_FLAG_INVERT_Y
        );

    OGLCall(glBindTexture(GL_TEXTURE_CUBE_MAP, texture));
    OGLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
    //    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    //    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    //    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    //    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    if (0 == texture) {
        OErrLog("SOIL loading error: "<< SOIL_last_result() << " \n");
    }

    return texture;
}
//loads images 
void loadImages()
{
	images["skybox"] = SOIL_load_OGL_cubemap("skybox_xp.png", "skybox_xn.png", "skybox_yp.png", "skybox_yn.png", "skybox_zp.png", "skybox_zn.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
	images["font1"] = SOIL_load_OGL_texture("courier.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
	images["cubeTexture"] = SOIL_load_OGL_texture("cubeTexture.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
	images["cubeTexture2"] = SOIL_load_OGL_texture("cubeTexture2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
	images["flagTexture"] = SOIL_load_OGL_texture("flagTexture.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
	images["slimeTexture"] = SOIL_load_OGL_texture("slime.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, NULL);
}
Renderer::Renderer(Window &parent) : OGLRenderer(parent)
{
	camera = new Camera();
	heightMap = new HeightMap(TEXTUREDIR"terrain.raw");
	quad = Mesh::GenerateQuad();

	camera->SetPosition(Vector3(RAW_WIDTH * HEIGHTMAP_X / 2.0f, 500.0f, RAW_WIDTH * HEIGHTMAP_X));

	light = new Light(Vector3((RAW_HEIGHT * HEIGHTMAP_X / 2.0f), 500.0f,( RAW_WIDTH * HEIGHTMAP_X / 2.0f)), 
						Vector4(0.9f, 0.9f, 1.0f, 1), (RAW_WIDTH * HEIGHTMAP_X) / 2.0f);

	reflectShader = new Shader(SHADERDIR "PerPixelVertex.glsl", SHADERDIR "reflectFragment.glsl");

	skyboxShader = new Shader(SHADERDIR "skyboxVertex.glsl", SHADERDIR "skyboxFragment.glsl");

	lightShader = new Shader(SHADERDIR "PerPixelVertex.glsl", SHADERDIR "PerPixelFragment.glsl");

	if(!reflectShader->LinkProgram() || !lightShader->LinkProgram() || !skyboxShader->LinkProgram())
	{
		return;
	}

	//quad->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"water.TGA", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	quad->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"Barren RedsDOT3.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	heightMap->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"Barren Reds.JPG", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	heightMap->SetBumpMap(SOIL_load_OGL_texture(TEXTUREDIR"Barren RedsDOT3.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	cubeMap = SOIL_load_OGL_cubemap(TEXTUREDIR"rusted_west.jpg", TEXTUREDIR"rusted_east.jpg",
									TEXTUREDIR"rusted_up.jpg", TEXTUREDIR"rusted_down.jpg",
									TEXTUREDIR"rusted_south.jpg", TEXTUREDIR"rusted_north.jpg",
									SOIL_LOAD_RGB,
									SOIL_CREATE_NEW_ID, 0);

	if(!cubeMap || !quad->GetTexture() || !heightMap->GetTexture() || !heightMap->GetBumpMap())
	{
		return;
	}

	SetTextureRepeating(quad->GetTexture(), true);
	SetTextureRepeating(heightMap->GetTexture(),true);
	SetTextureRepeating(heightMap->GetBumpMap(),true);

	init = true;
	waterRotate = 0.0f;

	projMatrix = Matrix4::Perspective(1.0f, 15000.0f, (float)width / (float)height, 45.0f);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

}
Beispiel #6
0
void drawSkybox(std::vector<float> & vp, int & g_point, GLuint & vao) {

	int length = sizeof(sky_points) / sizeof(float);
	std::cout << length <<"\n\n";
	for(int i = 0; i < length; i++) {
		vp.push_back (sky_points[i]);
	}
	loc1 = glGetAttribLocation(shaderProgramID, "vertex_position");
	if(length != vp.size())
		std::cout << length << "- length\tvp - " << vp.size() << std::endl;

	g_point = length;
	unsigned int vbo = 0;
	glGenBuffers (1, &vbo);
	glBindBuffer (GL_ARRAY_BUFFER, vbo);
	glBufferData (GL_ARRAY_BUFFER, 3 * 36 * sizeof (float), &vp[0], GL_STATIC_DRAW);

	std::cout << "vao dae: "<< vao <<std::endl;
	glGenVertexArrays (1, &vao);
	
	glBindVertexArray (vao);

	glEnableVertexAttribArray (loc1);
	glBindBuffer (GL_ARRAY_BUFFER, vbo);
	glVertexAttribPointer (loc1, 3, GL_FLOAT, GL_FALSE, 0, NULL);

	texs[0] = SOIL_load_OGL_cubemap (
		RIGHT,
		LEFT,
		BOTTOM,
		TOP,

		BACK,
		FRONT,

		SOIL_LOAD_RGB,
		SOIL_CREATE_NEW_ID,
		0
		);
	glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
	glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	if (0 == texs[0]) {
		printf("SOIL loading error: '%s'\n", SOIL_last_result());
	}

	//	glBindVertexArray(vao);


	//	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_CUBE_MAP, texs[0]);
}
Beispiel #7
0
GLuint loadSoilCubeMap(const char** imagenames, const char* contentPath)
{
    std::string imagePath0 = std::string(contentPath) + std::string(imagenames[0]);
    std::string imagePath1 = std::string(contentPath) + std::string(imagenames[1]);
    std::string imagePath2 = std::string(contentPath) + std::string(imagenames[2]);
    std::string imagePath3 = std::string(contentPath) + std::string(imagenames[3]);
    std::string imagePath4 = std::string(contentPath) + std::string(imagenames[4]);
    std::string imagePath5 = std::string(contentPath) + std::string(imagenames[5]);
	GLuint tex_cube = SOIL_load_OGL_cubemap
	(
		imagePath0.c_str(),
		imagePath1.c_str(),
		imagePath2.c_str(),
		imagePath3.c_str(),
		imagePath4.c_str(),
		imagePath5.c_str(),
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS
	);
	return tex_cube;
}
//Initializes the skybox
bool Renderer::InitSkybox(){
	skyboxShader = new Shader(SHADERDIR"skyboxVertex.glsl",
		SHADERDIR"skyboxFragment.glsl");

	if (!skyboxShader->LinkProgram())
		return false;

	cubeMap = SOIL_load_OGL_cubemap(
		TEXTUREDIR"rusted_west.jpg", TEXTUREDIR"rusted_east.jpg",
		TEXTUREDIR"rusted_up.jpg", TEXTUREDIR"rusted_down.jpg",
		TEXTUREDIR"rusted_south.jpg", TEXTUREDIR"rusted_north.jpg",
		SOIL_LOAD_RGB, SOIL_CREATE_NEW_ID, 0);

	if (!cubeMap)
		return false;

	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

	//Value used to fade the skybox at night
	skyboxLight = 1.0f;

	return true;

}
Beispiel #9
0
///////////////////////////////////////////////////////////
// Draw the skybox. This is just six quads, with texture
// coordinates set to the corners of the cube map
void DrawSkyBox(GLfloat fExtent)
{
	// Sky Box is manually textured
	bool isTexGenEnabled[3] = {0};
	if(glIsEnabled(GL_TEXTURE_GEN_S))
	{
		glDisable(GL_TEXTURE_GEN_S);
		isTexGenEnabled[0] = true;
	}
	if(glIsEnabled(GL_TEXTURE_GEN_T))
	{
		glDisable(GL_TEXTURE_GEN_T);
		isTexGenEnabled[1] = true;
	}
	if(glIsEnabled(GL_TEXTURE_GEN_R))
	{
		glDisable(GL_TEXTURE_GEN_R);
		isTexGenEnabled[2] = true;
	}
	//////////////////////////////////////////////////////////////////////////
	static bool isInitialized = false;
	if(!isInitialized)
	{
		// Six sides of a cube map
		const char *szCubeFaces[6] = { "data/brightday1_posx.bmp", "data/brightday1_negx.bmp", 
			"data/brightday1_posy.bmp", "data/brightday1_negy.bmp", "data/brightday1_posz.bmp", "data/brightday1_negz.bmp" };

		g_CubeMapID = SOIL_load_OGL_cubemap(szCubeFaces[0],szCubeFaces[1],szCubeFaces[2],szCubeFaces[3],szCubeFaces[4],szCubeFaces[5],
			SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS 
			| SOIL_FLAG_COMPRESS_TO_DXT	| SOIL_FLAG_TEXTURE_REPEATS	/*| SOIL_FLAG_INVERT_Y*/);
		// Set up texture maps        
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
		isInitialized = true;
	}

	// Enable cube mapping, and set texture environment to decal
	glEnable(GL_TEXTURE_CUBE_MAP);
	glBindTexture(GL_TEXTURE_CUBE_MAP,g_CubeMapID);	

	glBegin(GL_QUADS);
	//////////////////////////////////////////////
	// Negative X
	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);


	///////////////////////////////////////////////
	//  Postive X
	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);


	////////////////////////////////////////////////
	// Negative Z 
	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);


	////////////////////////////////////////////////
	// Positive Z 
	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);


	//////////////////////////////////////////////////
	// Positive Y
	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);


	///////////////////////////////////////////////////
	// Negative Y
	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);
	glEnd();

	glDisable(GL_TEXTURE_CUBE_MAP);
	// Sky Box is manually textured
	if(isTexGenEnabled[0])
	{
		glEnable(GL_TEXTURE_GEN_S);
	}
	if(isTexGenEnabled[1])
	{
		glEnable(GL_TEXTURE_GEN_T);
	}
	if(isTexGenEnabled[2])
	{
		glEnable(GL_TEXTURE_GEN_R);
	}
}
Beispiel #10
0
MyGame::MyGame()	{
	//Init variables
	ammo = 0;
	force = 0;
	waveno=0;
	
	cube	= new OBJMesh(MESHDIR"cube.obj");
	cube->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!cube->GetTexture()) {
		cout << "barren reds is playing up" << endl;
	}
	quad	= Mesh::GenerateQuad();


	enemy = new OBJMesh(MESHDIR"ico2.obj");
	enemy ->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"leo.png", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!enemy->GetTexture()) {
		cout << "leopard skins f****d" << endl;
	}
	
	sphere	= new OBJMesh(MESHDIR"ico2.obj");
	sphere->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!sphere->GetTexture()) {
		cout << "swirl is BUM" << endl;
	}

	player  = new OBJMesh(MESHDIR"ico2.obj");
	player->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!player->GetTexture()) {
		cout << "cliff is f****d" << endl;
	}
	
	CubeMap = SOIL_load_OGL_cubemap(
		TEXTUREDIR"interstellar_ft.tga", TEXTUREDIR"interstellar_bk.tga",
		TEXTUREDIR"interstellar_up.tga", TEXTUREDIR"interstellar_dn.tga",
		TEXTUREDIR"interstellar_rt.tga", TEXTUREDIR"interstellar_lf.tga", 
		SOIL_LOAD_RGB,
		SOIL_CREATE_NEW_ID,0);
	enemy->SetCubeMap(CubeMap);
	if(!CubeMap)
		cout << "cube maps f*****g broken";
	

	bumpShader = new Shader(SHADERDIR"bumpVertex.glsl",SHADERDIR"bumpFragment.glsl");
	if(!bumpShader->LinkProgram()) {
		return;
	}

	
	enemyShader = new Shader(SHADERDIR"perPixelVertex.glsl",SHADERDIR"enemyFragment.glsl");
	if(!enemyShader->LinkProgram()) {
		return;
	}

	heightmap = new HeightMap(TEXTUREDIR"stage1.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"grass.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(
			TEXTUREDIR"grassbump.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	SetTextureRepeating(heightmap->GetBumpMap(),true);

	if(!heightmap->GetTexture()){
		cout << "height maps f*****g broken" << endl;
	}

	if(!heightmap->GetBumpMap()) {	
		cout << "height map bump map f*****g broken" << endl;
	}

	for(int i = 0; i < NO_PROJECTILES; ++i) {
		projectiles[i] = BuildSphereEntity(25.0f);
		projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i));
		projectiles[i]->GetPhysicsNode().sleep = true;
	}

	for(int i = 0; i < NO_LASERS; ++i) {
		PhysicsSystem::GetPhysicsSystem().AddLaser(buildLaserEntity());

	}
	
	PlanePos = Vector3(2048.0f,100.0f,2048.0f); // y = 450.0f
	playerEntity = buildPlayerEntity();
	PhysicsSystem::GetPhysicsSystem().SetPlayer(playerEntity);
	allEntities.push_back(playerEntity);
	allEntities.push_back(BuildHeightmapEntity());
	
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		allEntities.push_back(projectiles[i]);
	}

	for(int i = 0; i < 10; ++i) {
		EnemyEntity* ee = buildEnemyEntity(Vector3(PlanePos.x + 150,PlanePos.y + 150, PlanePos.z + (i * 90) - 270));
		ee->SetY(100.0f + (100.0f * i));
		allEntities.push_back(ee);
		PhysicsSystem::GetPhysicsSystem().AddEnemy((ee));
	}


	
	//gameCamera = new Camera(-2.0f,270.0f,Vector3(-360.0f,450.0f,3408.0f));
	//gameCamera = new TPCamera();
	gameCamera = new CameraMan(playerEntity->circleT);
	gameCamera->toggleLock();
	Renderer::GetRenderer().SetCamera(gameCamera);

	ret = new Reticule(WIDTH,HEIGHT,FOV,ASPECT, gameCamera);
	//ret->c = gameCamera;
	Renderer::GetRenderer().SetReticule(ret);
	PhysicsSystem::GetPhysicsSystem().SetReticule(ret);

	//ret = new Reticule();
}
Scene::Scene(Window& window) : OGLRenderer(window)
{	
	//used as friend class
	AssetsManager::InitializeMeshes();

	/*m_DebugShader = new Shader(SHADERDIR"debugVertex.glsl", SHADERDIR"debugFragment.glsl");
	if (!m_DebugShader->LinkProgram()){
		return;
	}

	m_DefaultLightShader = new Shader(SHADERDIR"TechVertex.glsl", SHADERDIR"TechLightFragment.glsl");
	if (!m_DefaultLightShader->LinkProgram()){
		return;
	}

	m_DefaultShadowShader = new Shader(SHADERDIR"TechVertex.glsl", SHADERDIR"TechShadowFragment.glsl");
	if (!m_DefaultShadowShader->LinkProgram()){
		return;
	}

	m_ShadowVolumeShader = new Shader(SHADERDIR"TechVertex.glsl", SHADERDIR"PassThroughFragment.glsl", SHADERDIR"ShadowVolumeGeometry.glsl");
	if (!m_ShadowVolumeShader->LinkProgram()){
		return;
	}*/
	SceneShader = new Shader(SHADERDIR"TardisVertex.glsl", SHADERDIR"TardisFragment.glsl");
	if (!SceneShader->LinkProgram()){
		return;
	}

	ShadowShader = new Shader(SHADERDIR"shadowVert.glsl", SHADERDIR"shadowFrag.glsl");
	if (!ShadowShader->LinkProgram()){
		return;
	}
	////*******************************
	////**		CUBE MAP			**
	////*******************************
	////for sky box
	m_skyboxShader = new Shader(SHADERDIR"skyboxVertex.glsl", SHADERDIR"skyboxFragment.glsl");
	if (!m_skyboxShader->LinkProgram()){
		return;
	}

	cubeMap = SOIL_load_OGL_cubemap(
		TEXTUREDIR"skyBox/sky_pos_z.jpg",
		TEXTUREDIR"skyBox/sky_neg_z.jpg",
		TEXTUREDIR"skyBox/sky_pos_y.jpg",
		TEXTUREDIR"skyBox/sky_neg_y.jpg",
		TEXTUREDIR"skyBox/sky_neg_x.jpg",
		TEXTUREDIR"skyBox/sky_pos_x.jpg",
		SOIL_LOAD_RGB, SOIL_CREATE_NEW_ID, 0);

	if (!cubeMap)
	{
		return;
	}
	m_ParticleShader = new Shader(SHADERDIR"ParticleVertex.glsl",
		SHADERDIR"ParticleFragment.glsl",
		SHADERDIR"ParticleGeometry.glsl");

	if (!m_ParticleShader->LinkProgram()) {
		return;
	}

	m_RootParticleList = new ParticleEmitter();

	m_Camera = new Camera();
	m_RootGameObject = new GameObject();	//root is created here

	m_RootGameObject->m_Scene = this;

	m_AmbientColour = Vector3(0.2f, 0.2f, 0.2f);
	m_InvLightDirection = Vector3(0.5f, 1.0f, -0.8f);
	m_SpecularIntensity = 128.0f;

	m_InvLightDirection.Normalise();

	m_ScreenDTex = NULL;
	m_ScreenCTex = NULL;
	m_ScreenFBO = NULL;
	BuildScreenFBO();

	clearcolor = Vector4(0.6f, 0.6f, 0.6f, 1.f);
	glClearColor(clearcolor.x, clearcolor.y, clearcolor.z, clearcolor.w);

	NCLDebug::LoadShaders();

	init = true;

	lightList.push_back(Light(Vector3(0, 175, 0),//position
		Vector4(1, 1, 1, 1), //light color
		600.0f //light radius
		, 2.0f // brightness
		, Vector3(1, 1, 1)
		));
	lightList.push_back(Light(Vector3(0, 1.5f, 0),//position
		Vector4(1, 1, 1, 1), //light color
		1.0f //light radius
		, 50.0f // brightness
		, Vector3(1, 1, 1)
		));
	

	glGenTextures(1, &shadowTex);
	glBindTexture(GL_TEXTURE_2D, shadowTex);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
		SHADOWSIZE, SHADOWSIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
		GL_COMPARE_R_TO_TEXTURE);
	glBindTexture(GL_TEXTURE_2D, 0);

	// create shadow FBO and bind depth texture
		glGenFramebuffers(1, &shadowFBO);
	glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
	//for (int i = 0; i < 6; i++) {
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowTex, 0);
	glDrawBuffer(GL_NONE);
	//}
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glEnable(GL_DEPTH_TEST);

}
Beispiel #12
0
	/*!
	 *	Loads a cube map texture consisting of 6 textures, one for every spatial direction.
	 *	+X, -X, +Y, -Y, +Z, -Z
	 *
	 *	@return
	 */
	void MaterialManager::LoadCubeMap(std::string filename)
	{
		std::string suffixes[] = {"posx", "negx", "posy", "negy", "posz", "negz"};
		std::string filenames[6];
		std::string fileext = ".tga";
		filenames[0] = filename + "_" + suffixes[0] + fileext;
		filenames[1] = filename + "_" + suffixes[1] + fileext;
		filenames[2] = filename + "_" + suffixes[2] + fileext;
		filenames[3] = filename + "_" + suffixes[3] + fileext;
		filenames[4] = filename + "_" + suffixes[4] + fileext;
		filenames[5] = filename + "_" + suffixes[5] + fileext;

		std::cout << filenames[0] << std::endl;

		GLuint cubemap_id;
		m_cubemaps.push_back(cubemap_id);

		glActiveTexture(GL_TEXTURE0);
		glGenTextures(1, &m_cubemaps[m_cubemapCounter]);
		glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubemaps[m_cubemapCounter]);

		//! Loading cube maps with SOIL
		m_cubemaps[m_cubemapCounter] = SOIL_load_OGL_cubemap(
				filenames[0].c_str(),
				filenames[1].c_str(),
				filenames[2].c_str(),
				filenames[3].c_str(),
				filenames[4].c_str(),
				filenames[5].c_str(),
				SOIL_LOAD_RGB,
				SOIL_CREATE_NEW_ID,
				SOIL_FLAG_COMPRESS_TO_DXT
		);

		//! Loading cube maps with DevIL
		/*
		ILboolean loadSuccess;
		GLuint cubemap_targets[] = {
			GL_TEXTURE_CUBE_MAP_POSITIVE_X,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
			GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
			GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
			GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
		};

		//! Load cubemap images
		for(int i=0; i < 6; i++)
		{
			std::string m_filename = filename + "_" + suffixes[i] + ".tga";
			loadSuccess = ilLoadImage(m_filename .c_str());
			glTexImage2D(	cubemap_targets[i],
							0,
							ilGetInteger(IL_IMAGE_BPP),
							ilGetInteger(IL_IMAGE_WIDTH),
							ilGetInteger(IL_IMAGE_HEIGHT),
							0,
							ilGetInteger(IL_IMAGE_FORMAT),
							GL_UNSIGNED_BYTE,
							ilGetData());
			if(!loadSuccess)
			{
				ErrorCheckTexture = ilGetError();
				std::cout << "ERROR | DeVIL: Image load error " << iluErrorString(ErrorCheckTexture) << std::endl;
			}
			else
				std::cout << "DeVIL: cubemap was generated from " << m_filename << "!" << std::endl;
		}
		//! Typical cube map settings
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		*/

		m_cubemapCounter++;
	}