diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2011-06-12 13:09:41 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2011-06-12 13:09:41 +0800 |
commit | 7d43c08d665cc0703aec5ab8a5b467a7f5bee7ed (patch) | |
tree | c0d0c68d4733072fd65b8973900bb6e4d8379416 | |
parent | 898ed88397ba222491da5db71fe9e9e8e4d534f6 (diff) |
build: check if availablity of x
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/gles-test.c | 66 |
3 files changed, 67 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac index 8806885..610be2e 100644 --- a/configure.ac +++ b/configure.ac @@ -180,6 +180,10 @@ if test "x$enable_opengl" != "xno"; then AX_CHECK_GL fi AM_CONDITIONAL(HAVE_OPENGL, [test "x$no_gl" != x"yes" ]) +AM_CONDITIONAL(HAVE_X, [test "x$no_x" != x"yes" ]) +if test "x$no_x" != x"yes"; then + AC_DEFINE_UNQUOTED(HAVE_X, 1, [defined if you have X headers and libraries])], +fi SDL_FREETYPE_OPENGLES_REQUIRES="sdl-freetype" enable_opengles=auto @@ -200,7 +204,7 @@ if test "x$enable_opengles" != "xno"; then done LIBS="$EGL_LIBS $LIBS" - for gles1_lib in GLES_CM GLESv1_CM; do + for gles1_lib in GLES_CM GLESv1_CM GLESv1; do AC_CHECK_LIB($gles1_lib, glGenTextures, [GLES_LIBS="-l$gles1_lib" have_opengles=yes]) diff --git a/src/Makefile.am b/src/Makefile.am index 4dd63e0..2a43f7d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -71,7 +71,11 @@ sdl_opengl_test = sdl-opengl-test endif endif -noinst_PROGRAMS = hash-test cache-test font-test $(sdl_test) $(sdl_opengl_test) +if HAVE_OPENGLES +gles_test = gles-test +endif + +noinst_PROGRAMS = hash-test cache-test font-test $(sdl_test) $(sdl_opengl_test) $(gles_test) hash_test_SOURCES = hash-test.c hash_test_LDADD = libsdl-freetype.la @@ -87,6 +91,9 @@ sdl_test_LDADD = libsdl-ft.la sdl_opengl_test_SOURCES = sdl-opengl-test.c sdl_opengl_test_LDADD = libsdl-freetype-opengl.la libsdl-ft.la +gles_test_SOURCES = gles-test.c +gles_test_LDADD = libsdl-freetype-opengles.la libsdl-ft.la $(EGL_LIBS) + lib_LTLIBRARIES = \ libsdl-freetype.la \ $(libsdl_ft) \ diff --git a/src/gles-test.c b/src/gles-test.c index d9c5282..1f1aae5 100644 --- a/src/gles-test.c +++ b/src/gles-test.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <EGL/egl.h> #include <GLES/gl.h> @@ -11,8 +15,11 @@ static EGLDisplay eglDisplay = 0; static EGLConfig eglConfig = 0; static EGLContext eglContext = 0; static EGLSurface eglSurface = 0; + +#ifdef HAVE_X static Display *x11Display = NULL; static Window x11Window = None; +#endif // consts #define COLOURDEPTH_RED_SIZE 8 @@ -32,6 +39,10 @@ static const EGLint configAttribs[] ={ static int InitOpenGL(int width, int height) { + EGLint numConfigsOut = 0; + /* EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; // Use GLES version 1.x */ + +#ifdef HAVE_X // use EGL to initialise GLES x11Display = XOpenDisplay(NULL); @@ -56,6 +67,9 @@ static int InitOpenGL(int width, int height) XFlush(x11Display); eglDisplay = eglGetDisplay((EGLNativeDisplayType)x11Display); +#else + eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); +#endif if (eglDisplay == EGL_NO_DISPLAY) { printf("Unable to initialise EGL display."); @@ -70,14 +84,17 @@ static int InitOpenGL(int width, int height) } // Find a matching config - EGLint numConfigsOut = 0; if (eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0) { fprintf(stderr, "Unable to find appropriate EGL config."); return 0; } +#ifdef HAVE_X eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)x11Window, 0); +#else + eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)0, 0); +#endif if ( eglSurface == EGL_NO_SURFACE) { printf("Unable to create EGL surface!"); @@ -86,7 +103,6 @@ static int InitOpenGL(int width, int height) // Bind GLES and create the context eglBindAPI(EGL_OPENGL_ES_API); - EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; // Use GLES version 1.x eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); if (eglContext == EGL_NO_CONTEXT) { @@ -106,7 +122,7 @@ static int InitOpenGL(int width, int height) /*====================================================== * Kill off any opengl specific details ====================================================*/ -static void TerminateOpenGL() +static void TerminateOpenGL(void) { eglMakeCurrent(eglDisplay, NULL, NULL, EGL_NO_CONTEXT); eglDestroySurface(eglDisplay, eglSurface); @@ -118,18 +134,39 @@ static void TerminateOpenGL() eglTerminate(eglDisplay); eglDisplay = 0; +#ifdef HAVE_X XDestroyWindow(x11Display, x11Window); XCloseDisplay(x11Display); x11Display = NULL; +#endif } -static int SwapBuffers() +static int SwapBuffers(void) { eglSwapBuffers(eglDisplay, eglSurface); + return 0; } -#define TEXT "sdl freetype OpenGLES render" +static void DrawLine(float x0, float y0, float x1, float y1) +{ + GLfloat verts[4]; + verts[0] = x0; + verts[1] = y0; + verts[2] = x1; + verts[3] = y1; + + glEnableClientState (GL_VERTEX_ARRAY); + + glVertexPointer (2, GL_FLOAT, 0, verts); + glDrawArrays (GL_LINES, 0, 2); + + glDisableClientState (GL_VERTEX_ARRAY); +} + +#define TEXT "sdl freetype OpenGLES render" +#define WIDTH 640 +#define HEIGHT 480 int main(int argc, char *argv[]) { @@ -138,10 +175,10 @@ main(int argc, char *argv[]) sdl_freetype_glyph_render_t * render; sdl_freetype_text_extents_t extents; - if (!InitOpenGL(640, 480)) + if (!InitOpenGL(WIDTH, HEIGHT)) return -1; - font = sdl_ft_create_font ("sans", 20, + font = sdl_ft_create_font ("sans", 12, SDL_FT_WEIGHT_NORMAL, SDL_FT_SLANT_NORMAL, 96); if (!font) goto errquit0; @@ -153,31 +190,36 @@ main(int argc, char *argv[]) glMatrixMode (GL_PROJECTION) ; glLoadIdentity (); - glOrthof (0, 640.0f, 480.0f, 0, -1.0, 1.0); + glOrthof (0, WIDTH, HEIGHT, 0, -1.0, 1.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); done = 0; while (!done) { + float x, y; + +#ifdef HAVE_X XEvent xevent; + while (XPending(x11Display)) { XNextEvent(x11Display, &xevent); if (xevent.type == KeyPress) done = 1; } +#endif glClearColor (0.8f, 0.8f, 0.8f, 0.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); sdl_freetype_font_utf8_extents (font, &extents, TEXT, -1); + x = (WIDTH - extents.width) / 2 - extents.x_bearing; + y = (HEIGHT - extents.height) / 2 + extents.y_bearing; sdl_freetype_font_show_utf8 (font, NULL, 255, 0, 0, 255, - (640 - extents.width) / 2 + extents.x_bearing, - (480 - extents.height) / 2 + extents.y_bearing, - TEXT, -1); + x, y, TEXT, -1); + DrawLine(x, y, x + extents.width, y); SwapBuffers(); - usleep(10000); } errquit1: |