Bienvenue, Invité. Merci de vous connecter ou de vous inscrire.
Avez-vous perdu votre e-mail d'activation ?

Auteur Sujet: [SFML 2.0 / OpenGL 3.1] Erreur lors d'un dessin d'un objet avec texture  (Lu 1723 fois)

0 Membres et 1 Invité sur ce sujet

lanquemar

  • Newbie
  • *
  • Messages: 21
    • Voir le profil
    • E-mail
Bonsoir !
Je m'excuse pour le dérangement, mais j'essaye désespérément d'afficher un simple cube texturé en OpenGL, je crois avoir tout mis dans l'ordre et agencé correctement, pourtant quand j’exécute le programme (pas d'erreur de compilation), j'ai dans la console :
An internal OpenGL call failed in RenderTarget.cpp (225) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state

Alors je vous donne un concentré du code :
// <-- INITIALISATION DES SHADERS -->

// Attribus des Shaders :
        const char* attribute_name;
    attribute_name = "in_Vertex";
    attribute_coord3d = glGetAttribLocation(m_shader.getProgramID(), attribute_name);
    if (attribute_coord3d == -1) {
        printf("Could not bind attribute %s\n", attribute_name);
        return;
    }

    attribute_name = "in_TexCoord";
    attribute_v_texture = glGetAttribLocation(m_shader.getProgramID(), attribute_name);
    if (attribute_v_texture == -1) {
        printf("Could not bind attribute %s\n", attribute_name);
        return;
    }

    const char* uniform_name;
    uniform_name = "mvp";
    uniform_mvp = glGetUniformLocation(m_shader.getProgramID(), uniform_name);
    if (uniform_mvp == -1) {
        printf("Could not bind uniform %s\n", uniform_name);
        return;
    }

    uniform_name = "Texture";
    uniform_mytexture = glGetUniformLocation(m_shader.getProgramID(), uniform_name);
    if (uniform_mytexture == -1) {
        fprintf(stderr, "Could not bind uniform %s\n", uniform_name);
        return;
    }
       
// Envoie des informations aux Shaders :

        glGenBuffers(1, &vbo_vertices);
    glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices);
    glBufferData(GL_ARRAY_BUFFER, sizeof(data_vertex), data_vertex, GL_STATIC_DRAW);
       
        glGenBuffers(1, &ibo_elements);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data_indices), data_indices, GL_STATIC_DRAW);
       
        glGenBuffers(1, &vbo_cube_texcoords);
        glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_texcoords);
        glBufferData(GL_ARRAY_BUFFER, sizeof(cube_texcoords), cube_texcoords, GL_STATIC_DRAW);
       
// Chargement de la Texture (image) :

        unsigned char* img = SOIL_load_image("grassTop.png", &TEX_WIDTH, &TEX_HEIGHT, NULL, 0);
        glGenTextures(1, &texture_id);
    glBindTexture(GL_TEXTURE_2D, texture_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, // target
               0,  // level, 0 = base, no minimap,
               GL_RGB, // internalformat
               TEX_WIDTH,  // width
               TEX_HEIGHT,  // height
               0,  // border, always 0 in OpenGL ES
               GL_RGB,  // format
               GL_UNSIGNED_BYTE, // type
               img);
                           
// Affichage :

        glm::mat4 mvp = projection * modelview;

    glUseProgram(m_shader.getProgramID());

        // Texture :
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture_id);
    glUniform1i(uniform_mytexture, /*GL_TEXTURE*/0);

        // Matrice MVP :
    glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));

        // Les sommets de l'objet :
    glEnableVertexAttribArray(attribute_coord3d);
    glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices);
    glVertexAttribPointer(attribute_coord3d, 3, GL_FLOAT, GL_FALSE, 0, 0);

        // Les coordonnées de la texture :
    glEnableVertexAttribArray(attribute_v_texture);
    glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_texcoords);
    glVertexAttribPointer(attribute_v_texture, 2, GL_FLOAT, GL_FALSE, 0, 0);

        // Les indices des sommets de l'objet :
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
    int size;
    glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);

        // Affichage :
    glDrawElements(GL_TRIANGLES, size/sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
    glDisableVertexAttribArray(attribute_coord3d);
    glDisableVertexAttribArray(attribute_v_texture);

Et mes shaders :
#version 120

attribute vec3 in_Vertex;
attribute vec2 in_TexCoord;

varying vec2 f_TexCoord;

uniform mat4 mvp;

void main()
{
    gl_Position = mvp * vec4(in_Vertex, 1.0);
    f_TexCoord = in_TexCoord;
}
 
#version 120

varying vec2 f_TexCoord;
uniform sampler2D Texture;

void main()
{
    gl_FragColor = texture2D(Texture, f_TexCoord);
}
 

Alors la première chose à laquelle j'ai pensé, c'est d'encadrer ma fonction d'affichage par
m_window->pushGLStates();
// AFFICHAGE
m_window->popGLStates();

Mais dans ce cas, mon programme est totalement bloqué jusqu'à ce qu'un gros "ne répond plus" Windows apparaisse.
J'ai dû faire une erreur quelque part, ce n'est probablement pas la SFML qui est en cause, mais comme l'erreur est apparemment située dans RenderTarget.cpp de la SFML, je me permets de poster ici...

Merci !!!  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Messages: 32504
    • Voir le profil
    • SFML's website
    • E-mail
Re : [SFML 2.0 / OpenGL 3.1] Erreur lors d'un dessin d'un objet avec texture
« Réponse #1 le: Novembre 05, 2012, 08:27:38 pm »
Il faudrait que tu extraies de tout ça un code complet minimal qui reproduit le problème.
Laurent Gomila - SFML developer

 

anything