예제 #1
0
// Decides what will elements drawn after this call will look like
void Scene::setAppearance(const ObjectInstance &instance, int timer) {
    const size_t shaderId = instance.shaderId;

    glUseProgram(shaderId); // From now on, this shader will be used.

    // We use the specific values of model per object
    setMatricesInShader(shaderId, instance.transformation, camera.getView(), camera.getPosition(), camera.getProjection());
    glUniform4fv(glGetUniformLocation(shaderId, "color"), 1, instance.color);

    // Specifies which VBO were filled
    const Object * pObject = storedObjects[instance.objectId];
    assert(pObject);
    setFilledDataInShader(shaderId, pObject->hasPrimitives(), pObject->hasNormals(), pObject->hasUvs(), pObject->hasColors());

    // Sets the light in the current shader
    setLightInShader(shaderId, lightPosition, lightPower);
    setTimerInShader(shaderId, (GLfloat) timer);

    //TO DO : Bind Texture
    if(instance.textureId0 != 999){
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, instance.textureId0);
        if(instance.textureId1 != 999){
             glActiveTexture(GL_TEXTURE1);
            glBindTexture(GL_TEXTURE_2D, instance.textureId1);
        }
        setTextureUnitsInShader(shaderId);
    }
}
예제 #2
0
// Decides what will elements drawn after this call will look like
void Scene::setAppearance(GLuint indexDrawnObject)
{
    glUseProgram(this->drawnObjectsShaderIDs[indexDrawnObject]); // From now on, this shader will be used.

    // We use the specific values of model per object
    GLfloat * model=&(this->drawnObjectsModels[indexDrawnObject*16]);
    setMatricesInShader(this->drawnObjectsShaderIDs[indexDrawnObject], model, this->camera->view, this->camera->c, this->camera->projection);

    // We use the specific values of color per object
    GLfloat * color=&(this->drawnObjectsColors[indexDrawnObject*4]);
    //changeMaterialColorInShader(this->drawnObjectsShaderIDs[indexDrawnObject], color);
    //glUniform4fv(glGetUniformLocation(this->drawnObjectsShaderIDs[indexDrawnObject], "color"), 1, color);
    changeMaterialColorInShader(this->drawnObjectsShaderIDs[indexDrawnObject], color); //Question 4a)
    // Specifies which VBO were filled
    Object * object=this->storedObjects[this->drawnObjects[indexDrawnObject]];
    setFilledDataInShader(this->drawnObjectsShaderIDs[indexDrawnObject], object->primitives, object->normals, object->uvs, object->colors);
    
    // Sets the light in the current shader
    setLightInShader(this->drawnObjectsShaderIDs[indexDrawnObject], this->lightPosition, this->lightPower);

    // in Scene::setAppearance(GLuint indexDrawnObject)  
    // Selects our current texture for unit 0
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, this->drawnObjectsTexture0IDs[indexDrawnObject]);
    
    // Selects our current texture for unit 1
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, this->drawnObjectsTexture1IDs[indexDrawnObject]);

}