Exemple #1
0
void init(void)
{
  forward = SetVector(1,1,1);
  // GL inits
  glClearColor(0.2,0.2,0.5,0);
   glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  glCullFace(GL_BACK);
  printError("GL inits");

  projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 500.0);

  // Load and compile shader
  
  programSky = loadShaders("sky.vert", "sky.frag");
  skybox = LoadModelPlus("skybox.obj");
  program = loadShaders("terrain.vert", "terrain.frag");
  //goal = LoadModelPlus("cube.obj"); // If I put this here the walls get darker
  
  printError("init shader");
	
  
  glUseProgram(programSky);
  glActiveTexture(GL_TEXTURE2);	 
  glUniform1i(glGetUniformLocation(programSky, "tex"),2); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, myTex);
  LoadTGATextureSimple("SkyBox512.tga", &myTex); 

	  glActiveTexture(GL_TEXTURE3);	 
  glUniform1i(glGetUniformLocation(program, "tex"),3); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex3);
  LoadTGATextureSimple("gold.tga", &tex3);

  glUseProgram(program);
  glActiveTexture(GL_TEXTURE0);	
  glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
  glUniform1i(glGetUniformLocation(program, "tex"),0); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex1);
  LoadTGATextureSimple("maskros512.tga", &tex1);

  glActiveTexture(GL_TEXTURE1);	 
  glUniform1i(glGetUniformLocation(program, "tex"),1); // Texture unit 1
  glBindTexture(GL_TEXTURE_2D, tex2);
  LoadTGATextureSimple("dirt.tga", &tex2);
  // Load terrain data
	

  
  LoadTGATextureData("MazeWall.tga", &ttexm);
  LoadTGATextureData("fft-terrain.tga", &ttex);
  tm = GenerateMazeTerrain(&ttexm,&ttex,vertexArray);
  mm = GenerateTerrain(&ttex,vertexArray);
  goal = LoadModelPlus("groundsphere.obj"); // The walls do not get darker
  printError("init terrain");


	sfMakeRasterFont(); // init font
	sfSetRasterSize(600, 200);
}
Exemple #2
0
void init(void)
{
    // GL inits
    glClearColor(0.2,0.2,0.5,0);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    printError("GL inits");

    projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 50.0);

    // Load and compile shader
    program = loadShaders("shaders/terrain.vert", "shaders/terrain.frag");
    glUseProgram(program);
    printError("init shader");

    glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
    LoadTGATextureSimple("maskros512.tga", &tex1);

// Load terrain data

    LoadTGATextureData("fft-terrain.tga", &ttex);
    tm = GenerateTerrain(&ttex);
    printError("init terrain");
}
Exemple #3
0
bool LoadTGATexture(char *filename, TextureData *texture)	// Loads A TGA File Into Memory and uploads to VRAM
{
	bool result = LoadTGATextureData(filename, texture); // Loads A TGA File Into Memory
	if (!result)
		return result;
	
	GLuint type = GL_RGBA;		// Set The Default GL Mode To RBGA (32 BPP)
	int h, w;

	w = 1;
	while (w < texture->width) w = w << 1;
	h = 1;
	while (h < texture->height) h = h << 1;
	
	// Build A Texture From The Data
	glGenTextures(1, &texture[0].texID);			// Generate OpenGL texture IDs
	glBindTexture(GL_TEXTURE_2D, texture[0].texID);		// Bind Our Texture
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtered
//	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	// Linear Filtered
	if (texture[0].bpp == 24)						// Was The TGA 24 Bits?
	{
		type=GL_RGB;			// If So Set The 'type' To GL_RGB
	}
//	gluBuild2DMipmaps(GL_TEXTURE_2D, type, w, h, type, GL_UNSIGNED_BYTE, texture[0].imageData);
	glTexImage2D(GL_TEXTURE_2D, 0, type, w, h, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);
	
	return result;
}
Exemple #4
0
bool LoadTGATexture(char *filename, TextureData *texture)	// Loads A TGA File Into Memory and creates texture object
{
	char ok;
	GLuint type = GL_RGBA;		// Set The Default GL Mode To RBGA (32 BPP)
	
	ok = LoadTGATextureData(filename, texture);	// Loads A TGA File Into Memory
	if (!ok)
		return false;

	// Build A Texture From The Data
	glGenTextures(1, &texture->texID);			// Generate OpenGL texture IDs
	glBindTexture(GL_TEXTURE_2D, texture->texID);		// Bind Our Texture
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtered
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// Linear Filtered
	if (texture->bpp == 24)						// Was The TGA 24 Bits?
	{
		type=GL_RGB;			// If So Set The 'type' To GL_RGB
	}
	glTexImage2D(GL_TEXTURE_2D, 0, type, texture->w, texture->h, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);
	
	if (gMipmap)
	{
		glGenerateMipmap(GL_TEXTURE_2D);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	// Linear Filtered
	}
	
	return true;				// Texture Building Went Ok, Return True
}
Exemple #5
0
void CreateCubeHeightMaps(TextureData* terrainTextures[6], mat4 terrainTransformationMatrix[6], struct PlanetStruct* planet)
{
		GLuint i;	
		for(i = 0; i < 6; i++)
		{
			terrainTextures[i] = chkmalloc(sizeof(TextureData));
		}

		// Load terrain data
		for (i = 0; i < 6; i++)
			if(fuzzy == 0)
				LoadTGATextureData("textures/fft-terrain.tga", terrainTextures[i]);
			else
				LoadTGATextureData("testTGA.tga", terrainTextures[i]);


		//Generate terrain model matrix

		planet->terrainWidth = (GLfloat)terrainTextures[0]->width;
		planet->terrainHeight = (GLfloat)terrainTextures[0]->height;
		GLfloat distanceToMiddleX = ((GLfloat)terrainTextures[0]->width*0.5f);
		GLfloat distanceToMiddleZ = ((GLfloat)terrainTextures[0]->height*0.5f);
		GLfloat distanceToMiddleY = planet->radius;

		for (i = 0; i < 4; ++i)
		{
			terrainTransformationMatrix[i] = T(-distanceToMiddleX, distanceToMiddleY, -distanceToMiddleZ);
			terrainTransformationMatrix[i] = Mult( Rz(M_PI*0.5f*(GLfloat)i), terrainTransformationMatrix[i] );
		}

		//Last two sides
		for (i = 0; i < 2; ++i)
		{
			terrainTransformationMatrix[4+i] = T(-distanceToMiddleX, distanceToMiddleY, -distanceToMiddleZ);
			terrainTransformationMatrix[4+i] = Mult( Rx(M_PI*(0.5f+(GLfloat)i)), terrainTransformationMatrix[4+i] );
		}

		//Weird offset: (Probably size dependent)
		terrainTransformationMatrix[1] = Mult(T(0, 1, 0), terrainTransformationMatrix[1]);
		terrainTransformationMatrix[2] = Mult(T(-1, 1, 0), terrainTransformationMatrix[2]);
		terrainTransformationMatrix[3] = Mult(T(-1, 0, 0), terrainTransformationMatrix[3]);
		terrainTransformationMatrix[4] = Mult(T(0, 0, -1), terrainTransformationMatrix[4]);
		terrainTransformationMatrix[5] = Mult(T(0, 1, 0), terrainTransformationMatrix[5]);

}
Exemple #6
0
void init(void)
{

	p = SetVector(20, 20, 0);
	l = SetVector(0,0,-1);
	v = SetVector(0,1,0);

	// GL inits
	glClearColor(0.2,0.2,0.5,0);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	printError("GL inits");

	projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 50.0);

	// Load and compile shader
	program = loadShaders("terrain4.vert", "terrain4.frag");
	glUseProgram(program);
	printError("init shader");
	
	glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);

	LoadTGATextureSimple("maskros512.tga", &tex1);
	LoadTGATextureSimple("dirt.tga", &tex2);


	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, tex1);
	glUniform1i(glGetUniformLocation(program, "texUnit0"), 0); // Texture unit 0
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex2);
	glUniform1i(glGetUniformLocation(program, "texUnit1"), 1);

// Load terrain data
	
	LoadTGATextureData("fft-terrain.tga", &ttex);
	tm = GenerateTerrain(&ttex);
	TextureData *texturePointer = &ttex;
	texWidth = texturePointer->width;
	printError("init terrain");
// Load objects
sphere = LoadModelPlus("groundsphere.obj");

}
Exemple #7
0
void init(void)
{
  forward = SetVector(1,1,1);
  // GL inits
  glClearColor(0.2,0.2,0.5,0);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  printError("GL inits");

  projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 500.0);

  // Load and compile shader
  program = loadShaders("terrain.vert", "terrain.frag");
  glUseProgram(program);
  printError("init shader");
	
  glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
  glActiveTexture(GL_TEXTURE0);	
  glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
  LoadTGATextureSimple("grass.tga", &tex1);

  //  glActiveTexture(GL_TEXTURE1);	
  //glUniform1i(glGetUniformLocation(program, "tex"),1); // Texture unit 0
  //  LoadTGATextureSimple("dirt.tga", &tex2);

	
  // Load terrain data
	
  LoadTGATextureData("fft-terrain.tga", &ttex);
  tm = GenerateTerrain(&ttex);
  printError("init terrain");

  //
  bunny= LoadModelPlus("bunnyplus.obj");

}
SkyCube::SkyCube(GLuint program)
: myDrawable(program) {
	/* Initialize skycube */
	model = generateCube(10.0f);

	// Creating cubemap texture
	glGenTextures(1, &textureID);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);

	TextureData texture1;
	memset(&texture1, 0, sizeof(texture1));
	TextureData texture2;
	memset(&texture2, 0, sizeof(texture2));
	TextureData texture3;
	memset(&texture3, 0, sizeof(texture3));
	TextureData texture4;
	memset(&texture4, 0, sizeof(texture4));
	TextureData texture5;
	memset(&texture5, 0, sizeof(texture5));
	TextureData texture6;
	memset(&texture6, 0, sizeof(texture6));

	LoadTGATextureData("resources/Skycube/Xn.tga", &texture1);
	LoadTGATextureData("resources/Skycube/Xp.tga", &texture2);
	LoadTGATextureData("resources/Skycube/Yn.tga", &texture3);
	LoadTGATextureData("resources/Skycube/Yp.tga", &texture4);
	LoadTGATextureData("resources/Skycube/Zn.tga", &texture5);
	LoadTGATextureData("resources/Skycube/Zp.tga", &texture6);

	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, texture1.width, texture1.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1.imageData);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, texture2.width, texture2.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture2.imageData);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, texture3.width, texture3.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture3.imageData);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, texture4.width, texture4.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture4.imageData);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, texture5.width, texture5.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture5.imageData);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, texture6.width, texture6.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture6.imageData);

	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);
}
Exemple #9
0
void init(void)
{
    
    printf("i1 \n");
    sfMakeRasterFont();
    
    sphere = LoadModelPlus("./OBJ/groundsphere.obj");
    
    camera = lookAt(0.0,2.0,-8.0,
                    0.0,0.0,0.0,
                    0.0,1.0,0.0);
    srand (time(NULL));
    
    skytot = T(0.0,0.0,0.0);
    lavatot = Mult(T(0,-1, 0), S(20, 0, 20));
    
    // GL inits
    glClearColor(0.2,0.2,0.5,0);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    printError("GL inits");
    
    projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 100.0);
    
    printf("i2 \n");
    // Load and compile shader
    program = loadShaders("./Shader/terrain.vert", "./Shader/terrain.frag");
    skyprogram = loadShaders("./Shader/sky.vert", "./Shader/sky.frag");
    glUseProgram(program);
    printError("init shader");
    
    glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0
    LoadTGATextureSimple("./TGA/lavaroad.tga", &tex1);
    LoadTGATextureSimple("./TGA/conc.tga", &tex2);
    

    printf("i3 \n");
    // Load terrain data
    InitTerrain();
    
    LoadTGATextureData("./TGA/fft-terrain.tga", &ttex);
    printError("init terrain");
    
    //Body
    LoadTGATextureSimple("./TGA/tex_01_lfy_weapon1out.tga", &tex_head);
    LoadTGATextureSimple("./TGA/red.tga", &tex_body);
    
    LegR = LoadModelPlus("./OBJ/LegR.obj");//Load Right Leg
    LegL = LoadModelPlus("./OBJ/LegL.obj");//Load Left Leg
    Body = LoadModelPlus("./OBJ/groundsphere.obj"); //Load Body & head
    ArmR = LoadModelPlus("./OBJ/armr.obj");//Load Right Arm
    ArmL = LoadModelPlus("./OBJ/arml.obj");//Load Right Arm
    printf("i4 \n");
    //boost & Obst
    LoadTGATextureSimple("./TGA/red.tga", &startex);
    LoadTGATextureSimple("./TGA/speed.tga", &speedtex);
    LoadTGATextureSimple("./TGA/imortal.tga", &imortaltex);
    //LoadTGATextureSimple("./TGA/spike.tga", &gatetex);
    LoadTGATextureSimple("./TGA/dirt.tga", &gatetex); //NY ANDREAS

    Star = LoadModelPlus("./OBJ/groundsphere.obj");//extra points
    SpeedObj = LoadModelPlus("./OBJ/groundsphere.obj");//speed
    Imortal = LoadModelPlus("./OBJ/groundsphere.obj");//speed

    //Gate = LoadModelPlus("./OBJ/spike.obj");//gate
    Gate = LoadModelPlus("./OBJ/gatecube.obj");//gate //NY ANDREREAS

    
    
    // Lava Ground
    Lava = LoadModelPlus("./OBJ/ground.obj");//load ground aka lava
    LoadTGATextureSimple("./TGA/lava.tga", &lavatex); //load the lava texture
    
    //Sky
    skybox = LoadModelPlus("./OBJ/cubeplus.obj");//Load skybox
    glUseProgram(skyprogram);
    glUniformMatrix4fv(glGetUniformLocation(skyprogram, "projMatrix"), 1, GL_TRUE, projectionMatrix.m);
    LoadTGATextureSimple("./TGA/skybox2.tga", &skytex); 	// Texture unit 1
    glUseProgram(program);
    
}
	StaticModel* ModelLoader::GenerateTerrain(VulkanBase* vulkanBase, std::string filename)
	{
		// Check if the model already is loaded
		if (mModelMap.find(filename) != mModelMap.end())
			return mModelMap[filename];

		// Load the terrain froma .tga file
		TextureData texture;
		LoadTGATextureData((char*)filename.c_str(), &texture);

		StaticModel* terrain = new StaticModel;
		Mesh mesh;

		int vertexCount = texture.width * texture.height;
		int triangleCount = (texture.width - 1) * (texture.height - 1) * 2;
		int x, z;

		mesh.vertices.resize(vertexCount);
		mesh.indices.resize(triangleCount * 3);

		printf("bpp %d\n", texture.bpp);
		for (x = 0; x < texture.width; x++)
			for (z = 0; z < texture.height; z++)
			{
				// Vertex array. You need to scale this properly
				float height = texture.imageData[(x + z * texture.width) * (texture.bpp / 8)] / 15.0f;

				vec3 pos = vec3(x / 1.0, height, z / 1.0);
				vec3 normal = vec3(0, 0, 0);
				vec2 uv = vec2(x / (float)texture.width, z / (float)texture.height);

				Vertex vertex = Vertex(pos, normal, uv, vec3(0, 0, 0), vec3(1.0, 1.0, 1.0));
				mesh.vertices[x + z * texture.width] = vertex;
			}

		// Normal vectors. You need to calculate these.
		for (x = 0; x < texture.width; x++)
		{
			for (z = 0; z < texture.height; z++)
			{
				vec3 p1, p2, p3;
				vec3 edge = { 0.0f, 0.0f, 0.0f };
				int i1;

				// p1 [x-1][z-1]
				if (x < 1 && z < 1)
					i1 = (x + 1 + (z + 1) * texture.width);
				else
					i1 = (x - 1 + (z - 1) * texture.width);

				// TODO: NOTE: HAX
				if (i1 < 0)
					i1 = 0;

				p1 = mesh.vertices[i1].Pos;

				// p1 [x-1][z] (if on the edge use [x+1] instead of [x-1])
				int i2;
				if (x < 1)
					i2 = (x + 1 + (z)* texture.width);
				else
					i2 = (x - 1 + (z)* texture.width);

				p2 = mesh.vertices[i2].Pos;

				// p1 [x][z-1]
				int i3;
				if (z < 1)
					i3 = (x + (z + 1) * texture.width);
				else
					i3 = (x + (z - 1) * texture.width);

				p3 = mesh.vertices[i3].Pos;

				vec3 e1 = p2 - p1;
				vec3 e2 = p3 - p1;
				vec3 normal = glm::cross(e2, e1);

				if (normal != vec3(0, 0, 0))
					int asda = 1;

				normal = glm::normalize(normal);

				//i = (x + 1 + (z + 1) * texture.width);
				mesh.vertices[i1].Normal += normal;
				mesh.vertices[i2].Normal += normal;
				mesh.vertices[i3].Normal += normal;

				// NOTE: Testing
				//mesh.vertices[i].Normal = vec3(0, 0, 0);
			}
		}

		for (x = 0; x < texture.width - 1; x++)
		{
			for (z = 0; z < texture.height - 1; z++)
			{
				// Triangle 1
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 0] = x + z * texture.width;
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 1] = x + (z + 1) * texture.width;
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 2] = x + 1 + z * texture.width;
				// Triangle 2
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 3] = x + 1 + z * texture.width;
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 4] = x + (z + 1) * texture.width;
				mesh.indices[(x + z * (texture.width - 1)) * 6 + 5] = x + 1 + (z + 1) * texture.width;
			}
		}

		// Now loop through each vertex vector, and average out all the normals stored.
		for (int i = 0; i < mesh.vertices.size(); ++i)
		{
			mesh.vertices[i].Normal = glm::normalize(mesh.vertices[i].Normal);
		}

		terrain->AddMesh(mesh);
		terrain->BuildBuffers(vulkanBase);

		// Add to the map
		mModelMap[filename] = terrain;

		return terrain;
	}