33{
34
37
38
40 if(mesh.vertex_count() == 0)
41 return -1;
42
43 vertex_count= mesh.vertex_count();
44
46 mesh.bounds(pmin, pmax);
47 camera.lookat(pmin, pmax);
48
49
50
51 glGenVertexArrays(1, &vao);
52 glBindVertexArray(vao);
53
54
55 glGenBuffers(1, &vertex_buffer);
56 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
57 glBufferData(GL_ARRAY_BUFFER, mesh.vertex_buffer_size(), mesh.vertex_buffer(), GL_STATIC_DRAW);
58
59
60 GLint position= glGetAttribLocation(program, "position");
61 if(position < 0)
62 return -1;
63 glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0);
64 glEnableVertexAttribArray(position);
65
66
67 glGenBuffers(1, &texcoord_buffer);
68 glBindBuffer(GL_ARRAY_BUFFER, texcoord_buffer);
69 glBufferData(GL_ARRAY_BUFFER, mesh.texcoord_buffer_size(), mesh.texcoord_buffer(), GL_STATIC_DRAW);
70
71
72 GLint texcoord= glGetAttribLocation(program, "texcoord");
73 if(texcoord < 0)
74 return -1;
75 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
76 glEnableVertexAttribArray(texcoord);
77
78
79 mesh.release();
80 glBindVertexArray(0);
81 glBindBuffer(GL_ARRAY_BUFFER, 0);
82
83
85
86 GLenum data_format;
87 GLenum data_type= GL_UNSIGNED_BYTE;
88 if(image.channels == 3)
89 data_format= GL_RGB;
90 else
91 data_format= GL_RGBA;
92
93 glGenTextures(1, &texture);
94 glBindTexture(GL_TEXTURE_2D, texture);
95
96 glTexImage2D(GL_TEXTURE_2D, 0,
97 GL_RGBA, image.width, image.height, 0,
98 data_format, data_type, image.data());
99
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
101
102
103 glBindTexture(GL_TEXTURE_2D, 0);
104 glUseProgram(0);
105
106
107 glClearColor(0.2f, 0.2f, 0.2f, 1);
108 glClearDepthf(1);
109
110 glDepthFunc(GL_LESS);
111 glEnable(GL_DEPTH_TEST);
112
113 glFrontFace(GL_CCW);
114 glCullFace(GL_BACK);
115 glEnable(GL_CULL_FACE);
116 return 0;
117}
representation d'un objet / maillage.
ImageData read_image_data(const void *buffer, const unsigned size, const bool flipY)
charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en ca...
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
affiche les erreurs de compilation.
stockage temporaire des donnees d'une image.
representation d'un point 3d.