Exemplo n.º 1
0
//renders a single `ModelInstance`
static void RenderInstance(const ModelInstance& inst) {
    ModelAsset* asset = inst.asset;
    tdogl::Program* shaders = asset->shaders;

    //bind the shaders
    shaders->use();

    //set the shader uniforms
    shaders->setUniform("camera", gCamera.matrix());
    shaders->setUniform("model", inst.transform);
    shaders->setUniform("material.tex", 0); //set to 0 because the texture will be bound to GL_TEXTURE0
    shaders->setUniform("material.shininess", asset->shininess);
    shaders->setUniform("material.specularColor", asset->specularColor);
    shaders->setUniform("light.position", gLight.position);
    shaders->setUniform("light.intensities", gLight.intensities);
    shaders->setUniform("light.attenuation", gLight.attenuation);
    shaders->setUniform("light.ambientCoefficient", gLight.ambientCoefficient);
    shaders->setUniform("cameraPosition", gCamera.position());

    //bind the texture
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, asset->texture->object());

    //bind VAO and draw
    glBindVertexArray(asset->vao);
    glDrawArrays(asset->drawType, asset->drawStart, asset->drawCount);

    //unbind everything
    glBindVertexArray(0);
    glBindTexture(GL_TEXTURE_2D, 0);
    shaders->stopUsing();
}
Exemplo n.º 2
0
static void Render() {
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0, 0.1, 0.1, 1.0); //set the background
    
    glUseProgram(gProgram->object());
    
    gProgram -> setUniform("camera", gCamera.matrix());
    gProgram -> setUniform("model", glm::rotate(glm::mat4(), gDegreesRotated, Axis));
    gProgram -> setUniform("light.position", gLight.position);
    gProgram -> setUniform("light.intensities",gLight.intensities);
    gProgram -> setUniform("materialSpecularColor", specularColor);
    gProgram -> setUniform("materialShininess", material_shininess);
    gProgram -> setUniform("light.attenuation", gLight.attenuation);
    gProgram -> setUniform("light.ambientCoefficient", gLight.ambientCoefficient);
    gProgram -> setUniform("cameraPosition", gCamera.position());
    
    glBindVertexArray(gVAO);
    glDrawArrays(GL_TRIANGLES, 0, NumVertices);
    
    glBindVertexArray(0);
    //glFlush();
    
    gProgram -> stopUsing();
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH);
    glfwSwapBuffers();
}
Exemplo n.º 3
0
// draws a single frame
static void Render() {
    // clear everything
    glClearColor(0, 0, 0, 1); // black
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // bind the program (the shaders)
    gProgram->use();

    // set the "camera" uniform
    gProgram->setUniform("camera", gCamera.matrix());

    // set the "model" uniform in the vertex shader, based on the gDegreesRotated global
    gProgram->setUniform("model", glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0,1,0)));
        
    // bind the texture and set the "tex" uniform in the fragment shader
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, gTexture->object());
    gProgram->setUniform("tex", 0); //set to 0 because the texture is bound to GL_TEXTURE0

    // bind the VAO (the triangle)
    glBindVertexArray(gVAO);
    
    // draw the VAO
    glDrawArrays(GL_TRIANGLES, 0, 6*2*3);
    
    // unbind the VAO, the program and the texture
    glBindVertexArray(0);
    glBindTexture(GL_TEXTURE_2D, 0);
    gProgram->stopUsing();
    
    // swap the display buffers (displays what was just drawn)
    glfwSwapBuffers();
}
Exemplo n.º 4
0
static void RenderInstance(const ModelInstance& inst) {
    ModelAsset* asset = inst.asset;
    tdogl::Program* shaders = asset->shaders;

    // bind the shaders
    shaders->use();

    // set the shader uniforms
    shaders->setUniform("camera", gCamera.matrix());
    shaders->setUniform("model", inst.transform);
    shaders->setUniform("tex", 0);

    // bind the texture
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, asset->texture->object());

    // bind VAO and draw
    glBindVertexArray(asset->vao);
    glDrawArrays(asset->drawType, asset->drawStart, asset->drawCount);

    // unbind everything
    glBindVertexArray(0);
    glBindTexture(GL_TEXTURE_2D, 0);
    shaders->stopUsing();
}
Exemplo n.º 5
0
// draws a single frame
static void Render() {
    // clear everything
    glClearColor(0, 0, 0, 1); // black
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // render all the instances
    std::list<ModelInstance>::const_iterator it;
    for(it = gInstances.begin(); it != gInstances.end(); ++it){
        RenderInstance(*it, gCamera.matrix());
    }
    
    // swap the display buffers (displays what was just drawn)
    glfwSwapBuffers();
}
Exemplo n.º 6
0
void Render(GLFWwindow* window)
{
	// clear everything
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLint uniformCamera = glGetUniformLocation(gProgram, "camera");
	if (uniformCamera == -1)
		throw std::runtime_error(std::string("Program uniform not found: ") + "camera");

	glUniformMatrix4fv(uniformCamera, 1, GL_FALSE, glm::value_ptr(gCamera.matrix()));


	GLint uniformModel = glGetUniformLocation(gProgram, "model");
	if (uniformModel == -1)
		throw std::runtime_error(std::string("Program uniform not found: ") + "tex");

	glm::tmat4x4<float, glm::highp> modelMatrix = glm::rotate(glm::mat4(), glm::radians(gDegreesRotated), glm::vec3(0, 1, 0));
	glUniformMatrix4fv(uniformModel, 1, GL_FALSE, glm::value_ptr(modelMatrix));


	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, gTex);

	GLint uniformTex = glGetUniformLocation(gProgram, "tex");
	if (uniformTex == -1)
		throw std::runtime_error(std::string("Program uniform not found: ") + "tex");

	glUniform1i(uniformTex, 0);



	glBindVertexArray(gVAO);

	// draw the VAO
	glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

	glBindVertexArray(0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glfwSwapBuffers(window);
}