X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=test%2Fglx-dlopen-gpa.c;h=902802368d02878f6a60cac24d755b24ed7959ed;hb=0c8d32dabf4cec6957dfb4c071ecdb2fb4e4cd0e;hp=716d3e2ffc7e31351140a4ecc45b61fb10057448;hpb=6b4c98a569784ffe9c0d580daf687cb624708937;p=fips diff --git a/test/glx-dlopen-gpa.c b/test/glx-dlopen-gpa.c index 716d3e2..9028023 100644 --- a/test/glx-dlopen-gpa.c +++ b/test/glx-dlopen-gpa.c @@ -23,7 +23,7 @@ * * 1. Using GLX to construct an OpenGL context * 2. By using dlopen to dynamically load libGL.so - * 3. By using dlsym to lookup OpenGL functions + * 3. By using glXGetProcAddress to lookup OpenGL functions */ #define GL_GLEXT_PROTOTYPES @@ -34,14 +34,11 @@ #include #include -#include "util.h" +#include "util-x11.h" void* (*my_glXGetProcAddress) (char *); void (*my_glClear) (GLbitfield); void (*my_glClearColor) (GLclampf, GLclampf, GLclampf, GLclampf); -void (*my_glLoadIdentity) (void); -void (*my_glMatrixMode) (GLenum); -void (*my_glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); void (*my_glViewport) (GLint, GLint, GLsizei, GLsizei); XVisualInfo * (*my_glXChooseVisual) (Display *, int, int *); GLXContext (*my_glXCreateContext) (Display *, XVisualInfo *, GLXContext, Bool); @@ -49,98 +46,8 @@ void (*my_glXDestroyContext) (Display *, GLXContext); Bool (*my_glXMakeCurrent) (Display *, GLXDrawable, GLXContext); void (*my_glXSwapBuffers) (Display *, GLXDrawable); -static void -set_2d_projection (int width, int height) -{ - my_glMatrixMode (GL_PROJECTION); - my_glLoadIdentity (); - my_glOrtho (0, width, height, 0, 0, 1); - my_glMatrixMode (GL_MODELVIEW); -} - -static void -paint_rgb_using_clear (double r, double g, double b) -{ - my_glClearColor(r, g, b, 1.0); - my_glClear(GL_COLOR_BUFFER_BIT); -} - -static void -draw (Display *dpy, Window window, int width, int height) -{ - int i; - int visual_attr[] = { - GLX_RGBA, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, - GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR, - None - }; - - /* Window and context setup. */ - XVisualInfo *visual_info = my_glXChooseVisual(dpy, 0, visual_attr); - GLXContext ctx = my_glXCreateContext(dpy, visual_info, NULL, True); - my_glXMakeCurrent(dpy, window, ctx); - - my_glViewport(0, 0, width, height); - - set_2d_projection (width, height); - -/* Simply count through some colors, frame by frame. */ -#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2) - - int frame = 0; - for (i = 0; i < 2; i++) { - /* Frame: Draw a solid (magenta) frame */ - paint_rgb_using_clear (RGB(frame)); - my_glXSwapBuffers (dpy, window); - frame++; - - /* Frame: Draw a solid (yellow) frame */ - paint_rgb_using_clear (RGB(frame)); - my_glXSwapBuffers (dpy, window); - frame++; - - /* Frame: Draw a solid (cyan) frame */ - paint_rgb_using_clear (RGB(frame)); - my_glXSwapBuffers (dpy, window); - frame++; - } - - /* Cleanup */ - my_glXDestroyContext (dpy, ctx); -} - -static void -handle_events(Display *dpy, Window window) -{ - XEvent xev; - int width = 0; - int height = 0; - - XNextEvent (dpy, &xev); - - while (1) { - XNextEvent (dpy, &xev); - switch (xev.type) { - case ConfigureNotify: - width = xev.xconfigure.width; - height = xev.xconfigure.height; - break; - case Expose: - if (xev.xexpose.count == 0) { - draw (dpy, window, width, height); - return; - } - break; - } - } -} +#define COMMON_GL_PREFIX my_ +#include "common.c" static void resolve_symbols (void) @@ -176,24 +83,6 @@ resolve_symbols (void) exit (1); } - my_glLoadIdentity = my_glXGetProcAddress ("glLoadIdentity"); - if (my_glLoadIdentity == NULL) { - fprintf (stderr, "Failed to glXGetProcAddress glLoadIdentity\n"); - exit (1); - } - - my_glMatrixMode = my_glXGetProcAddress ("glMatrixMode"); - if (my_glMatrixMode == NULL) { - fprintf (stderr, "Failed to glXGetProcAddress glMatrixMode\n"); - exit (1); - } - - my_glOrtho = my_glXGetProcAddress ("glOrtho"); - if (my_glOrtho == NULL) { - fprintf (stderr, "Failed to glXGetProcAddress glOrtho\n"); - exit (1); - } - my_glViewport = my_glXGetProcAddress ("glViewport"); if (my_glViewport == NULL) { fprintf (stderr, "Failed to glXGetProcAddress glViewport\n"); @@ -236,14 +125,24 @@ main (void) { Display *dpy; Window window; - - util_init_display_window (&dpy, &window); + GLXContext ctx; + XVisualInfo *visual_info; resolve_symbols (); - handle_events (dpy, window); + dpy = util_x11_init_display (); + + common_create_glx_context (dpy, &ctx, &visual_info); + + window = util_x11_init_window (dpy, visual_info); + + common_make_current (dpy, ctx, window); + + common_handle_events (dpy, dpy, window); + + util_x11_fini_window (dpy, window); - util_fini_display_window (dpy, window); + util_x11_fini_display (dpy); return 0; }