diff --git a/configure.ac b/configure.ac index e22593f..7d5cb42 100644 --- a/configure.ac +++ b/configure.ac @@ -946,6 +946,10 @@ if test "x$enable_lyricwiki" != "xno"; then ) fi +dnl Check for Opengl support +dnl ======================== +AX_CHECK_GL + dnl OpenGL Spectrum Analyzer dnl ======================== @@ -955,13 +959,7 @@ AC_ARG_ENABLE(glspectrum, have_glspectrum=no if test "x$enable_glspectrum" != "xno"; then - AC_CHECK_LIB([GL], [glXChooseVisual], - [have_glspectrum=yes - VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS gl-spectrum"], - [if test "x$enable_glspectrum" = "xyes"; then - AC_MSG_ERROR([Cannot find GLX development files, but compilation of OpenGL Spectrum Analyzer has been explicitly requested; please install GLX dev files and run configure again]) - fi] - ) + have_glspectrum=yes fi dnl *** End of all plugin checks *** diff --git a/extra.mk.in b/extra.mk.in index b4d6e0d..bb3ddde 100644 --- a/extra.mk.in +++ b/extra.mk.in @@ -84,3 +84,5 @@ XML_CFLAGS ?= @XML_CFLAGS@ XML_LIBS ?= @XML_LIBS@ XRENDER_CFLAGS ?= @XRENDER_CFLAGS@ XRENDER_LIBS ?= @XRENDER_LIBS@ +GL_CFLAGS ?= @GL_CFLAGS@ +GL_LIBS ?= @GL_LIBS@ diff --git a/src/gl-spectrum/Makefile b/src/gl-spectrum/Makefile index 0d766ea..f985c4e 100644 --- a/src/gl-spectrum/Makefile +++ b/src/gl-spectrum/Makefile @@ -7,6 +7,6 @@ include ../../extra.mk plugindir := ${plugindir}/${VISUALIZATION_PLUGIN_DIR} -CFLAGS += ${PLUGIN_CFLAGS} -CPPFLAGS += ${PLUGIN_CPPFLAGS} -I../.. ${GTK_CFLAGS} -LIBS += -lm ${GTK_LIBS} -lGL +CFLAGS += ${PLUGIN_CFLAGS} ${GL_CFLAGS} +CPPFLAGS += ${PLUGIN_CPPFLAGS} -I../.. ${GTK_CFLAGS} ${GL_CFLAGS} +LIBS += -lm ${GTK_LIBS} ${GL_LIBS} diff --git a/src/gl-spectrum/gl-spectrum.c b/src/gl-spectrum/gl-spectrum.c index 111acff..d3abc6f 100644 --- a/src/gl-spectrum/gl-spectrum.c +++ b/src/gl-spectrum/gl-spectrum.c @@ -27,11 +27,23 @@ #include #include -#include +#include #include #include + +#ifdef GDK_WINDOWING_X11 #include +#include +#endif + +#ifdef GDK_WINDOWING_WIN32 +#include +#endif + +#ifdef GDK_WINDOWING_QUARTZ +#include +#endif #define NUM_BANDS 32 #define DB_RANGE 40 @@ -42,7 +54,10 @@ static float logscale[NUM_BANDS + 1]; static float colors[NUM_BANDS][NUM_BANDS][3]; +#ifdef GDK_WINDOWING_X11 static GLXContext s_context; +#endif + static GtkWidget * s_widget = NULL; static int s_pos = 0; @@ -200,10 +215,48 @@ static void draw_bars (void) static bool_t draw_cb (GtkWidget * widget, cairo_t * cr) { +#ifdef GDK_WINDOWING_X11 Display * xdisplay = GDK_SCREEN_XDISPLAY (gdk_screen_get_default ()); Window xwindow = GDK_WINDOW_XID (gtk_widget_get_window (widget)); glXMakeCurrent (xdisplay, xwindow, s_context); +#endif + +#ifdef GDK_WINDOWING_WIN32 + PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor + { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, // Version Number (?) + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, // Must Support Double Buffering + PFD_TYPE_RGBA, // Request An RGBA Format + 24, // Select A 8:8:8 Bit Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) + 0, // No Alpha Buffer + 0, // Shift Bit Ignored (?) + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored (?) + 16, // 16Bit Z-Buffer (Depth Buffer) + 0, // No Stencil Buffer + 0, // No Auxiliary Buffer (?) + PFD_MAIN_PLANE, // Main Drawing Layer + 0, // Reserved (?) + 0, 0, 0 // Layer Masks Ignored (?) + }; + + GdkWindow *window = gtk_widget_get_window(widget); + HWND hWnd = GDK_WINDOW_HWND(window); + HDC hDC = GetDC(hWnd); + HGLRC hRC = wglCreateContext(hDC); + GLuint Found; + + Found = ChoosePixelFormat(hDC, &pfd); + if (Found) + SetPixelFormat(hDC, Found, &pfd); + + wglMakeCurrent(hDC, hRC); +#endif GtkAllocation alloc; gtk_widget_get_allocation (widget, & alloc); @@ -235,7 +288,21 @@ static bool_t draw_cb (GtkWidget * widget, cairo_t * cr) glDisable (GL_BLEND); glDepthMask (GL_TRUE); +#ifdef GDK_WINDOWING_X11 glXSwapBuffers (xdisplay, xwindow); +#endif + +#ifdef GDK_WINDOWING_WIN32 + SwapBuffers(hDC); + + wglMakeCurrent(hDC, NULL); + + // Kill The RC + wglDeleteContext(hRC); + + // Free The DC + ReleaseDC(hWnd, hDC); +#endif return TRUE; } @@ -250,6 +317,7 @@ static /* GtkWidget * */ void * get_widget (void) g_signal_connect (s_widget, "draw", (GCallback) draw_cb, NULL); g_signal_connect (s_widget, "destroy", (GCallback) gtk_widget_destroyed, & s_widget); +#ifdef GDK_WINDOWING_X11 GdkScreen * screen = gdk_screen_get_default (); Display * xdisplay = GDK_SCREEN_XDISPLAY (screen); int nscreen = GDK_SCREEN_XNUMBER (screen); @@ -272,6 +340,7 @@ static /* GtkWidget * */ void * get_widget (void) /* Fix up visual/colormap */ GdkVisual * visual = gdk_x11_screen_lookup_visual (screen, xvinfo->visualid); gtk_widget_set_visual (s_widget, visual); +#endif /* Disable GTK double buffering */ gtk_widget_set_double_buffered (s_widget, FALSE);