Ejemplo n.º 1
0
void initScene()
{
  currentTicks=SDL_GetTicks();
  totalTime=0.0f;
  //createFramebuffer();
  string modelPath = ASSET_PATH + MODEL_PATH + "/armoredrecon.fbx";
  auto currentGameObject = loadFBXFromFile(modelPath);
  
  string vsPath = ASSET_PATH + SHADER_PATH + "/specularVS.glsl";
  string fsPath = ASSET_PATH + SHADER_PATH + "/specularFS.glsl";
  currentGameObject->loadShader(vsPath, fsPath);
  
  gameObjects.push_back(currentGameObject);
  currentGameObject->setPosition(vec3(0.0f, -10.0f, 0.0f));
  
  modelPath = ASSET_PATH + MODEL_PATH + "/sphere-highpoly.fbx";//
  currentGameObject = loadFBXFromFile(modelPath);
  vsPath = ASSET_PATH + SHADER_PATH + "/textureVS.glsl";
  fsPath = ASSET_PATH + SHADER_PATH + "/textureFS.glsl";
  currentGameObject->loadShader(vsPath, fsPath);
  currentGameObject->setScale(vec3(10.0f, 10.0f, 10.0f));
  
  string texturePath = ASSET_PATH + TEXTURE_PATH + "/mercurymap.png";
  currentGameObject->loadDiffuseMap(texturePath);
  
  gameObjects.push_back(currentGameObject);
}
Ejemplo n.º 2
0
void initScene()
{
	currentTicks=SDL_GetTicks();
	totalTime=0.0f;
	createFramebuffer();
  //shared_ptr<Material> planets=shared_ptr<Material>(new Material);
  string mercuryDiffuse=ASSET_PATH+TEXTURE_PATH+"/mercurymap.jpg";
	string modelPath = ASSET_PATH + MODEL_PATH + "/sphere-highpoly.fbx";
	auto currentGameObject = loadFBXFromFile(modelPath);
  //planets->loadDiffuseMap(mercuryDiffuse);
  //mercury=shared_ptr<GameObject>(new GameObject);
  //mercury->setMaterial(planets);
	string vsPath = ASSET_PATH + SHADER_PATH + "/specularVS.glsl";
	string fsPath = ASSET_PATH + SHADER_PATH + "/specularFS.glsl";
	currentGameObject->loadShader(vsPath, fsPath);
 
	currentGameObject->setScale(vec3(10.1f, 10.0f, 10.0f));

	gameObjects.push_back(currentGameObject);

	modelPath = ASSET_PATH + MODEL_PATH + "/armoredrecon.fbx";
	currentGameObject = loadFBXFromFile(modelPath);
	currentGameObject->loadShader(vsPath, fsPath);
	gameObjects.push_back(currentGameObject);

}
Ejemplo n.º 3
0
void initScene()
{

	string modelPath = ASSET_PATH + MODEL_PATH + "/armoredrecon.fbx";
	loadFBXFromFile(modelPath, &currentMesh);
	//Generate Vertex Array
	glGenVertexArrays(1, &VAO);
	glBindVertexArray(VAO);
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);

	glBufferData(GL_ARRAY_BUFFER, currentMesh.getNumVerts()*sizeof(Vertex), &currentMesh.vertices[0], GL_STATIC_DRAW);

	//create buffer
	glGenBuffers(1, &EBO);
	//Make the EBO active
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
	//Copy Index data to the EBO
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, currentMesh.getNumIndices()*sizeof(int), &currentMesh.indices[0], GL_STATIC_DRAW);

	//Tell the shader that 0 is the position element
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), NULL);

	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void**)(sizeof(vec3)));

	glEnableVertexAttribArray(2);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void**)(sizeof(vec3) + sizeof(vec4)));

	GLuint vertexShaderProgram = 0;
	string vsPath = ASSET_PATH + SHADER_PATH + "/simpleVS.glsl";
	vertexShaderProgram = loadShaderFromFile(vsPath, VERTEX_SHADER);
	checkForCompilerErrors(vertexShaderProgram);

	GLuint fragmentShaderProgram = 0;
	string fsPath = ASSET_PATH + SHADER_PATH + "/simpleFS.glsl";
	fragmentShaderProgram = loadShaderFromFile(fsPath, FRAGMENT_SHADER);
	checkForCompilerErrors(fragmentShaderProgram);

	shaderProgram = glCreateProgram();
	glAttachShader(shaderProgram, vertexShaderProgram);
	glAttachShader(shaderProgram, fragmentShaderProgram);

	//Link attributes
	glBindAttribLocation(shaderProgram, 0, "vertexPosition");
	glBindAttribLocation(shaderProgram, 1, "vertexColour");
	glBindAttribLocation(shaderProgram, 2, "vertexTexCoords");

	glLinkProgram(shaderProgram);
	checkForLinkErrors(shaderProgram);
	//now we can delete the VS & FS Programs
	glDeleteShader(vertexShaderProgram);
	glDeleteShader(fragmentShaderProgram);
}
Ejemplo n.º 4
0
Model::Model(const string& fileName)
{
	vertices = new vector<Vertex>();
	indices = new vector<int>();

	if (!loadFBXFromFile(fileName))
	{
		printf("Error loading model!\n");
		return;
	}
	//printf("Verts: %d Ints: %d\n", vertices->size(), indices->size());

	//generate and bind vao so that it keeps the current vbo and ebo and attribs
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	CHECK_GL_ERROR();

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * GetVertCount(), vertices->data(), GL_STATIC_DRAW);
	CHECK_GL_ERROR();

	glGenBuffers(1, &ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * GetIndCount(), indices->data(), GL_STATIC_DRAW);
	CHECK_GL_ERROR();

	//tell the VAO that 1 is the position element
	SetUpAttrib(0, 3, GL_FLOAT, 0);

	//tell the VAO that 1 is the color element
	SetUpAttrib(1, 4, GL_FLOAT, sizeof(vec3));

	//uv
	SetUpAttrib(2, 2, GL_FLOAT, sizeof(vec3) + sizeof(vec4));

	//normals
	SetUpAttrib(3, 3, GL_FLOAT, sizeof(vec3) + sizeof(vec4) + sizeof(vec2));

	//tangent
	SetUpAttrib(4, 3, GL_FLOAT, sizeof(vec3) + sizeof(vec4) + sizeof(vec2) + sizeof(vec3));

	//binormal
	SetUpAttrib(5, 3, GL_FLOAT, sizeof(vec3) + sizeof(vec4) + sizeof(vec2) + sizeof(vec3) + sizeof(vec3));

	GenerateBoundSphere();
}
Ejemplo n.º 5
0
void neptuneLoader()
{
    string modelPath = ASSET_PATH + MODEL_PATH + "/Planet.fbx";
    auto currentGameObject = loadFBXFromFile(modelPath);
    string vsPath = ASSET_PATH + SHADER_PATH + "/textureVS.glsl";
    string fsPath = ASSET_PATH + SHADER_PATH + "/textureFS.glsl";
    currentGameObject->loadShader(vsPath, fsPath);
    currentGameObject->setScale(vec3(0.9f, 0.9f, 0.9f));
    currentGameObject->setPosition(vec3(95.0f, 0.0f, 0.0f));
    
    currentGameObject->setRotationSpeed(vec3(0.0f, -1.0f, 0.0f));
    currentGameObject->setOrbitSpeed(vec3(0.0f, 0.78f, 0.0f));
    
    string texturePath = ASSET_PATH + TEXTURE_PATH + "/NeptuneColourMap.png";
    currentGameObject->loadDiffuseMap(texturePath);
    
    gameObjects.push_back(currentGameObject);
}
Ejemplo n.º 6
0
void marsLoader()
{
    string modelPath = ASSET_PATH + MODEL_PATH + "/Planet.fbx";
    auto currentGameObject = loadFBXFromFile(modelPath);
  string vsPath = ASSET_PATH + SHADER_PATH + "/specularVS.glsl";
  string fsPath = ASSET_PATH + SHADER_PATH + "/specularFS.glsl";
    currentGameObject->loadShader(vsPath, fsPath);
    currentGameObject->setScale(vec3(0.45f, 0.45f, 0.45f));
    currentGameObject->setPosition(vec3(42.0f, 0.0f, 0.0f));
    
    currentGameObject->setRotationSpeed(vec3(0.0f, -1.0f, 0.0f));
    currentGameObject->setOrbitSpeed(vec3(0.0f, 2.5f, 0.0f));
    
    string texturePath = ASSET_PATH + TEXTURE_PATH + "/MarsColourMap2.png";
    currentGameObject->loadDiffuseMap(texturePath);
    
    gameObjects.push_back(currentGameObject);
}
Ejemplo n.º 7
0
void earthLoader()
{
    string modelPath = ASSET_PATH + MODEL_PATH + "/Planet.fbx";
    auto currentGameObject = loadFBXFromFile(modelPath);
  string vsPath = ASSET_PATH + SHADER_PATH + "/specularVSTest.glsl";
  string fsPath = ASSET_PATH + SHADER_PATH + "/specularFSTest.glsl";
    currentGameObject->loadShader(vsPath, fsPath);
    currentGameObject->setScale(vec3(0.5f, 0.5f, 0.5f));

    currentGameObject->setPosition(vec3(35.0f, 0.0f, 0.0f));

    currentGameObject->setRotationSpeed(vec3(0.0f, -1.0f, 0.0f));
    currentGameObject->setOrbitSpeed(vec3(0.0f, 3.0f, 0.0f));

    string texturePath = ASSET_PATH + TEXTURE_PATH + "/EarthColourMap.png";
   string tecture2Path = ASSET_PATH + TEXTURE_PATH + "/EarthSpecMap.png";
    currentGameObject->loadDiffuseMap(texturePath);
     currentGameObject->LoadSpecularMap(tecture2Path);
  
    gameObjects.push_back(currentGameObject);
}
Ejemplo n.º 8
0
void createBasicObject(std::string modelName,
	std::string gameObjectName,
	std::string diffTexture,
	std::string specTexture,
	std::string bumpTexture,
	std::string heightTexture,
	std::string renderType)
{
	// Load a 3D model + all of it's children as GameObjects as well as choose the appropriate shader to be used -AM
	std::string modelPath = ASSET_PATH + MODEL_PATH + "/" + modelName + ".fbx";
	GameObject * go = loadFBXFromFile(modelPath);
	go->setName(gameObjectName);
	for (int i = 0; i < go->getChildCount(); i++)
	{
		Material * material = new Material();
		material->init();
		if (renderType == "directional")
		{
			std::string vsPath = ASSET_PATH + SHADER_PATH + "/directionalLightTextureVS.glsl";
			std::string fsPath = ASSET_PATH + SHADER_PATH + "/directionalLightTextureFS.glsl";
			material->loadShader(vsPath, fsPath);
		}

		if (renderType == "point")
		{
			std::string vsPath = ASSET_PATH + SHADER_PATH + "/PointLightTextureVS.glsl";
			std::string fsPath = ASSET_PATH + SHADER_PATH + "/PointLightTextureFS.glsl";
			material->loadShader(vsPath, fsPath);
		}

		if (renderType == "diffuse")
		{
			std::string vsPath = ASSET_PATH + SHADER_PATH + "/diffuseVS.glsl";
			std::string fsPath = ASSET_PATH + SHADER_PATH + "/diffuseFS.glsl";
			material->loadShader(vsPath, fsPath);

			material->setDiffuseColour(0.5f, 0.5f, 0.5f, 1.0f);
		}

		if (renderType == "bump")
		{
			std::string vsPath = ASSET_PATH + SHADER_PATH + "/bumpMappingVS.glsl";
			std::string fsPath = ASSET_PATH + SHADER_PATH + "/bumpMappingFS.glsl";
			material->loadShader(vsPath, fsPath);
		}

		if (renderType == "texture")
		{
			std::string vsPath = ASSET_PATH + SHADER_PATH + "/textureVS.glsl";
			std::string fsPath = ASSET_PATH + SHADER_PATH + "/textureFS.glsl";
			material->loadShader(vsPath, fsPath);
		}


		std::string diffTexturePath = ASSET_PATH + TEXTURE_PATH + "/" + diffTexture;
		material->loadDiffuseMap(diffTexturePath);

		std::string specTexturePath = ASSET_PATH + TEXTURE_PATH + "/" + specTexture;
		material->loadSpecularMap(specTexturePath);

		std::string bumpTexturePath = ASSET_PATH + TEXTURE_PATH + "/" + bumpTexture;
		material->loadBumpMap(bumpTexturePath);

		std::string heightTexturePath = ASSET_PATH + TEXTURE_PATH + "/" + heightTexture;
		material->loadHeightMap(heightTexturePath);

		go->getChild(i)->setMaterial(material);
	}
	Scene::m_currentScene->getDisplayList()->push_back(go);
}