Précédent   Forum du club des développeurs et IT Pro > Applications > Développement 2D, 3D et Jeux > API graphiques > SFML
SFML Forum d'entraide sur l'API SFML
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 17/08/2009, 11h36   #1
coda_blank
Membre habitué
 
Inscription : mai 2009
Messages : 255
Détails du profil
Informations forums :
Inscription : mai 2009
Messages : 255
Points : 133
Points : 133
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 :
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
coda_blank est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/08/2009, 17h17   #2
Laurent Gomila
Rédacteur
 
Avatar de Laurent Gomila
 
Développeur informatique
Inscription : avril 2003
Messages : 10 651
Détails du profil
Informations personnelles :
Âge : 28
Localisation : France, Moselle (Lorraine)

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : avril 2003
Messages : 10 651
Points : 17 725
Points : 17 725
Les images SFML ont un canal alpha, ce qui n'apparaît pas dans ton utilisation de glTexImage2D.
__________________
Mieux que SDL : découvrez SFML
Laurent Gomila est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/08/2009, 16h58   #3
coda_blank
Membre habitué
 
Inscription : mai 2009
Messages : 255
Détails du profil
Informations forums :
Inscription : mai 2009
Messages : 255
Points : 133
Points : 133
Ah d'accord, donc je dois juste modifier les paramètres de glTexImage2D(), ou bien remplacer cette fonction ?
coda_blank est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/08/2009, 22h58   #4
coda_blank
Membre habitué
 
Inscription : mai 2009
Messages : 255
Détails du profil
Informations forums :
Inscription : mai 2009
Messages : 255
Points : 133
Points : 133
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
coda_blank est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 07h37.


 
 
 
 
Partenaires

Hébergement Web