void SimpleRender::Render(ICamera* camera, const Vector4f& lightPosition) {

    ShaderProgram* shader = isAo ? m_aoShader : m_simpleShader;

    // bind shader of the batch.
    shader->Bind();

    m_vertexBuffer->EnableVertexAttribInterleavedWithBind();

    shader->SetUniform("textureArray", 0);
    Texture::SetActiveTextureUnit(0);
    m_arrayTexture->Bind();

    shader->SetUniform("aoOnly", 1.0f);

    Matrix4f modelMatrix = Matrix4f::CreateIdentity(); //geoObj->GetModelMatrix();

    shader->SetPhongUniforms(
	modelMatrix
	, camera, lightPosition);

    for(size_t i = 0; i < m_chunks.size(); ++i) {

	Chunk* chunk = m_chunks[i];

	chunk->m_indexBuffer->Bind();
	chunk->m_indexBuffer->DrawIndices(GL_TRIANGLES, (chunk->m_numTriangles)*3);
	chunk->m_indexBuffer->Unbind();
    }

    m_vertexBuffer->DisableVertexAttribInterleavedWithBind();

    m_arrayTexture->Unbind();

}
Пример #2
0
void MeshRenderer::PreRender(const ShaderProgram& shader, const Material& material, const glm::mat4& parent) {
    shader.SetUniform("model"       , parent * owner->matrix);
    shader.SetUniform("diffuseColor", material.diffuseColor); 
    shader.SetUniform("hasTexture"  , material.hasTexture);
    
    if (material.hasTexture)
       material.texture->Bind(GL_TEXTURE0);
}
Пример #3
0
void Font::Flush(float deltaTime)
{
	//flush all of the vertices to the GPU for drawing
	if (!preRenderStage)
	{
		timer += deltaTime;
		if (timer > 1.f / 60.f) //60fps text updating
		{
			timer = 0;
			preRenderStage = true;

			//clear out the memory to start rendering new ones
			vertices = new vector<Vertex>();
			indices = new vector<int>();
		}
	}
	else
	{
		m->SetVertices(vertices, GL_STREAM_DRAW, true);
		m->SetIndices(indices, GL_STREAM_DRAW, true);
		m->FlushBuffers();
		preRenderStage = false;
	}

	glEnable(GL_BLEND);
	renderer->Ready();
	ShaderProgram *prog = renderer->GetProgram();
	prog->SetUniform("MVP", (void*)value_ptr(guiCam->Get()));
	renderer->Render();
	glDisable(GL_BLEND);
}
Пример #4
0
void Planet::Draw(ShaderProgram &shaderProgram, Camera *camera, Texture moonTexture)
{
    // modelMatrix has to be set
    // moonModelMatrices have to be set
    shaderProgram.UseProgram();
    shaderProgram.SetUniform("mvpMatrix", camera->GetMVP(modelMatrix));
    modelData->Draw();

    for(GLint i = 0; i < moonModelMatrices.size(); i++)
    {
        moonTexture.Bind(0);
        shaderProgram.SetUniform("mvpMatrix", camera->GetMVP(moonModelMatrices[i]));
        modelData->Draw();
    }

    shaderProgram.DisUseProgram();
}
Пример #5
0
void GameObject::Render(Camera *camera)
{
	if (!renderer)
		return;

	renderer->Ready();
	ShaderProgram *program = renderer->GetProgram();
	program->SetUniform("Model", value_ptr(modelMatrix));
	mat4 VP = camera->Get();
	program->SetUniform("VP", value_ptr(VP));
	mat4 MVP = VP * GetModelMatrix();
	program->SetUniform("MVP", value_ptr(MVP));

	vec3 camPos = camera->GetPos(); 
	program->SetUniform("cameraPosition", &camPos);

	vec3 lightDir = normalize(camPos - pos);
	program->SetUniform("lightDirection", &lightDir);

	vec4 ambMatColor(1, 0, 0, 1);
	program->SetUniform("ambientMaterialColor", &ambMatColor);

	vec4 difMatColor(1, 0, 0, 1); 
	program->SetUniform("diffuseMaterialColor", &difMatColor);

	vec4 specMatColor(1, 1, 1, 1);
	program->SetUniform("specularMaterialColor", &specMatColor);

	float power = 25;
	program->SetUniform("specularPower", &power);

	vec4 ambLightColor(1, 0, 0, 1);
	program->SetUniform("ambientLightColor", &ambLightColor);

	vec4 difLightColor(1, 0, 0, 1);
	program->SetUniform("diffuseLightColor", &difLightColor);

	vec4 specLightColor(1, 1, 1, 1); 
	program->SetUniform("specularLightColor", &specLightColor);

	float heightScale = 5.0f;
	program->SetUniform("heightScale", &heightScale);

	for (auto it = components.begin(); it != components.end(); it++)
		(*(it->second)).OnRender(camera);

	renderer->Render(); 
}