Пример #1
0
void TP1::Draw(){
    // efface le color buffer
	glClearColor(0.0f, 0.0f, 0.0f, 1.f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	GLuint programObject = shader.GetProgram();
	glUseProgram(programObject);

    projectionMatrix = esgiOrtho(0.f, WINDOW_WIDTH, 0.f, WINDOW_HEIGHT, 0.f, 1.f);
	GLint projectionUniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
	glUniformMatrix4fv(projectionUniform, 1, 0, &projectionMatrix.I.x);	

	sprite.Render(programObject);
    
    glutSwapBuffers();
    glutPostRedisplay();
}
Пример #2
0
// Draw Method
void Draw()
{
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glClearColor(0.3f, 0.3f, 0.3f, 1.f);
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
	GLint projection_uniform;
	GLint world_uniform;
	mat4 projectionMatrix = esgiOrtho(0.f, 800.f, 600.f, 0.f, 0.f, 1.f);
	
	GLint position_attr;
	GLint texcoord_attr;

	GLint sampler_uniform;

	float angle = 0.f;

	mat4 worldMatrix;
	worldMatrix.Identity();

	worldMatrix = esgiRotateZ(angle);
	worldMatrix.I.x = 800.f / 1.6f;
	worldMatrix.J.y = 600.f /1.6f;

	/**
	 * Draw Sky - Start
	 */
	programObject = shaders.UseShader("Sky");

	position_attr = glGetAttribLocation(programObject, "a_Position");
	texcoord_attr = glGetAttribLocation(programObject, "a_TexCoords");

	projection_uniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
	world_uniform = glGetUniformLocation(programObject, "u_WorldMatrix");


	glVertexAttribPointer(position_attr, 3, GL_FLOAT, false, sizeof(Vertex), vertices);
	glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, false, sizeof(Vertex), &vertices[0].texcoords);

	glEnableVertexAttribArray(position_attr);
	glEnableVertexAttribArray(texcoord_attr);
	
	glUniformMatrix4fv(projection_uniform, 1, false, &projectionMatrix.I.x);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, textures["Sky"]);

	sampler_uniform = glGetUniformLocation(programObject, "u_Texture");
	glUniform1i(sampler_uniform, 0);

	worldMatrix.T.set(400.f, 300.f, 0.f, 1.0f);

	glUniformMatrix4fv(world_uniform, 1, false, &worldMatrix.I.x);

	glDrawArrays(GL_TRIANGLES, 0, VertexCount);

	glDisableVertexAttribArray(position_attr);
	glDisableVertexAttribArray(texcoord_attr);
	shaders.UnUseShader("sky");
	/**
	 * Draw Sky - End
	 */

	/**
	 * Draw Clouds - Start
	 */
	programObject = shaders.UseShader("Clouds");

	position_attr = glGetAttribLocation(programObject, "a_Position");
	texcoord_attr = glGetAttribLocation(programObject, "a_TexCoords");
		
	projection_uniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
	world_uniform = glGetUniformLocation(programObject, "u_WorldMatrix");
	GLint time_uniform = glGetUniformLocation(programObject, "u_Time");

	glVertexAttribPointer(position_attr, 3, GL_FLOAT, false, sizeof(Vertex), vertices);
	glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, false, sizeof(Vertex), &vertices[0].texcoords);
	
	glUniformMatrix4fv(projection_uniform, 1, false, &projectionMatrix.I.x);

	glEnableVertexAttribArray(position_attr);
	glEnableVertexAttribArray(texcoord_attr);

	glUniform1f(time_uniform, t);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, textures["Clouds"]);

	sampler_uniform = glGetUniformLocation(programObject, "u_Texture");
	glUniform1i(sampler_uniform, 0);

	worldMatrix.T.set(400.f, 300.f, 0.f, 1.0f);
	glUniformMatrix4fv(world_uniform, 1, false, &worldMatrix.I.x);
	glDrawArrays(GL_TRIANGLES, 0, VertexCount);

	glDisableVertexAttribArray(position_attr);
	glDisableVertexAttribArray(texcoord_attr);

	shaders.UnUseShader("Clouds");
	/**
	 * Draw Clouds - End
	 */

	/**
	 * Draw Particle - Start
	 */
	programObject = shaders.UseShader("Particle");

	position_attr = glGetAttribLocation(programObject, "a_Position");
	texcoord_attr = glGetAttribLocation(programObject, "a_TexCoords");

	projection_uniform = glGetUniformLocation(programObject, "u_ProjectionMatrix");
	world_uniform = glGetUniformLocation(programObject, "u_WorldMatrix");

	glVertexAttribPointer(position_attr, 3, GL_FLOAT, false, sizeof(Vertex), vertices);
	glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, false, sizeof(Vertex), &vertices[0].texcoords);

	GLint ttl_uniform = glGetUniformLocation(programObject, "u_ttl");
	GLint ttl_max_uniform = glGetUniformLocation(programObject, "u_ttl_max");

	GLint dir_uniform = glGetUniformLocation(programObject, "u_dir");
	
	glUniformMatrix4fv(projection_uniform, 1, false, &projectionMatrix.I.x);

	glEnableVertexAttribArray(position_attr);
	glEnableVertexAttribArray(texcoord_attr);

	for(int i = 0; i < ParticleEmiters.size(); i++)
	{
		for(int j = 0; j < ParticleEmiters[i].nbParticle; j++)
		{
			if(ParticleEmiters[i].particles[j].living == true && ParticleEmiters[i].particles[j].emited == true )
			{
				glUniform1f(ttl_uniform, ParticleEmiters[i].particles[j].ttlCurr);
				glUniform1f(ttl_max_uniform, ParticleEmiters[i].particles[j].ttlMax);
				glUniform3f(dir_uniform, ParticleEmiters[i].particles[j].direction.x, ParticleEmiters[i].particles[j].direction.y, ParticleEmiters[i].particles[j].direction.z);
				
				if(ParticleEmiters[i].particles[j].type == 1)
					drawParticle(ParticleEmiters[i].particles[j].position, programObject, sampler_uniform, worldMatrix, world_uniform, textures["Fireworks"]);
				if(ParticleEmiters[i].particles[j].type == 2)
					drawParticle(ParticleEmiters[i].particles[j].position, programObject, sampler_uniform, worldMatrix, world_uniform, textures["Water"]);
			}
		}
	}

	glDisableVertexAttribArray(position_attr);
	glDisableVertexAttribArray(texcoord_attr);

	shaders.UnUseShader("Particle");
	/**
	 * Draw Clouds - End
	 */
}