Ejemplo n.º 1
0
void GameManager::createSimpleProgram() {
	std::string fs_src = readFile("shaders/test.frag");
	std::string vs_src = readFile("shaders/test.vert");

	//Compile shaders, attach to program object, and link
	program.reset(new Program(vs_src, fs_src));

	//Set uniforms for the program.
	program->use();
	glUniformMatrix4fv(program->getUniform("projection_matrix"), 1, 0, glm::value_ptr(projection_matrix));
	program->disuse();
}
Ejemplo n.º 2
0
std::shared_ptr<GLUtils::Program> GameManager::createProgram( std::string vs_path, std::string fs_Path, bool setProjM)
{
	std::shared_ptr<GLUtils::Program> program;
	std::string fs_src = readFile(fs_Path);
	std::string vs_src = readFile(vs_path);

	//Compile shaders, attach to program object, and link
	program.reset(new Program(vs_src, fs_src));

	//Set uniforms for the program.
	program->use();
	if(setProjM)
		glUniformMatrix4fv(program->getUniform("projection_matrix"), 1, 0, glm::value_ptr(projection_matrix));
	program->disuse();
	return program;
}
Ejemplo n.º 3
0
void GameManager::createHeightProgram() {
	std::string fs_src = readFile("shaders/height.frag");
	std::string vs_src = readFile("shaders/height.vert");
	
	//Compile shaders, attach to program object, and link
	height_program.reset(new Program(vs_src, fs_src));

	//Set uniforms for the program.
	height_program->use();
	
	glUniformMatrix4fv(height_program->getUniform("projection"), 1, 0, glm::value_ptr(projection_matrix));
	glUniformMatrix4fv(height_program->getUniform("view"), 1, 0, glm::value_ptr(view_matrix));
	glUniformMatrix4fv(height_program->getUniform("model"), 1, 0, glm::value_ptr(model_matrix));
	glUniform1i(height_program->getUniform("height_texture"), 0); //< 0 means GL_TEXTURE0
	glUniform1i(height_program->getUniform("color_texture"), 1); //< 1 means GL_TEXTURE1
	
	glUseProgram(0);
	CHECK_GL_ERROR();
}
Ejemplo n.º 4
0
void GameManager::render() {
	//First, make sure our framebuffer is empty 
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glPushMatrix();
		world.Render();
		ship->Render();
		spawnManager.Render();
		bulletpool.Render();
	glPopMatrix();
	checkGLErrors();
}
Ejemplo n.º 5
0
void GameManager::createFBOProgram()
{
	std::string vs_src = readFile("shaders/fbo.vert");
	std::string fs_src = readFile("shaders/fbo.frag");

	fbo_program.reset(new Program(vs_src, fs_src));
	fbo_program->use();

	glUniformMatrix4fv(fbo_program->getUniform("projection"), 1, 0, glm::value_ptr(fbo_projectionMatrix));
	glUniformMatrix4fv(fbo_program->getUniform("view"), 1, 0, glm::value_ptr(fbo_viewMatrix));
	glUniformMatrix4fv(fbo_program->getUniform("model_matrix"), 1, 0, glm::value_ptr(fbo_modelMatrix));
	glUniform1i(fbo_program->getUniform("fbo_texture"), 0);
	glUseProgram(0);
	CHECK_GL_ERROR();

	std::string vs_lsrc = readFile("shaders/lightPoV.vert");
	std::string fs_lsrc = readFile("shaders/lightPoV.frag");
	light_prog.reset(new Program(vs_lsrc, fs_lsrc));
	light_prog->use();
	glUniformMatrix4fv(light_prog->getUniform("projection"), 1, 0, glm::value_ptr(lightProjection));
	light_prog->disuse();
	CHECK_GL_ERROR();
}
Ejemplo n.º 6
0
void GameManager::init() {
	// Initialize SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
		std::stringstream err;
		err << "Could not initialize SDL: " << SDL_GetError();
		throw std::runtime_error(err.str());
	}
	atexit( SDL_Quit);

	createOpenGLContext();
	setOpenGLStates();

	//Finally check for errors
	checkGLErrors();

	world.Init();
}