26 GLuint fragment_shader;
35 std::string read(
const char *filename )
37 std::stringbuf source;
38 std::ifstream in(filename);
40 if(in.good() ==
false)
41 printf(
"[error] loading program '%s'...\n", filename);
43 printf(
"loading program '%s'...\n", filename);
56 std::string vertex_source= read(
"tutos/tuto1GL_vertex.glsl");
58 vertex_shader= glCreateShader(GL_VERTEX_SHADER);
61 const char *vertex_strings[]= { vertex_source.c_str() };
62 glShaderSource(vertex_shader, 1, vertex_strings, NULL);
64 glCompileShader(vertex_shader);
67 std::string fragment_source= read(
"tutos/tuto1GL_fragment.glsl");
68 fragment_shader= glCreateShader(GL_FRAGMENT_SHADER);
69 const char *fragment_strings[]= { fragment_source.c_str() };
70 glShaderSource(fragment_shader, 1, fragment_strings, NULL);
71 glCompileShader(fragment_shader);
74 program= glCreateProgram();
76 glAttachShader(program, vertex_shader);
77 glAttachShader(program, fragment_shader);
79 glLinkProgram(program);
83 glGetProgramiv(program, GL_LINK_STATUS, &status);
84 if(status == GL_FALSE)
86 printf(
"[error] compiling shaders / linking pogram...\n");
97 glGenVertexArrays(1, &vao);
113 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
114 glDrawBuffer(GL_BACK);
125 glViewport(0, 0, 1024, 640);
127 glClearColor(0.2, 0.2, 0.2, 1);
129 glDisable(GL_DEPTH_TEST);
130 glDisable(GL_CULL_FACE);
132 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
141 glDeleteShader(vertex_shader);
142 glDeleteShader(fragment_shader);
143 glDeleteProgram(program);
144 glDeleteVertexArrays(1, &vao);
153 glClear(GL_COLOR_BUFFER_BIT);
156 glBindVertexArray(vao);
159 glUseProgram(program);
164 glDrawArrays(GL_TRIANGLES, 0, 3);
168 int main(
int argc,
char **argv )
171 if(SDL_Init(SDL_INIT_VIDEO) < 0)
173 printf(
"[error] SDL_Init() failed:\n%s\n", SDL_GetError());
181 SDL_Window *window= SDL_CreateWindow(
"gKit", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 640, SDL_WINDOW_OPENGL);
184 printf(
"[error] SDL_CreateWindow() failed.\n");
189 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
190 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
191 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
192 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
195 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
197 SDL_GLContext context= SDL_GL_CreateContext(window);
200 printf(
"[error] creating openGL context.\n");
204 SDL_GL_SetSwapInterval(1);
209 GLenum err= glewInit();
212 printf(
"[error] loading extensions\n%s\n", glewGetErrorString(err));
213 SDL_GL_DeleteContext(context);
214 SDL_DestroyWindow(window);
219 while(glGetError() != GL_NO_ERROR) {;}
225 printf(
"[error] init failed.\n");
235 while(SDL_PollEvent(&event))
237 if(event.type == SDL_QUIT)
239 else if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
247 SDL_GL_SwapWindow(window);
253 SDL_GL_DeleteContext(context);
254 SDL_DestroyWindow(window);
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().
int init(std::vector< const char * > &options)