summaryrefslogtreecommitdiffstats
path: root/progs
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-04-01 13:47:53 +0800
committerChia-I Wu <[email protected]>2010-04-01 22:25:49 +0800
commitdd7276f494f81e57450fac93434ed6d9abfe8e41 (patch)
treea5d2b53f9247d8416797114264515c374318d099 /progs
parent765b30849cd271896901f9e02c920187e82c6494 (diff)
progs/egl: Port ES1 tri to eglut.
This also removes EGL_MESA_screen_surface version of ES1 tri as eglut supports the extension.
Diffstat (limited to 'progs')
-rw-r--r--progs/egl/opengles1/Makefile35
-rw-r--r--progs/egl/opengles1/screen/Makefile6
-rw-r--r--progs/egl/opengles1/screen/tri.c129
-rw-r--r--progs/egl/opengles1/tri.c311
4 files changed, 54 insertions, 427 deletions
diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile
index 0dd47edf1b3..d6c09c6abe3 100644
--- a/progs/egl/opengles1/Makefile
+++ b/progs/egl/opengles1/Makefile
@@ -19,6 +19,14 @@ ES1_LIBS = \
-L$(TOP)/$(LIB_DIR) -lEGL \
-L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ tri
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
PROGRAMS = \
bindtex \
drawtex \
@@ -27,16 +35,15 @@ PROGRAMS = \
pbuffer \
render_tex \
torus \
- tri \
two_win
.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
-default: $(PROGRAMS)
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
@@ -72,11 +79,23 @@ two_win: two_win.o $(ES1_LIB_DEPS)
$(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@
-tri: tri.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) tri.o $(ES1_LIBS) -o $@
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS)
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(ES1_LIBS) -L$(EGLUT_DIR) -leglut-$* -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(ES1_LIBS) -L$(EGLUT_DIR) -leglut-$*
-clean:
- rm -f *.o *~
- rm -f $(PROGRAMS)
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/egl/opengles1/screen/Makefile b/progs/egl/opengles1/screen/Makefile
index 5b2a59c71ca..0c3c136ff25 100644
--- a/progs/egl/opengles1/screen/Makefile
+++ b/progs/egl/opengles1/screen/Makefile
@@ -13,8 +13,7 @@ ES1_LIB_DEPS = \
WINSYS_OBJS = winsys.o
PROGRAMS = \
- gears \
- tri
+ gears
.c.o:
$(CC) -c $(ES1_CFLAGS) $(CFLAGS) $< -o $@
@@ -24,9 +23,6 @@ default: $(PROGRAMS)
gears: gears.o $(WINSYS_OBJS) $(ES1_LIB_DEPS)
$(CC) $(CFLAGS) -o $@ [email protected] $(WINSYS_OBJS) $(ES1_LIBS)
-tri: tri.o $(WINSYS_OBJS) $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) -o $@ [email protected] $(WINSYS_OBJS) $(ES1_LIBS)
-
clean:
-rm -f *.o *~
-rm -f $(PROGRAMS)
diff --git a/progs/egl/opengles1/screen/tri.c b/progs/egl/opengles1/screen/tri.c
deleted file mode 100644
index bab9499944b..00000000000
--- a/progs/egl/opengles1/screen/tri.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2009 Chia-I Wu <[email protected]>
- *
- * Based on egltri by
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <GLES/gl.h>
-#include "winsys.h"
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-static void tri_init()
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-}
-
-static void tri_reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-static void tri_draw(void *data)
-{
- static const GLfloat verts[3][2] = {
- { -1, -1 },
- { 1, -1 },
- { 0, 1 }
- };
- static const GLfloat colors[3][4] = {
- { 1, 0, 0, 1 },
- { 0, 1, 0, 1 },
- { 0, 0, 1, 1 }
- };
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_roty, 0, 1, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- {
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(4, GL_FLOAT, 0, colors);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- glPopMatrix();
-}
-
-static void tri_run(void)
-{
- winsysRun(3.0, tri_draw, NULL);
-}
-
-int main(int argc, char *argv[])
-{
- EGLint width, height;
- GLboolean printInfo = GL_FALSE;
- int i;
-
- /* parse cmd line args */
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-info") == 0) {
- printInfo = GL_TRUE;
- }
- else {
- printf("Warning: unknown parameter: %s\n", argv[i]);
- }
- }
-
- if (!winsysInitScreen())
- exit(1);
- winsysQueryScreenSize(&width, &height);
-
- if (printInfo) {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
- }
-
- tri_init();
- tri_reshape(width, height);
- tri_run();
-
- winsysFiniScreen();
-
- return 0;
-}
diff --git a/progs/egl/opengles1/tri.c b/progs/egl/opengles1/tri.c
index 42a978207c9..01ad9bd37e4 100644
--- a/progs/egl/opengles1/tri.c
+++ b/progs/egl/opengles1/tri.c
@@ -25,27 +25,18 @@
* 5 June 2008
*/
-#define USE_FULL_GL 0
-
#define USE_FIXED_POINT 0
#include <assert.h>
#include <math.h>
-#include <stdlib.h>
#include <stdio.h>
-#include <string.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-#if USE_FULL_GL
-#include <GL/gl.h> /* use full OpenGL */
-#else
#include <GLES/gl.h> /* use OpenGL ES 1.x */
#include <GLES/glext.h>
-#endif
#include <EGL/egl.h>
+#include "eglut.h"
+
#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
@@ -178,293 +169,43 @@ init(void)
test_query_matrix();
}
-
-/*
- * Create an RGB, double-buffered X window.
- * Return the window and context handles.
- */
-static void
-make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
- const char *name,
- int x, int y, int width, int height,
- Window *winRet,
- EGLContext *ctxRet,
- EGLSurface *surfRet)
-{
- static const EGLint attribs[] = {
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_DEPTH_SIZE, 1,
- EGL_NONE
- };
-
- int scrnum;
- XSetWindowAttributes attr;
- unsigned long mask;
- Window root;
- Window win;
- XVisualInfo *visInfo, visTemplate;
- int num_visuals;
- EGLContext ctx;
- EGLConfig config;
- EGLint num_configs;
- EGLint vid;
-
- scrnum = DefaultScreen( x_dpy );
- root = RootWindow( x_dpy, scrnum );
-
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- assert(config);
- assert(num_configs > 0);
-
- if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
- printf("Error: eglGetConfigAttrib() failed\n");
- exit(1);
- }
-
- /* The X window visual must match the EGL config */
- visTemplate.visualid = vid;
- visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
- if (!visInfo) {
- printf("Error: couldn't get X visual\n");
- exit(1);
- }
-
- /* window attributes */
- attr.background_pixel = 0;
- attr.border_pixel = 0;
- attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-
- win = XCreateWindow( x_dpy, root, 0, 0, width, height,
- 0, visInfo->depth, InputOutput,
- visInfo->visual, mask, &attr );
-
- /* set hints and properties */
- {
- XSizeHints sizehints;
- sizehints.x = x;
- sizehints.y = y;
- sizehints.width = width;
- sizehints.height = height;
- sizehints.flags = USSize | USPosition;
- XSetNormalHints(x_dpy, win, &sizehints);
- XSetStandardProperties(x_dpy, win, name, name,
- None, (char **)NULL, 0, &sizehints);
- }
-
-#if USE_FULL_GL
- eglBindAPI(EGL_OPENGL_API);
-#else
- eglBindAPI(EGL_OPENGL_ES_API);
-#endif
-
- ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
- if (!ctx) {
- printf("Error: eglCreateContext failed\n");
- exit(1);
- }
-
- *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
-
- if (!*surfRet) {
- printf("Error: eglCreateWindowSurface failed\n");
- exit(1);
- }
-
- XFree(visInfo);
-
- *winRet = win;
- *ctxRet = ctx;
-}
-
-
static void
-event_loop(Display *dpy, Window win,
- EGLDisplay egl_dpy, EGLSurface egl_surf)
+special_key(int special)
{
- while (1) {
- int redraw = 0;
- XEvent event;
-
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- reshape(event.xconfigure.width, event.xconfigure.height);
- break;
- case KeyPress:
- {
- char buffer[10];
- int r, code;
- code = XLookupKeysym(&event.xkey, 0);
- if (code == XK_Left) {
- view_roty += 5.0;
- }
- else if (code == XK_Right) {
- view_roty -= 5.0;
- }
- else if (code == XK_Up) {
- view_rotx += 5.0;
- }
- else if (code == XK_Down) {
- view_rotx -= 5.0;
- }
- else {
- r = XLookupString(&event.xkey, buffer, sizeof(buffer),
- NULL, NULL);
- if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
-
- if (redraw) {
- draw();
- eglSwapBuffers(egl_dpy, egl_surf);
- }
+ switch (special) {
+ case EGLUT_KEY_LEFT:
+ view_roty += 5.0;
+ break;
+ case EGLUT_KEY_RIGHT:
+ view_roty -= 5.0;
+ break;
+ case EGLUT_KEY_UP:
+ view_rotx += 5.0;
+ break;
+ case EGLUT_KEY_DOWN:
+ view_rotx -= 5.0;
+ break;
+ default:
+ break;
}
}
-
-static void
-usage(void)
-{
- printf("Usage:\n");
- printf(" -display <displayname> set the display to run on\n");
- printf(" -info display OpenGL renderer info\n");
-}
-
-
int
main(int argc, char *argv[])
{
- const int winWidth = 300, winHeight = 300;
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- GLboolean printInfo = GL_FALSE;
- EGLint egl_major, egl_minor;
- int i;
- const char *s;
-
- static struct {
- char *name;
- GLenum value;
- enum {GetString, GetInteger} type;
- } info_items[] = {
- {"GL_RENDERER", GL_RENDERER, GetString},
- {"GL_VERSION", GL_VERSION, GetString},
- {"GL_VENDOR", GL_VENDOR, GetString},
- {"GL_EXTENSIONS", GL_EXTENSIONS, GetString},
- {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger},
- {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger},
- };
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-display") == 0) {
- dpyName = argv[i+1];
- i++;
- }
- else if (strcmp(argv[i], "-info") == 0) {
- printInfo = GL_TRUE;
- }
- else {
- usage();
- return -1;
- }
- }
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
+ eglutInit(argc, argv);
- x_dpy = XOpenDisplay(dpyName);
- if (!x_dpy) {
- printf("Error: couldn't open display %s\n",
- dpyName ? dpyName : getenv("DISPLAY"));
- return -1;
- }
-
- egl_dpy = eglGetDisplay(x_dpy);
- if (!egl_dpy) {
- printf("Error: eglGetDisplay() failed\n");
- return -1;
- }
-
- if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
- printf("Error: eglInitialize() failed\n");
- return -1;
- }
-
- s = eglQueryString(egl_dpy, EGL_VERSION);
- printf("EGL_VERSION = %s\n", s);
-
- s = eglQueryString(egl_dpy, EGL_VENDOR);
- printf("EGL_VENDOR = %s\n", s);
-
- s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
- printf("EGL_EXTENSIONS = %s\n", s);
-
- s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
- printf("EGL_CLIENT_APIS = %s\n", s);
+ eglutCreateWindow("tri");
- make_x_window(x_dpy, egl_dpy,
- "OpenGL ES 1.x tri", 0, 0, winWidth, winHeight,
- &win, &egl_ctx, &egl_surf);
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+ eglutSpecialFunc(special_key);
- XMapWindow(x_dpy, win);
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent() failed\n");
- return -1;
- }
-
- if (printInfo) {
- for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) {
- switch (info_items[i].type) {
- case GetString:
- printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value));
- break;
- case GetInteger: {
- GLint rv = -1;
- glGetIntegerv(info_items[i].value, &rv);
- printf("%s = %d\n", info_items[i].name, rv);
- break;
- }
- }
- }
- };
init();
- /* Set initial projection/viewing transformation.
- * We can't be sure we'll get a ConfigureNotify event when the window
- * first appears.
- */
- reshape(winWidth, winHeight);
-
- event_loop(x_dpy, win, egl_dpy, egl_surf);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
+ eglutMainLoop();
return 0;
}