Beispiel #1
0
OGL::Program* Graphics::LoadShaders( const std::string& vertFilename, const std::string& fragFilename )
{
	std::vector<OGL::Shader> shaders;
	shaders.push_back(OGL::Shader::shaderFromFile(ResourcePath(vertFilename), GL_VERTEX_SHADER));
	shaders.push_back(OGL::Shader::shaderFromFile(ResourcePath(fragFilename), GL_FRAGMENT_SHADER));
	return new OGL::Program(shaders);
}
Beispiel #2
0
static void LoadShaders() {
    std:: vector<tdogl::Shader> shaders;
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath("vertex.glsl"), GL_VERTEX_SHADER));
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath("fragment.glsl"), GL_FRAGMENT_SHADER));
    gProgram = new tdogl::Program(shaders);
    
}
Beispiel #3
0
// loads the vertex shader and fragment shader, and links them to make the global gProgram
static void LoadShaders() {
    std::vector<tdogl::Shader> shaders;
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath("vertex-shader.txt"), GL_VERTEX_SHADER));
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath("fragment-shader.txt"), GL_FRAGMENT_SHADER));
    gProgram = new tdogl::Program(shaders);

    gProgram->use();

    //set the "projection" uniform in the vertex shader, because it's not going to change
    glm::mat4 projection = glm::perspective(glm::radians(50.0f), SCREEN_SIZE.x/SCREEN_SIZE.y, 0.1f, 10.0f);
    gProgram->setUniform("projection", projection);

    //set the "camera" uniform in the vertex shader, because it's also not going to change
    glm::mat4 camera = glm::lookAt(glm::vec3(3,3,3), glm::vec3(0,0,0), glm::vec3(0,1,0));
    gProgram->setUniform("camera", camera);

    gProgram->stopUsing();
}
Beispiel #4
0
void rpInitRecording(Replay* R, const char* File, const char LevelFile[255])
{
	R->f = fopen(File, "wb");
	char file[255] ;
	sprintf(file,(ResourcePath()+"levels/%s").c_str(),LevelFile);
	if (R->f == NULL)
		printf("Error creating replay file %s\n", File);
	else
		fwrite(file, sizeof(char), 255, R->f);
}
Beispiel #5
0
int main(int argc, char** argv)
{
	if (!DirectoryExists((ResourcePath()+"replays").c_str()))
		CreateDirectory((ResourcePath()+"replays").c_str());
	
	sf::Context C;
	C.setActive(1);
	SharedResources SR;
	shInit(&SR, &glTexLoad, &glTexFree);
	shLoadAudio(&SR);
	shLoadTextures(&SR);
	shLoadFonts(&SR);

	Game G;

	gmInit(&G, &SR);
	gmLoadLvl(&G, (ResourcePath()+"levels/MainMenu.lvl").c_str());
	gmPlay(&G);
	gmFree(&G);

	shFree(&SR);

	return EXIT_SUCCESS;
}
Beispiel #6
0
// returns a new tdogl::Texture created from the given filename
static tdogl::Texture* LoadTexture(const char* filename) {
    tdogl::Bitmap bmp = tdogl::Bitmap::bitmapFromFile(ResourcePath(filename));
    bmp.flipVertically();
    return new tdogl::Texture(bmp);
}
Beispiel #7
0
// returns a new tdogl::Program created from the given vertex and fragment shader filenames
static tdogl::Program* LoadShaders(const char* vertFilename, const char* fragFilename) {
    std::vector<tdogl::Shader> shaders;
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath(vertFilename), GL_VERTEX_SHADER));
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath(fragFilename), GL_FRAGMENT_SHADER));
    return new tdogl::Program(shaders);
}
Beispiel #8
0
void plInit(Player* P, World *W)
{
	P->ULPos = vec2(-20.f, -70.f);
	P->URPos = vec2(20.f, -70.f);
	P->DLPos = vec2(-35.f, 70.f);
	P->DRPos = vec2(35.f, 70.f);

	strcpy(P->SndFoot[0], "snd_step1");
	strcpy(P->SndFoot[1], "snd_step2");

	P->timer.restart();

	P->VxUL = newVertex();
	vxSetPosition(P->VxUL, P->ULPos);
	P->VxUR = newVertex();
	vxSetPosition(P->VxUR, P->URPos);
	P->VxDR = newVertex();
	vxSetPosition(P->VxDR, P->DRPos);
	P->VxDL = newVertex();
	vxSetPosition(P->VxDL, P->DLPos);

	vxSetMass(P->VxUL, 0.01f);
	vxSetMass(P->VxUR, 0.01f);
	vxSetMass(P->VxDL, 1.5f);
	vxSetMass(P->VxDR, 1.5f);

	P->Shape = polyRectangle(P->VxUL, P->VxUR, P->VxDR, P->VxDL);
	wdAddVxFromPoly(W, P->Shape);

	P->GroundAngle = M_PI_2;

	P->Dir = DIR_RIGHT;

	animAnglesStatesInit(&P->Angles);
	animPositionsStatesInit(&P->Positions);

	P->aniRun = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniRun, (ResourcePath()+"data/anims/animRun.ani").c_str());
	//aniSetForce(P->aniRun, 0.65f);

	P->aniJump = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniJump, (ResourcePath()+"data/anims/animJump.ani").c_str());
	aniSetForce(P->aniJump, 0.65f);

	P->aniFall = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniFall, (ResourcePath()+"data/anims/animFall.ani").c_str());

	P->aniHello = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniHello, (ResourcePath()+"data/anims/animHello.ani").c_str());

	P->aniStand = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniStand, (ResourcePath()+"data/anims/animStand.ani").c_str());

	unsigned int i=0;
	for (i=0; i<polyGetVxCount(P->Shape); i++)
		vxSetFixed(polyGetVertex(P->Shape, i), FALSE);

	P->GrabR = NULL;
	P->GrabL = NULL;
	P->VxULStatus = P->VxURStatus = P->VxDRStatus = P->VxDLStatus =
		P->RdUStatus = P->RdRStatus = P->RdDStatus = P->RdLStatus = nullCollisionInfo();
	P->State = PL_NOSTATE;
	plResetJump(P);

	/* On crée les vertices du personnage, pour l'animation et quand il meurt */
	for (int i=0; i<12; i++)
		P->vxBodyParts[i] = newVertex();

	vxSetPosition(P->vxBodyParts[bpBase], vec2(0.f, 100.f));
	Vec2 B = vxGetPosition(P->vxBodyParts[bpBase]);
	vxSetPosition(P->vxBodyParts[bpNeck], vec2(B.x, B.y - 60.f));
	 vxSetPosition(P->vxBodyParts[bpHeadLeft], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(-20.f, -20.f)));
	 vxSetPosition(P->vxBodyParts[bpHeadRight], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(20.f, -20.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f)));
	 vxSetPosition(P->vxBodyParts[bpRightArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f)));
	 vxSetPosition(P->vxBodyParts[bpRightArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f)));
	vxSetPosition(P->vxBodyParts[bpLeftLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f)));
	vxSetPosition(P->vxBodyParts[bpRightLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f)));
	vxSetPosition(P->vxBodyParts[bpRightLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f)));

	for (int i=0; i<12; i++)
	{
		switch (i) {
			case bpNeck:
			case bpLeftLeg1:
			case bpRightLeg1:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpBase], -1.f);
				break;
			case bpLeftArm1:
			case bpRightArm1:
			case bpHeadLeft:
			case bpHeadRight:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpNeck], -1.f);
				break;
			case bpLeftArm2:
			case bpRightArm2:
			case bpLeftLeg2:
			case bpRightLeg2:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[i-1], -1.f);
				break;
			case bpBase:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[bpHeadLeft], P->vxBodyParts[bpHeadRight], -1.f);
				break;
			default:
				break;
		}
	}

	P->CurrentAnim = P->aniStand;
	aniUpdateForCurrentState(P->CurrentAnim, P);
	aniUpdate(P->CurrentAnim, P, 1.f);

}
Beispiel #9
0
OGL::Texture* Graphics::LoadTexture( const std::string& fileName )
{
	OGL::Bitmap bmp = OGL::Bitmap::bitmapFromFile(ResourcePath(fileName));
	bmp.flipVertically();
	return new OGL::Texture(bmp);
}
Beispiel #10
0
void AppMain() {
	//Init everything in the game.
		fps = new FPS(glfwGetTime());

		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);

		std::vector<Shader> shaders;
		shaders.push_back(Shader::shaderFromFile(ResourcePath("vertex-shader.txt"), GL_VERTEX_SHADER));
		shaders.push_back(Shader::shaderFromFile(ResourcePath("fragment-shader.txt"), GL_FRAGMENT_SHADER));
		_program = new Program(shaders);

		World* world = new World();
		world->generateWorld(_program);

		gLight.position = world->_player->_camera->position();
		gLight.intensities = glm::vec3(1, 1, 1);
		gLight.attenuation = 0.00f; /* 0.01f; */
		gLight.ambientCoefficient = 0.01f;

	//Run the game.
    while(glfwGetWindowParam(GLFW_OPENED)) {
		//update
		fps->_thisTime = glfwGetTime(); {
			world->update(fps->_thisTime - fps->_lastTime);
			
			gLight.position = world->_player->_camera->position();
			if(glfwGetKey('1'))
				gLight.intensities = glm::vec3(0,0,1); //blue
			if(glfwGetKey('2'))
				gLight.intensities = glm::vec3(1,0,0); //red
			else if(glfwGetKey('3'))
				gLight.intensities = glm::vec3(0,1,0); //green
			else if(glfwGetKey('4'))
				gLight.intensities = glm::vec3(1,1,1); //white
		} fps->_lastTime = fps->_thisTime;
		
		//render
        _program->use(); {
			glClearColor(0.2, 0.2, 0.2, 1);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
			_program->setUniform("camera", world->_player->_camera->matrix());
			_program->setUniform("light.position", gLight.position);
			_program->setUniform("light.intensities", gLight.intensities);
			_program->setUniform("light.attenuation", gLight.attenuation);
			_program->setUniform("light.ambientCoefficient", gLight.ambientCoefficient);
		
			world->render();
		} _program->stopUsing();

		fps->update(glfwGetTime());

		if(glfwGetKey(GLFW_KEY_ESC) || (fps->_fps < 5.0 && fps->_counter > 5)) {
            glfwCloseWindow();
		}

		//Display.
		glfwSwapBuffers();
    }

	//It's time to close, KILL EVERYTHING!!! MUHAHAHA!!!
	delete world;
	delete _program;
	delete fps;

    glfwTerminate();
}
Beispiel #11
0
// loads the file "wooden-crate.jpg" into gTexture
static tdogl::Texture* LoadTexture(std::string texture_file) {
    tdogl::Bitmap bmp = tdogl::Bitmap::bitmapFromFile(ResourcePath("wooden-crate.jpg"));
    bmp.flipVertically();
    return new tdogl::Texture(bmp);
}
Beispiel #12
0
// loads the vertex shader and fragment shader, and links them to make the global gProgram
static tdogl::Program* LoadShaders(std::string vertex_shader, std::string fragment_shader) {
    std::vector<tdogl::Shader> shaders;
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath(vertex_shader), GL_VERTEX_SHADER));
    shaders.push_back(tdogl::Shader::shaderFromFile(ResourcePath(fragment_shader), GL_FRAGMENT_SHADER));
    return new tdogl::Program(shaders);
}
SplashScreen::SplashScreen() : myTxBack(), mySprBack()
{
    //Load the textures needed
    myTxBack.LoadFromFile(ResourcePath()+"img/SplashScreen.png");
    mySprBack.SetTexture(myTxBack);
}
Beispiel #14
0
void IRenderable::LoadTexture( const std::string& fileName )
{
    OGL::Bitmap bmp = OGL::Bitmap::bitmapFromFile(ResourcePath(fileName));
    bmp.flipVertically();
    m_asset->texture = new OGL::Texture(bmp);
}
Beispiel #15
0
// loads the file "hazard.png" into gTexture
static void LoadTexture() {
    tdogl::Bitmap bmp = tdogl::Bitmap::bitmapFromFile(ResourcePath("hazard.png"));
    bmp.flipVertically();
    gTexture = new tdogl::Texture(bmp);
}
Beispiel #16
0
// loads the file "wooden-crate.jpg" into gTexture
static void LoadTexture() {
    tdogl::Bitmap bmp = tdogl::Bitmap::bitmapFromFile(ResourcePath("wooden-crate.jpg"));
    bmp.flipVertically();
    gTexture = new tdogl::Texture(bmp);
}
int main( int argc, char* argv[] )
{
	GLboolean running;

	// Initialise SDL2
	if( 0 != SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) )
	{
		fprintf( stderr, "Failed to initialize SDL2: %s\n", SDL_GetError() );
		exit( EXIT_FAILURE );
	}

	// Open OpenGL window
	SDL_Window * window = SDL_CreateWindow( "SOIL2 Test",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );

	if( NULL == window )
	{
		fprintf( stderr, "Failed to open SDL2 window: %s\n", SDL_GetError() );
		exit( EXIT_FAILURE );
	}

	SDL_GLContext context = SDL_GL_CreateContext( window );

	if ( NULL == context )
	{
		fprintf( stderr, "Failed to create SDL2 OpenGL Context: %s\n", SDL_GetError() );

		SDL_DestroyWindow( window );

		exit( EXIT_FAILURE );
	}

	SDL_GL_SetSwapInterval( 1 );

	SDL_GL_MakeCurrent( window, context );

	//	log what the use is asking us to load
	std::string load_me;

	if ( argc >= 2 )
	{
		load_me = std::string( argv[1] );
	}
	else
	{
		load_me = ResourcePath( "img_test.png" );
	}

	std::cout << "'" << load_me << "'" << std::endl;

	//	1st try to load it as a single-image-cubemap
	//	(note, need DDS ordered faces: "EWUDNS")
	GLuint tex_ID;
	Uint64 time_me;

	std::cout << "Attempting to load as a cubemap" << std::endl;
	time_me = SDL_GetPerformanceCounter();

	tex_ID = SOIL_load_OGL_single_cubemap(
			load_me.c_str(),
			SOIL_DDS_CUBEMAP_FACE_ORDER,
			SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_POWER_OF_TWO
			| SOIL_FLAG_MIPMAPS
			| SOIL_FLAG_DDS_LOAD_DIRECT
			| SOIL_FLAG_PVR_LOAD_DIRECT
			| SOIL_FLAG_ETC1_LOAD_DIRECT
			);

	std::cout << "the load time was " << get_total_ms(time_me) << " milliseconds" << std::endl;

	if( tex_ID > 0 )
	{
		glEnable( GL_TEXTURE_CUBE_MAP );
		glEnable( GL_TEXTURE_GEN_S );
		glEnable( GL_TEXTURE_GEN_T );
		glEnable( GL_TEXTURE_GEN_R );
		glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glBindTexture( GL_TEXTURE_CUBE_MAP, tex_ID );
		
		std::cout << "the loaded single cube map ID was " << tex_ID << std::endl;
	}
	else
	{
		std::cout << "Attempting to load as a HDR texture" << std::endl;
		time_me = SDL_GetPerformanceCounter();
		
		tex_ID = SOIL_load_OGL_HDR_texture(
				load_me.c_str(),
				SOIL_HDR_RGBdivA2,
				0,
				SOIL_CREATE_NEW_ID,
				SOIL_FLAG_POWER_OF_TWO
				| SOIL_FLAG_MIPMAPS
				| SOIL_FLAG_GL_MIPMAPS
				);

		std::cout << "the load time was " << get_total_ms(time_me) << " milliseconds" << std::endl;
		
		//	did I fail?
		if( tex_ID < 1 )
		{
			//	loading of the single-image-cubemap failed, try it as a simple texture
			std::cout << "Attempting to load as a simple 2D texture" << std::endl;
			
			//	load the texture, if specified
			time_me = SDL_GetPerformanceCounter();
			
			tex_ID = SOIL_load_OGL_texture(
					load_me.c_str(),
					SOIL_LOAD_AUTO,
					SOIL_CREATE_NEW_ID,
					  SOIL_FLAG_POWER_OF_TWO
					| SOIL_FLAG_MIPMAPS
					| SOIL_FLAG_GL_MIPMAPS
					| SOIL_FLAG_DDS_LOAD_DIRECT
					| SOIL_FLAG_PVR_LOAD_DIRECT
					| SOIL_FLAG_ETC1_LOAD_DIRECT
					| SOIL_FLAG_COMPRESS_TO_DXT
					);

			std::cout << "the load time was " << get_total_ms(time_me) << " milliseconds" << std::endl;
		}

		if( tex_ID > 0 )
		{
			//	enable texturing
			glEnable( GL_TEXTURE_2D );
			
			//  bind an OpenGL texture ID
			glBindTexture( GL_TEXTURE_2D, tex_ID );
			
			//	report
			std::cout << "the loaded texture ID was " << tex_ID << std::endl;
		}
		else
		{
			//	loading of the texture failed...why?
			glDisable( GL_TEXTURE_2D );
			
			std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl;
		}
	}

	running = GL_TRUE;

	const float ref_mag = 0.1f;
	float theta = 0.0f;
	float tex_u_max = 1.0f;
	float tex_v_max = 1.0f;
	Uint64 counterOld = SDL_GetPerformanceCounter();

	while( running )
	{
		float dt = (float)((double)(SDL_GetPerformanceCounter() - counterOld) / (double)SDL_GetPerformanceFrequency());
		counterOld = SDL_GetPerformanceCounter();

		SDL_Event evt;

		while (SDL_PollEvent(&evt))
		{
			switch (evt.type)
			{
				case SDL_QUIT:
				{
					running = false;
					break;
				}
				case SDL_KEYUP:
				{
					if ( SDLK_ESCAPE == evt.key.keysym.sym )
					{
						running = false;
					}
					break;
				}
			}
		}

		theta += dt * 40;

		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT);
		
		// Draw our textured geometry (just a rectangle in this instance)
		glPushMatrix();
		glScalef( 0.8f, 0.8f, 0.8f );
		glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
		glNormal3f( 0.0f, 0.0f, 1.0f );
		glBegin(GL_QUADS);
			glNormal3f( -ref_mag, -ref_mag, 1.0f );
			glTexCoord2f( 0.0f, tex_v_max );
			glVertex3f( -1.0f, -1.0f, -0.1f );

			glNormal3f( ref_mag, -ref_mag, 1.0f );
			glTexCoord2f( tex_u_max, tex_v_max );
			glVertex3f( 1.0f, -1.0f, -0.1f );

			glNormal3f( ref_mag, ref_mag, 1.0f );
			glTexCoord2f( tex_u_max, 0.0f );
			glVertex3f( 1.0f, 1.0f, -0.1f );

			glNormal3f( -ref_mag, ref_mag, 1.0f );
			glTexCoord2f( 0.0f, 0.0f );
			glVertex3f( -1.0f, 1.0f, -0.1f );
		glEnd();
		glPopMatrix();

		glPushMatrix();
		glScalef( 0.8f, 0.8f, 0.8f );
		glRotatef(theta, 0.0f, 0.0f, 1.0f);
		glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
		glNormal3f( 0.0f, 0.0f, 1.0f );
		glBegin(GL_QUADS);
			glTexCoord2f( 0.0f, tex_v_max );		glVertex3f( 0.0f, 0.0f, 0.1f );
			glTexCoord2f( tex_u_max, tex_v_max );	glVertex3f( 1.0f, 0.0f, 0.1f );
			glTexCoord2f( tex_u_max, 0.0f );		glVertex3f( 1.0f, 1.0f, 0.1f );
			glTexCoord2f( 0.0f, 0.0f );				glVertex3f( 0.0f, 1.0f, 0.1f );
		glEnd();
		glPopMatrix();

		// Swap buffers
		SDL_GL_SwapWindow( window );
	}

	// Close OpenGL window and terminate SDL2
	SDL_GL_DeleteContext( context );

	SDL_DestroyWindow( window );

	exit( EXIT_SUCCESS );
}