Bonjour,
Je suis entrain d'essayer d'appliquer une texture sur un objet QUAD seulement quand je souhaite charger une image JPG il me fait une magnifique erreur de segmentation au lancement du programme.
Il compile correctement mais ne veut pas se lancer.
Textures.hpp :
Textures.cpp :
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 #ifndef TEXTURES_HPP #define TEXTURES_HPP #include <GL/gl.h> #include <GL/glut.h> #include <iostream> #include <png.h> #include "jpeglib.h" #include "jerror.h" class Textures { GLuint TexNum[2]; public: int LoadJPG (const char * filename, int nb ); int LoadPNG (const char * filename, int nb ); }; #endif
Fontaine.hpp :
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 #include "Textures.hpp" int Textures::LoadJPG(const char * filename, int nb ) { struct jpeg_decompress_struct cinfo; // les infos du fichiers struct jpeg_error_mgr jerr; // les erreurs GLubyte *ligne; // une ligne (?) GLubyte *image; // l'image sous forme de données int ImageSize; // Taille de l'image cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); // Lit le fichier et son header, puis le décompresse FILE *fichier=fopen(filename, "rb"); jpeg_stdio_src(&cinfo, fichier); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress ( &cinfo ); ImageSize = cinfo.image_width * cinfo.image_height * 3; image = (GLubyte *) malloc ( ImageSize ); ligne=image; while ( cinfo.output_scanline < cinfo.output_height ) { ligne = image + 3 * cinfo.image_width * cinfo.output_scanline; jpeg_read_scanlines ( &cinfo, &ligne, 1 ); } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); // Traitements de la texture par OpenGL int error = glPixelStorei(GL_UNPACK_ALIGNMENT,1); // Construit la texture sous forme de données glGenTextures(nb, &TexNum[nb]); // Génère une ID pour la texture OpenGL glBindTexture(GL_TEXTURE_2D, TexNum[nb]); // Pointe la texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); // Génère la texture OpenGL en mémoire glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, cinfo.image_width, cinfo.image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); fclose (fichier); free (image); return TexNum[nb]; } int Textures::LoadPNG (const char * filename, int nb ) { return 0; }
Fontaine.cpp :
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 #ifndef FONTAINE_HPP #define FONTAINE_HPP #include <GL/gl.h> #include <GL/glut.h> #include <iostream> #include <cmath> #include "Textures.hpp" class Fontaine { public: Fontaine(); void chargerTextures(); void draw(void); }; #endif
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 #include "Fontaine.hpp" GLuint texture[2]; Textures text; void Fontaine::chargerTextures() { texture[0] = text.LoadJPG("img/veg008.jpg", 0); } Fontaine::Fontaine() { Fontaine::chargerTextures(); } void Fontaine::draw(void) { //int n = 15;int m = 15; glPushMatrix(); /*for ( int j = 0 ; j < m ; j++ ) { float hi = 1.0F-j*2.0F/m; float hf = hi-2.0F/m; glBegin(GL_QUAD_STRIP); for( int i = 0 ; i <= n ; i++ ){ float a = (2*M_PI*i)/n; float sn = -sin(a); float cs = cos(a); glNormal3f(cs,0.0F,sn); glVertex3f(cs,hi,sn); glVertex3f(cs,hf,sn); } glEnd(); }*/ glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2d(-5,-5); glVertex3d(-5,-5,5); glTexCoord2d(5,-5); glVertex3d(5,-5,5); glTexCoord2d(5,-5); glVertex3d(5,-5,-5); glTexCoord2d(-5,-5); glVertex3d(-5,-5,-5); glEnd(); glPopMatrix(); }
L'erreur de segmentation provient du fichier Textures.cpp dans la méthode Textures::LoadJPG et des lignes suivantes :
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(nb, &TexNum[nb]);
J'avoue que je suis bloqué et que j'ai beau chercher sur le web depuis le début de l'après midi. Si vous connaissez une astuce ou une bibliothèque sous Ubuntu qui permet de m'aider je suis preneur.
Merci d'avance
Bonne soirée
Partager