Bonjour, voila je commence opengl j'essaye de faire une boite avec des textures dessus.
En ce moment j'ai réussi a faire la boite et je voudrais rajouter la texture.
Malheureusement j'ai une erreur de segmentation sur la fontion glGenTextures(1, &_texture[0]);
Je ne comprend pas d'ou ca vient surtout que le fichier BMP à l'air d'ètre bien chargé :
Je poste mon code si quelqu'un à la solut ce serit sympa car cela fait depuis toutes l'après-midi que je cherche.
main.cpp
scene.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 using namespace std; #include <stdlib.h> #include <math.h> #include <unistd.h> #include <GL/glew.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include "scene.hpp" #define ESCAPE 27 // La scene Scene s; // La fenetre int _win; int _win_width; int _win_height; // Prototype glut void Rechape (int Width, int Height); void Display (); void Keyboard (unsigned char key, int x, int y); int main(int argc, char **argv) { // Initialisation fenetre glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH); glutInitWindowSize(640, 480); glutInitWindowPosition(50, 50); _win = glutCreateWindow("SIA Project - FERY MORI"); glutFullScreen(); // Initialisation evenement glutDisplayFunc(&Display); glutIdleFunc(&Display); glutReshapeFunc(&Rechape); glutKeyboardFunc(&Keyboard); // OpenGL - Boucle glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)_win_width/(GLfloat)_win_height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glutMainLoop(); return 1; } /* Evenement : ----------- */ void Rechape (int Width, int Height) { if (Height==0) Height=1; glViewport(0, 0, Width, Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); } void Display () { glClearColor(175,151,124,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); s.draw(); glutSwapBuffers(); } void Keyboard (unsigned char key, int x, int y) { if (key == ESCAPE) { glutDestroyWindow(_win); exit(0); } }
scene.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 #ifndef SCENE_HPP #define SCENE_HPP #include <GL/glut.h> #include <GL/gl.h> #include <GL/glu.h> #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <iostream> class Scene { public: Scene (); void draw (); private: GLuint _texture[1]; void LoadGLTextures (); void caisse (); }; #endif /* SCENE_HPP */
Merci d'avance.
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 using namespace std; #include "scene.hpp" #include <GL/glut.h> #include <GL/gl.h> #include <GL/glu.h> #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <iostream> /* Constructeur Chargement Affichage */ Scene::Scene () { LoadGLTextures(); } void Scene::draw () { caisse(); } void Scene::LoadGLTextures( ) { SDL_Surface *TextureImage[1]; if ((TextureImage[0] = SDL_LoadBMP( "../texture/caisse_bois.bmp" ))) cout << "Erreur chargement image" << endl; // Création de la texture glGenTextures(1, &_texture[0]); glBindTexture( GL_TEXTURE_2D, _texture[0] ); glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w, TextureImage[0]->h, 0, GL_BGR, GL_UNSIGNED_BYTE, TextureImage[0]->pixels ); // Filtre linéaire glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); if ( TextureImage[0] ) SDL_FreeSurface( TextureImage[0] ); } /* Objets de la scene : -------------------- */ void Scene::caisse () { glColor3f (0, 0, 0); glBegin(GL_QUADS); // Dessous glVertex3f (-0.5, -0.5, 0); glVertex3f (0.5, -0.5, 0); glVertex3f (0.5, 0.5, 0); glVertex3f (-0.5, 0.5, 0); // Droite glVertex3f (-0.5, -0.5 , 1); glVertex3f (-0.5, 0.5 , 1); glVertex3f (-0.5, 0.5 , 0); glVertex3f (-0.5, -0.5 , 0); // Gauche glVertex3f (0.5, -0.5 , 1); glVertex3f (0.5, 0.5 , 1); glVertex3f (0.5, 0.5 , 0); glVertex3f (0.5, -0.5 , 0); // Devant glVertex3f (-0.5, 0.5 , 1); glVertex3f (0.5, 0.5 , 1); glVertex3f (0.5, 0.5 , 0); glVertex3f (-0.5, 0.5 , 0); // Derrière glVertex3f (-0.5, -0.5 , 1); glVertex3f (0.5, -0.5 , 1); glVertex3f (0.5, -0.5 , 0); glVertex3f (-0.5, -0.5 , 0); // Dessus glVertex3f (-0.5, -0.5 , 1); glVertex3f (0.5, -0.5 , 1); glVertex3f (0.5, 0.5 , 1); glVertex3f (-0.5, 0.5 , 1); glEnd(); }
Partager