43# include <epoxy/glx.h>
48#define APP_EXTENSION ".exe"
63 char * help =
"\nUsage: ATOMES_OPENGL_TESTING\n\n"
64 " atomes OpenGL setup utility\n\n"
66 " -v, --version version information\n"
67 " -h, --help display this help message\n\n";
68 char bug[20] =
"\nReport a bug to <";
73 printf(
"%s", PACKAGE_BUGREPORT);
84 char scanid[80]=
"\natomes OpenGL setup utility\n";
85 char bug[20] =
"\nReport a bug to <";
88 printf (
"%s", scanid);
89 printf (
"\n%s version : %s\n", PACKAGE, VERSION);
90 printf (
"\nGTK+ version : %1d.%1d.%1d\n",
95 printf (
"%s", PACKAGE_BUGREPORT);
109 gtk_widget_set_visible (widg, TRUE);
111 gtk_widget_show_all (widg);
125 gtk_widget_set_visible (widg, FALSE);
127 gtk_widget_hide (widg);
140 if (GTK_IS_WIDGET(widg))
142 return gtk_widget_is_visible (widg);
161 if (GTK_IS_WIDGET(widg))
165 gtk_widget_destroy (widg);
184 glGetIntegerv (GL_NUM_EXTENSIONS, & i);
187 if (g_strcmp0 (extension, (
const char*)glGetStringi(GL_EXTENSIONS, j)) == 0)
return TRUE;
199 glEnable (GL_DEPTH_TEST);
200 glDepthMask (GL_TRUE);
201 glDepthFunc (GL_LEQUAL);
202 glDepthRange (0.0f, 1.0f);
204 glEnable (GL_NORMALIZE);
206 glShadeModel(GL_SMOOTH);
208 glEnable (GL_CULL_FACE);
212 glEnable (GL_PROGRAM_POINT_SIZE);
213 glEnable (GL_VERTEX_PROGRAM_POINT_SIZE);
214 glEnable (GL_POINT_SPRITE);
216 glEnable (GL_POINT_SMOOTH);
217 glHint (GL_POINT_SMOOTH_HINT, GL_NICEST);
218 glEnable (GL_LINE_SMOOTH);
219 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
221 glDisable (GL_POLYGON_SMOOTH);
222 glEnable (GL_POLYGON_STIPPLE);
223 glEnable (GL_POLYGON_OFFSET_FILL);
226 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
228 glPolygonOffset (1.0, 1.0);
229 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
231 glHint (GL_FOG_HINT, GL_NICEST);
232 glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
246 area = (GtkGLArea *)gtk_gl_area_new ();
250 gtk_gl_area_make_current (area);
252 gtk_gl_area_set_has_depth_buffer (area, TRUE);
253 gtk_gl_area_set_has_stencil_buffer (area, TRUE);
254 return gtk_gl_area_get_error (area);
266G_MODULE_EXPORT
void on_realize (GtkGLArea * area, gpointer data)
276G_MODULE_EXPORT
void on_realize (GtkWidget * widg, gpointer data)
285 GdkWindow *
xwin = gtk_widget_get_window (widg);
286 GLint attr_list[] = {GLX_DOUBLEBUFFER,
293 XVisualInfo * visualinfo = glXChooseVisual (GDK_WINDOW_XDISPLAY (
xwin),
294 gdk_screen_get_number (gdk_window_get_screen (
xwin)), attr_list);
295 GLXcontext *
glcontext = glXCreateContext (GDK_WINDOW_XDISPLAY (
xwin), visualinfo, NULL, TRUE);
297 if (glXMakeCurrent (GDK_WINDOW_XDISPLAY (
xwin), GDK_WINDOW_XID (
xwin),
glcontext))
335void gtk_window_change_gdk_visual (GtkWidget * win)
341 GdkScreen * screen = gdk_screen_get_default ();
342 GList * visuals = gdk_screen_list_visuals (screen);
344 GdkX11Screen* x11_screen = GDK_X11_SCREEN (screen);
345 g_assert (x11_screen != NULL);
346 Visual * default_xvisual = DefaultVisual (GDK_SCREEN_XDISPLAY(x11_screen), GDK_SCREEN_XNUMBER(x11_screen));
347 GdkVisual * default_visual = NULL;
349 while (visuals != NULL)
351 GdkVisual * visual = GDK_X11_VISUAL (visuals -> data);
352 if (default_xvisual -> visualid == gdk_x11_visual_get_xvisual(GDK_X11_VISUAL (visuals -> data)) -> visualid)
355 default_visual = visual;
358 visuals = visuals -> next;
360 gtk_widget_set_visual (win, default_visual);
374 GtkWidget * win = gtk_application_window_new (GTK_APPLICATION(app));
384 area = gtk_gl_area_new ();
386 area = gtk_drawing_area_new ();
389 gtk_container_add (GTK_CONTAINER(win), area);
391 gtk_window_set_child (GTK_WINDOW(win), area);
393 g_signal_connect (G_OBJECT (area),
"realize", G_CALLBACK(
on_realize), NULL);
433 g_application_quit (app);
436int main (
int argc,
char * argv[])
438 gboolean RUNC = TRUE;
442 if (g_strcmp0 (argv[1],
"-h") == 0 || g_strcmp0 (argv[1],
"--help") == 0)
447 else if (g_strcmp0 (argv[1],
"-v") == 0 || g_strcmp0 (argv[1],
"--version") == 0)
463 GtkApplication * TestOpenGLApp;
464#if GLIB_MINOR_VERSION < 74
465 TestOpenGLApp = gtk_application_new (g_strdup_printf (
"fr.ipcms.atomes.ogl-%d", (
int)clock()), G_APPLICATION_FLAGS_NONE);
467 TestOpenGLApp = gtk_application_new (g_strdup_printf (
"fr.ipcms.atomes.ogl-%d", (
int)clock()), G_APPLICATION_DEFAULT_FLAGS);
469 GError * error = NULL;
470 g_application_register (G_APPLICATION(TestOpenGLApp), NULL, & error);
471 g_signal_connect (G_OBJECT(TestOpenGLApp),
"activate", G_CALLBACK(
run_opengl_test), NULL);
472 int status = g_application_run (G_APPLICATION (TestOpenGLApp), 0, NULL);
473 g_object_unref (TestOpenGLApp);
G_MODULE_EXPORT void on_realize(GtkWidget *widg, gpointer data)
realize event for the OpenGL widget
int main(int argc, char *argv[])
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
GError * init_gtk_gl_area(GtkGLArea *area)
void test_opengl_window(GApplication *app)
test possibility to create an OpenGL context
G_MODULE_EXPORT void run_opengl_test(GApplication *app, gpointer data)
run the OpenGL testing
void init_opengl()
initialize OpenGL rendering parameters
GtkWidget * create_opengl_window(GApplication *app)
create the test OpenGL window
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
gboolean is_GLExtension_Supported(const char *extension)
void show_the_widgets(GtkWidget *widg)
show GtkWidget