Bonsoir
Je suis en train d'apprendre OpenGL,
et j'aimerai créer un objet static Texture pour ne pas à avoir créer des centaines de fois la même texture.
Or depuis ce matin, je bloque sur un problème à propos de ces textures très embêtant.
Dans un premier temps il m'est impossible d'envoyer la texture de type GLuint vers glBindTexture
Voici l'erreur :
Puis dans un second temps j'ai une erreur qui est apparu en même temps que la première :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 1>QuadShape.obj : error LNK2001: symbole externe non résolu "public: static class texture::Texture texture::Texture::dirt" (?dirt@Texture@texture@@2V12@A) 1>F:\Documents\Programmation\Visual Studio 2015\Projects\Opengl_1\Debug\Opengl_1.exe : fatal error LNK1120: 1 externes non résolus
glGenerateMipmap cré cette erreur :
Voici le code réduit au minimum :
Code : Sélectionner tout - Visualiser dans une fenêtre à part Exception levée à 0x00000000 dans Opengl_1.exe*: 0xC0000005*: Violation d'accès lors de l'exécution à l'emplacement 0x00000000.
Texture.h
Texture.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 #ifndef TEXTURE #define TEXTURE #include <GL\glew.h> #include <iostream> using namespace std; namespace texture { class Texture { public: Texture() {} Texture(const char* path); void Link(const char* path); GLuint Get(); static Texture dirt; private: int width, height, nbrChannels; GLuint texture; }; } #endif TEXTURE
QuadShape.h
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 #ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #include "Texture.h" namespace texture { Texture::Texture(const char* path) { Link(path); } void Texture::Link(const char* path) { glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); unsigned char *data; data = stbi_load(path, &width, &height, &nbrChannels, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); stbi_image_free(data); } GLuint Texture::Get() { return texture; } Texture container = Texture("container.jpg"); } #endif STB_IMAGE_IMPLEMENTATION
QuadShape.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 #ifndef QUAD_SHAPE_H #define QUAD_SHAPE_H #include <GL\glew.h> #include "math.h" #include "Texture.h" using namespace texture; class QuadShape { public: QuadShape(); void Render(bool POLYGON_MODE); private: Vertex vertices[4]; GLuint indices[6]; GLuint VBO, EBO, VAO; }; #endif QUAD_SHAPE_H
Peut être que ce que j'ai mis à disposition est trop insuffisant
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 #include "QuadShape.h" QuadShape::QuadShape() { //Quad //Position vertices[0].position = vec3(-1.0f, 1.0f, 0.0f); //Left Top vertices[1].position = vec3(-1.0f, -1.0f, 0.0f); //Left Bottom vertices[2].position = vec3(1.0f, -1.0f, 0.0f); //Right Bottom vertices[3].position = vec3(1.0f, 1.0f, 0.0f); //Right Top //Color vertices[0].color = vec3(0.0f, 0.0f, 0.0f); //Left Top vertices[1].color = vec3(0.0f, 1.0f, 0.0f); //Left Bottom vertices[2].color = vec3(1.0f, 0.0f, 1.0f); //Right Bottom vertices[3].color = vec3(1.0f, 1.0f, 0.0f); //Right Top //Texture Coords vertices[0].textCoords = vec2(0.0f, 1.0f); //Left Top vertices[1].textCoords = vec2(0.0f, 0.0f); //Left Bottom vertices[2].textCoords = vec2(1.0f, 0.0f); //Right Bottom vertices[3].textCoords = vec2(1.0f, 1.0f); //Right Top //indices indices[0] = 0, indices[1] = 1, indices[2] = 3, indices[3] = 1, indices[4] = 2, indices[5] = 3; //VAO glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); //VBO glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //EBO glGenBuffers(1, &EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); //Attribute 0 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(offsetof(Vertex, position))); glEnableVertexAttribArray(0); //Attribute 1 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(offsetof(Vertex, color))); glEnableVertexAttribArray(1); //Attribute 2 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(offsetof(Vertex, textCoords))); glEnableVertexAttribArray(2); } void QuadShape::Render(bool POLYGON_MODE) { if (POLYGON_MODE) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBindTexture(GL_TEXTURE_2D, Texture::dirt.Get()); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glBindVertexArray(0); }
Le problème est que ca ferai beaucoup de fichier...
J'espère que j'aurez bien décris mon problème et que vous arriverez à le résoudre
Merci d'avance pour votre aide
Martantoine
Partager