IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SFML Discussion :

Cube mapping SFML


Sujet :

SFML

  1. #1
    Membre habitué
    Profil pro
    Dev
    Inscrit en
    Mai 2009
    Messages
    257
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Dev

    Informations forums :
    Inscription : Mai 2009
    Messages : 257
    Points : 190
    Points
    190
    Par défaut Cube mapping SFML
    Bonjour,

    Je cherche une solution de Cube mapping en Opengl afin de réaliser une skybox et faire de l'environnement mapping, mais je ne parviens pas à texturer la cube map
    J'ai comme lib de fenetrage la SFML 1.5;

    J'ai suivi de le tuto de raptor http://raptor.developpez.com/tutorial/opengl/skybox/ pour créer une skybox; mes textures s'affichent correctement en 2D mais c'est avec la texture cube mappée que cela se corse

    J'ai vérifié l'existence des extensions GL_EXT_texture_cube_map et GL_ARB_texture_cube_map

    Donc voici code (je mets l'essentiel)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
     
     
    //***************j'initialise mes constantes : 
     
    #define GL_TEXTURE_CUBE_MAP             0x8513
    #define GL_TEXTURE_BINDING_CUBE_MAP     0x8514
    #define GL_TEXTURE_CUBE_MAP_POSITIVE_X  0x8515
    #define GL_TEXTURE_CUBE_MAP_NEGATIVE_X  0x8516
    #define GL_TEXTURE_CUBE_MAP_POSITIVE_Y  0x8517
    #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y  0x8518
    #define GL_TEXTURE_CUBE_MAP_POSITIVE_Z  0x8519
    #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z  0x851A
     
    #define CUBE_MAP_SIZE 256
     
    //***************Puis je crée mes texture target 
     
    vector<GLenum> cube_map_target;
     
    cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
            cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
            cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
            cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
            cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
            cube_map_target.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
     
    //***************fonction de chargement d'image
     
    int LoadTex(string file, sf::Image& Image)
    {
        if (!Image.LoadFromFile(file))
            return EXIT_FAILURE;
     
        return 0;
    }
     
    //**********chargement des textures
     
    vector<sf::Image> textures;
     
    LoadTex("Skybox/XN.bmp", textures[0]);
        LoadTex("Skybox/XP.bmp", textures[1]);
        LoadTex("Skybox/YN.bmp", textures[2]);
        LoadTex("Skybox/YP.bmp", textures[3]);
        LoadTex("Skybox/ZN.bmp", textures[4]);
        LoadTex("Skybox/ZP.bmp", textures[5]);
     
    //****************** Génération d'une texture CubeMap
     
        GLuint cube_map_texture_ID;
        glEnable(GL_TEXTURE_CUBE_MAP);
        GLuint cube_map_texture_ID;
        glGenTextures(1, &cube_map_texture_ID);
     
    // Configuration de la texture
        glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID);
     
    //Création de la texture
        for (int i = 0; i < 6; i++)
        {
            sf::Image im = textures[i];
     
            glTexImage2D(cube_map_target[i], 0, 3, im.GetWidth(), im.GetHeight(), 0,   GL_RGB, GL_UNSIGNED_BYTE, im.GetPixelsPtr());
        }
     
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP);
     
        //************Création du cube
     
        //vertices
     
               // Taille du cube
        float t = 1.0f;
     
        float t_vertices[72] = {
     
        -t,-t,-t,
        -t,t,-t,
        t,t,-t,
        t,-t,-t,
     
        -t,-t,t,
        -t,t,t,
        t,t,t,
        t,-t,t,
     
        -t,-t,-t,
        -t,t,-t,
        -t,t,t,
        -t,-t,t,
     
        t,-t,-t,
        t,t,-t,
        t,t,t,
        t,-t,t,
     
        -t,-t,t,
        -t,-t,-t,
        t,-t,-t,
        t,-t,t,
     
     
        -t,t,t,
        -t,t,-t,
        t,t,-t,
        t,t,t
     
     
        };
     
    //indices
    int t_indices[24] = {
     
            0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
     
     
        };
     
     
    //coordonnées de textures (identiques aux coordonnées de vertices)
     
    float t_texcoords[72] = {
     
     
        -t,-t,-t,
        -t,t,-t,
        t,t,-t,
        t,-t,-t,
     
        -t,-t,t,
        -t,t,t,
        t,t,t,
        t,-t,t,
     
        -t,-t,-t,
        -t,t,-t,
        -t,t,t,
        -t,-t,t,
     
        t,-t,-t,
        t,t,-t,
        t,t,t,
        t,-t,t,
     
        -t,-t,t,
        -t,-t,-t,
        t,-t,-t,
        t,-t,t,
     
     
        -t,t,t,
        -t,t,-t,
        t,t,-t,
        t,t,t
    };
     
    //*************Rendu
     
    glEnable(GL_TEXTURE_CUBE_MAP);
    glBindTexture(GL_TEXTURE_CUBE_MAP, cube_map_texture_ID);
     
    //(les VBO ont été préalablement alloués)
     
        // Utilisation des données des buffers
        glBindBuffer(GL_ARRAY_BUFFER, VBObuffersId[0]);
        glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
     
        //stride de 3 car cube map
        glTexCoordPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(VBOverticesSize*sizeof(float));
     
     
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBObuffersId[1]);
     
        glDrawElements(GL_QUADS, VBOindicesSize[2], GL_UNSIGNED_INT, 0);

    Le cube est dessiné mais avec des stries (sillons) sur les faces

    Si je texture en 2D (face apres face) avec les textures de la Skybox, aucun problème

    Je n'arrive pas à situer quand ça pêche

    mauvaise utilisation de sf::Image GetPixelsPtr() ?Mauvaises coordonnées de textures ? Mauvaise définition des constantes ?

    Si certains possèdent du code utilisant les memes libs je suis preneur (pour le multitexturing également)

    J'attends vos réponses avec impatience

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Les images SFML ont un canal alpha, ce qui n'apparaît pas dans ton utilisation de glTexImage2D.

  3. #3
    Membre habitué
    Profil pro
    Dev
    Inscrit en
    Mai 2009
    Messages
    257
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Dev

    Informations forums :
    Inscription : Mai 2009
    Messages : 257
    Points : 190
    Points
    190
    Par défaut
    Ah d'accord, donc je dois juste modifier les paramètres de glTexImage2D(), ou bien remplacer cette fonction ?

  4. #4
    Membre habitué
    Profil pro
    Dev
    Inscrit en
    Mai 2009
    Messages
    257
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Dev

    Informations forums :
    Inscription : Mai 2009
    Messages : 257
    Points : 190
    Points
    190
    Par défaut
    Au temps pour moi il suffisait de remplacer GL_RGB par GL_RGBA

    glTexImage2D(cube_map_target[i], 0, 3, im.GetWidth(), im.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im.GetPixelsPtr());


    merci pour ton aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Appliquer cube mapping a deux fenetre différente en meme temps
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 5
    Dernier message: 29/07/2009, 12h01
  2. Cube mapping dynamique
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 3
    Dernier message: 28/04/2009, 17h43
  3. Texture avec Cube mapping
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 5
    Dernier message: 27/04/2009, 14h47
  4. Réponses: 4
    Dernier message: 27/02/2008, 12h48
  5. Rotation d'un cube map
    Par ShevchenKik dans le forum OpenGL
    Réponses: 1
    Dernier message: 08/02/2008, 16h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo