Esempio n. 1
0
void mainLoop()
{
    while (!glfwWindowShouldClose(window) && !glfwGetKey(window, GLFW_KEY_ESCAPE))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        program.use();

        program.setUniform("Material.Kd", 0.2f, 0.8f, 0.3f);
        program.setUniform("Material.Ka", 0.2f, 0.6f, 0.3f);
        program.setUniform("Material.Ks", 0.2f, 0.2f, 0.8f);
        program.setUniform("Material.Shininess", 100.0f);

        glm::mat4 mv = view * model;
        program.setUniform("ModelViewMatrix", mv);
        program.setUniform("NormalMatrix",
                           glm::mat3(glm::vec3(mv[0]), glm::vec3(mv[1]), glm::vec3(mv[2])));

        glm::mat4 mvp = projection * mv;
        program.setUniform("MVP", mvp);

        cube->render();

        glfwPollEvents();
        glfwSwapBuffers(window);
    }
}
Esempio n. 2
0
void init()
{
    glfwWindowHint(GLFW_SAMPLES, 15);
    glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);
    glClearColor(0.1f, 0.2f, 0.3f, 1.0f);

    cube = new Cube(false, 1);

    GLShader vert(GLShader::GLShaderType::VERTEX);
    vert.readShader("fog.vert");
    vert.compileShader();
    GLShader frag(GLShader::GLShaderType::FRAGMENT);
    frag.readShader("fog.frag");
    frag.compileShader();

    program.setShaders({ vert.getId(), frag.getId() });
    program.link();

    model = glm::mat4(1.0f);

    view = glm::lookAt(eye, target, up);

    projection = glm::perspective(45.0f, (float)WIN_WIDTH / WIN_HEIGHT, 0.1f, 100.0f);

    program.use();
    /*program.setUniform("Light[0].Position", view * worldLight);
    program.setUniform("Light[0].Intensity", 0.8f, 0.5f, 0.5f);
    worldLight = glm::vec4(7.0f, 5.0f, 5.0f, 1.0f);
    program.setUniform("Light[1].Position", view * worldLight);
    program.setUniform("Light[1].Intensity", -0.8f, 0.5f, 0.5f);
    */

    program.setUniform("sli.Position", eye);
    program.setUniform("sli.intensity", 0.8f, 0.5f, 0.5f);
    program.setUniform("sli.direction", target);
    program.setUniform("sli.exponent", 3);
    program.setUniform("sli.cutoff", 0.1f);

}
Esempio n. 3
0
 void State::setUniform(GLProgram& prog, const QString& name, const glm::mat4& m)
 {
   /// @todo should work with mat4 and mat3
   prog.setUniform(this, name, m);
 }