31 GLuint fragment_shader;
39 std::string read(
const char *filename )
41 std::stringbuf source;
42 std::ifstream in(filename);
44 if(in.good() ==
false)
45 printf(
"[error] loading program '%s'...\n", filename);
47 printf(
"loading program '%s'...\n", filename);
60 glGenVertexArrays(1, &vao);
63 std::string vertex_source= read(
"tutos/tuto2GL_vertex.glsl");
65 vertex_shader= glCreateShader(GL_VERTEX_SHADER);
68 const char *vertex_strings[]= { vertex_source.c_str() };
69 glShaderSource(vertex_shader, 1, vertex_strings, NULL);
71 glCompileShader(vertex_shader);
74 std::string fragment_source= read(
"tutos/tuto2GL_fragment.glsl");
75 fragment_shader= glCreateShader(GL_FRAGMENT_SHADER);
76 const char *fragment_strings[]= { fragment_source.c_str() };
77 glShaderSource(fragment_shader, 1, fragment_strings, NULL);
78 glCompileShader(fragment_shader);
81 program= glCreateProgram();
83 glAttachShader(program, vertex_shader);
84 glAttachShader(program, fragment_shader);
86 glLinkProgram(program);
90 glGetProgramiv(program, GL_LINK_STATUS, &status);
91 if(status == GL_FALSE)
92 printf(
"[error] linking pogram...\n");
105 glDeleteShader(vertex_shader);
106 glDeleteShader(fragment_shader);
107 glDeleteProgram(program);
108 glDeleteVertexArrays(1, &vao);
117 glClearColor(0.2, 0.2, 0.2, 1);
118 glClear(GL_COLOR_BUFFER_BIT);
121 glUseProgram(program);
124 glBindVertexArray(vao);
127 glDrawArrays(GL_TRIANGLES, 0, 3);
133 int main(
int argc,
char **argv )
148 printf(
"[error] init failed.\n");
Context create_context(Window window)
cree et configure un contexte opengl
void release_window(Window window)
destruction de la fenetre.
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.
int init(std::vector< const char * > &options)
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.