/* * Copyright (C) 2010 Nick Bowler * * License WTFPL2: Do What The Fuck You Want To Public License, version 2. * This is free software: you are free to do what the fuck you want to. * There is NO WARRANTY, to the extent permitted by law. * * In case the above is not acceptable, you may alternately choose the terms * of the MIT license: http://opensource.org/licenses/mit-license.php. */ #include #include #include void resize(GdkGLDrawable *drawable) { gint w, h; gdk_gl_drawable_get_size(drawable, &w, &h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); glOrtho(0, 1, 0, 1, -1, 1); glMatrixMode(GL_MODELVIEW); } void render(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINE_LOOP); glVertex2d(0.1, 0.1); glVertex2d(0.9, 0.1); glVertex2d(0.9, 0.9); glVertex2d(0.1, 0.9); glEnd(); } int main(int argc, char **argv) { GdkWindow *root, *win; GdkGLWindow *glwin; GdkGLConfig *config; GdkGLDrawable *drawable; GdkGLContext *context; gint screen_w, screen_h; int state = 0, mode = GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE; GdkWindowAttr attrs = { .window_type = GDK_WINDOW_TOPLEVEL, .wclass = GDK_INPUT_OUTPUT, .x = 0, .y = 0, .width = 300, .height = 300, .override_redirect = 1, }; gdk_init(&argc, &argv); gdk_gl_init(&argc, &argv); if (argc > 1 && strcmp(argv[1], "--single") == 0) mode &= ~GDK_GL_MODE_DOUBLE; root = gdk_get_default_root_window(); gdk_window_get_geometry(root, NULL, NULL, &screen_w, &screen_h, NULL); printf("screen size: %dx%d\n", screen_w, screen_h); config = gdk_gl_config_new_by_mode(mode); win = gdk_window_new(NULL, &attrs, GDK_WA_NOREDIR); glwin = gdk_window_set_gl_capability(win, config, NULL); drawable = gdk_window_get_gl_drawable(win); context = gdk_gl_context_new(drawable, NULL, 1, GDK_GL_RGBA_TYPE); if (gdk_gl_drawable_is_double_buffered(drawable)) puts("using double buffering"); else puts("using single buffering"); gdk_window_show(win); glClearColor(0.7, 0.7, 1.0, 0.0); glColor3d(0, 0, 0); while (1) { gdk_gl_drawable_make_current(drawable, context); resize(drawable); render(); if (gdk_gl_drawable_is_double_buffered(drawable)) gdk_gl_drawable_swap_buffers(drawable); else glFinish(); gdk_gl_drawable_gl_end(drawable); if (state = !state) gdk_window_resize(win, screen_w, screen_h); else gdk_window_resize(win, attrs.width, attrs.height); } return 0; }