19 const char *glsl_string(
const GLenum type )
46 void print_uniform_value(
const GLuint program,
const int index,
const char *name,
const GLenum type,
const GLint size )
54 float values[16]= { };
64 for(
int i= 0; i < n; i++)
74 glGetUniformiv(program, index +i, &
value);
78 glGetUniformiv(program, index +i, &
value);
82 glGetUniformfv(program, index +i, values);
83 printf(
"value= %f\n", values[0]);
86 glGetUniformfv(program, index +i, values);
87 printf(
"values= %f %f\n", values[0], values[1]);
90 glGetUniformfv(program, index +i, values);
91 printf(
"values= %f %f %f\n", values[0], values[1], values[2]);
94 glGetUniformfv(program, index +i, values);
95 printf(
"values= %f %f %f %f\n", values[0], values[1], values[2], values[3]);
98 glGetUniformfv(program, index +i, values);
100 for(
int r= 0; r < 4; r++)
103 for(
int c= 0; c < 4; c++)
104 printf(
"%f ", values[c*4 + r]);
110 printf(
" uniform '%s', type %x, type unknown\n", name, type);
120 int print_uniforms(
const GLuint program )
124 printf(
"[error] program 0, no uniforms...\n");
130 glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &n);
133 printf(
"program %u: no uniforms...\n", program);
139 glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &length_max);
142 char *name=
new char [length_max];
144 printf(
"program %u:\n", program);
146 for(
int index= 0; index < n; index++)
150 glGetActiveUniform(program, index, length_max, NULL, &glsl_size, &glsl_type, name);
152 GLint location= glGetUniformLocation(program, name);
154 printf(
" uniform %i '%s': location %d, type %s (0x%x), array_size %d\n", index, name, location,
155 glsl_string(glsl_type), glsl_type, glsl_size);
157 print_uniform_value(program, index, name, glsl_type, glsl_size);
166 int print_attribs(
const GLuint program,
const GLuint vao= 0 )
170 printf(
"[error] program 0, no attributes...\n");
176 glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &n);
179 printf(
"program %u: no attributes...\n", program);
185 glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &length_max);
188 char *name=
new char [length_max];
190 printf(
"program %u:\n", program);
192 for(
int index= 0; index < n; index++)
196 glGetActiveAttrib(program, index, length_max, NULL, &glsl_size, &glsl_type, name);
198 GLint location= glGetAttribLocation(program, name);
200 printf(
" attribute %d '%s': location %d, type %s (0x%x), array_size %d\n", index, name, location,
201 glsl_string(glsl_type), glsl_type, glsl_size);
206 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &buffer);
208 printf(
" buffer %d\n", buffer);
229 print_uniforms(program);
235 GLint location= glGetUniformLocation(program,
"positions");
243 glGenVertexArrays(1, &vao);
246 print_uniforms(program);
248 print_attribs(program, vao);
251 glClearColor(0.2, 0.2, 0.2, 1);
254 glDepthFunc(GL_LESS);
255 glEnable(GL_DEPTH_TEST);
263 glDeleteVertexArrays(1, &vao);
272 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
275 glBindVertexArray(vao);
278 glUseProgram(program);
282 location= glGetUniformLocation(program,
"color");
283 glUniform4f(location, 1, 0.5, 0, 1);
301 glDrawArrays(GL_TRIANGLES, 0, 36);
307 int main(
int argc,
char **argv )
322 printf(
"[error] init failed.\n");
representation d'un objet / maillage.
const float * vertex_buffer() const
renvoie l'adresse de la position du premier sommet. permet de construire les vertex buffers openGL....
int vertex_count() const
renvoie le nombre de sommets.
void release()
detruit les objets openGL.
Context create_context(Window window)
cree et configure un contexte opengl
void release_window(Window window)
destruction de la fenetre.
bool value(Widgets &w, const char *label, int &value, const int value_min, const int value_max, const int value_step)
valeur editable par increment.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Window create_window(const int w, const int h, const int major, const int minor, const int samples)
creation d'une fenetre pour l'application.
void release_context(Context context)
detruit le contexte openGL.
Point min(const Point &a, const Point &b)
renvoie la plus petite composante de chaque point. x, y, z= min(a.x, b.x), min(a.y,...
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 release_program(const GLuint program)
detruit les shaders et le program.
int init(std::vector< const char * > &options)
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.