summaryrefslogtreecommitdiff
path: root/progs/egl/opengles1
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-05-21 09:32:38 -0700
committerEric Anholt <eric@anholt.net>2010-05-21 12:20:39 -0700
commit68fc4b415e322f6744299e39864fbc377c6eff74 (patch)
tree4bafffd8b0105174f3c5c0ae327a005be9145990 /progs/egl/opengles1
parente4f4489e3fc0b36d72821b55794fb843b2b7fa5f (diff)
Remove demos that have moved to git+ssh://git.freedesktop.org/git/mesa/demos.
The remaining programs are ones I've had difficulty finding a build environment for to make the build system or are unit tests that should probably live next to their code instead. Hopefully people can bring over the build for remaining pieces they care about.
Diffstat (limited to 'progs/egl/opengles1')
-rw-r--r--progs/egl/opengles1/.gitignore15
-rw-r--r--progs/egl/opengles1/Makefile99
-rw-r--r--progs/egl/opengles1/bindtex.c474
-rw-r--r--progs/egl/opengles1/drawtex.c217
-rw-r--r--progs/egl/opengles1/es1_info.c289
-rw-r--r--progs/egl/opengles1/gears.c383
-rw-r--r--progs/egl/opengles1/msaa.c442
-rw-r--r--progs/egl/opengles1/pbuffer.c611
-rw-r--r--progs/egl/opengles1/render_tex.c663
-rw-r--r--progs/egl/opengles1/texture_from_pixmap.c579
-rw-r--r--progs/egl/opengles1/torus.c452
-rw-r--r--progs/egl/opengles1/tri.c211
-rw-r--r--progs/egl/opengles1/two_win.c433
13 files changed, 0 insertions, 4868 deletions
diff --git a/progs/egl/opengles1/.gitignore b/progs/egl/opengles1/.gitignore
deleted file mode 100644
index 135e3deb35..0000000000
--- a/progs/egl/opengles1/.gitignore
+++ /dev/null
@@ -1,15 +0,0 @@
-bindtex
-drawtex_x11
-drawtex_screen
-es1_info
-gears_x11
-gears_screen
-msaa
-pbuffer
-render_tex
-texture_from_pixmap
-torus_x11
-torus_screen
-tri_x11
-tri_screen
-two_win
diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile
deleted file mode 100644
index e7802f8003..0000000000
--- a/progs/egl/opengles1/Makefile
+++ /dev/null
@@ -1,99 +0,0 @@
-# progs/egl/opengles1/Makefile
-
-TOP = ../../..
-include $(TOP)/configs/current
-
-
-INCLUDE_DIRS = \
- -I$(TOP)/include \
- $(X11_CFLAGS)
-
-HEADERS = $(TOP)/include/GLES/egl.h
-
-
-ES1_LIB_DEPS = \
- $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) \
- $(TOP)/$(LIB_DIR)/$(GLESv1_CM_LIB_NAME)
-
-
-ES1_LIBS = \
- -L$(TOP)/$(LIB_DIR) -l$(EGL_LIB) -l$(GLESv1_CM_LIB) \
- $(LIBDRM_LIB) $(X11_LIBS)
-
-EGLUT_DIR = $(TOP)/progs/egl/eglut
-
-EGLUT_DEMOS = \
- drawtex \
- gears \
- torus \
- tri
-
-EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
-EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
-
-PROGRAMS = \
- bindtex \
- es1_info \
- msaa \
- pbuffer \
- render_tex \
- texture_from_pixmap \
- two_win
-
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
-
-
-
-bindtex: bindtex.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@
-
-
-es1_info: es1_info.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@
-
-
-msaa: msaa.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@
-
-
-pbuffer: pbuffer.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@
-
-
-render_tex: render_tex.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@
-
-
-texture_from_pixmap: texture_from_pixmap.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) texture_from_pixmap.o $(ES1_LIBS) -o $@
-
-torus: torus.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@
-
-
-two_win: two_win.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@
-
-
-# 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 $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) $(X11_LIBS)
-$(EGLUT_SCREEN_DEMOS):
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS)
-
-
-clean:
- -rm -f *.o *~
- -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
diff --git a/progs/egl/opengles1/bindtex.c b/progs/egl/opengles1/bindtex.c
deleted file mode 100644
index c243b5941b..0000000000
--- a/progs/egl/opengles1/bindtex.c
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Simple demo for eglBindTexImage. Based on xegl_tri.c by
- *
- * Copyright (C) 2008 Brian Paul 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.
- */
-
-/*
- * The spec says that eglBindTexImage supports only OpenGL ES context, but this
- * demo uses OpenGL context. Keep in mind that this is non-standard.
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-#include <GLES/gl.h>
-#include <EGL/egl.h>
-
-static EGLDisplay dpy;
-static EGLContext ctx_win, ctx_pbuf;
-static EGLSurface surf_win, surf_pbuf;
-static GLuint tex_pbuf;
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-static GLboolean blend = GL_TRUE;
-static GLuint color_flow;
-
-static void
-make_pbuffer(int width, int height)
-{
- static const EGLint config_attribs[] = {
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
- EGL_NONE
- };
- EGLint pbuf_attribs[] = {
- EGL_WIDTH, width,
- EGL_HEIGHT, height,
- EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
- EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
- EGL_NONE
- };
- EGLConfig config;
- EGLint num_configs;
-
- if (!eglChooseConfig(dpy, config_attribs, &config, 1, &num_configs) ||
- !num_configs) {
- printf("Error: couldn't get an EGL visual config for pbuffer\n");
- exit(1);
- }
-
- ctx_pbuf = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL );
- surf_pbuf = eglCreatePbufferSurface(dpy, config, pbuf_attribs);
- if (surf_pbuf == EGL_NO_SURFACE) {
- printf("failed to allocate pbuffer\n");
- exit(1);
- }
-}
-
-static void
-use_pbuffer(void)
-{
- static int initialized;
-
- eglMakeCurrent(dpy, surf_pbuf, surf_pbuf, ctx_pbuf);
- if (!initialized) {
- EGLint width, height;
- GLfloat ar;
-
- initialized = 1;
-
- eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &width);
- eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &height);
- ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-ar, ar, -1, 1, 1.0, 10.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- /* y-inverted */
- glScalef(1.0, -1.0, 1.0);
-
- glTranslatef(0.0, 0.0, -5.0);
-
- glClearColor(0.2, 0.2, 0.2, 0.0);
-
- glGenTextures(1, &tex_pbuf);
- }
-}
-
-static void
-make_window(Display *x_dpy, const char *name,
- int x, int y, int width, int height,
- Window *winRet)
-{
- static const EGLint attribs[] = {
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
- EGL_DEPTH_SIZE, 8,
- EGL_NONE
- };
-
- int scrnum;
- XSetWindowAttributes attr;
- unsigned long mask;
- Window root;
- Window win;
- XVisualInfo *visInfo, visTemplate;
- int num_visuals;
- EGLConfig config;
- EGLint num_configs, vid;
-
- scrnum = DefaultScreen( x_dpy );
- root = RootWindow( x_dpy, scrnum );
-
- if (!eglChooseConfig(dpy, attribs, &config, 1, &num_configs) ||
- !num_configs) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- if (!eglGetConfigAttrib(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;
- attr.override_redirect = 0;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
-
- 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);
- }
-
- ctx_win = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL );
- if (!ctx_win) {
- printf("Error: eglCreateContext failed\n");
- exit(1);
- }
-
- surf_win = eglCreateWindowSurface(dpy, config, win, NULL);
-
- XFree(visInfo);
-
- *winRet = win;
-}
-
-static void
-use_window(void)
-{
- static int initialized;
-
- eglMakeCurrent(dpy, surf_win, surf_win, ctx_win);
- if (!initialized) {
- initialized = 1;
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, tex_pbuf);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
-}
-
-static void
-draw_triangle(void)
-{
- static const GLfloat verts[3][2] = {
- { -3, -3 },
- { 3, -3 },
- { 0, 3 }
- };
- GLfloat colors[3][4] = {
- { 1, 0, 0, 1 },
- { 0, 1, 0, 1 },
- { 0, 0, 1, 1 }
- };
- GLint i;
-
- /* flow the color */
- for (i = 0; i < 3; i++) {
- GLint first = (i + color_flow / 256) % 3;
- GLint second = (first + 1) % 3;
- GLint third = (second + 1) % 3;
- GLfloat c = (color_flow % 256) / 256.0f;
-
- c = c * c * c;
- colors[i][first] = 1.0f - c;
- colors[i][second] = c;
- colors[i][third] = 0.0f;
- }
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- 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);
-}
-
-static void
-draw_textured_cube(void)
-{
- static const GLfloat verts[][2] = {
- { -4, -4 },
- { 4, -4 },
- { 4, 4 },
- { -4, 4 }
- };
- static const GLfloat colors[][4] = {
- { 1, 1, 1, 0.5 },
- { 1, 1, 1, 0.5 },
- { 1, 1, 1, 0.5 },
- { 1, 1, 1, 0.5 }
- };
- static const GLfloat texs[][2] = {
- { 0, 0 },
- { 1, 0 },
- { 1, 1 },
- { 0, 1 }
- };
- static const GLfloat xforms[6][4] = {
- { 0, 0, 1, 0 },
- { 90, 0, 1, 0 },
- { 180, 0, 1, 0 },
- { 270, 0, 1, 0 },
- { 90, 1, 0, 0 },
- { -90, 1, 0, 0 }
- };
- GLint i;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- if (blend) {
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- } else {
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
-
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(4, GL_FLOAT, 0, colors);
- glTexCoordPointer(2, GL_FLOAT, 0, texs);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- for (i = 0; i < 6; i++) {
- glPushMatrix();
- glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]);
- glTranslatef(0, 0, 4.1);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- glPopMatrix();
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-static void
-draw(void)
-{
- use_pbuffer();
- draw_triangle();
-
- use_window();
-
- eglBindTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_roty, 0, 1, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- draw_textured_cube();
-
- glPopMatrix();
-
- eglReleaseTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER);
-}
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- use_window();
-
- 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, -40.0);
-}
-
-static void
-event_loop(Display *x_dpy, Window win)
-{
- while (1) {
- int redraw = 1;
-
- if (XPending(x_dpy) > 0) {
- XEvent event;
- XNextEvent(x_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 if (code == XK_b) {
- blend = !blend;
- }
- else {
- r = XLookupString(&event.xkey, buffer, sizeof(buffer),
- NULL, NULL);
- if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
- }
-
- if (redraw) {
- view_rotx += 1.0;
- view_roty += 2.0;
- view_rotz += 1.5;
- color_flow += 20;
- draw();
- eglSwapBuffers(dpy, surf_win);
- }
- }
-}
-
-int
-main(int argc, char *argv[])
-{
- const int winWidth = 300, winHeight = 300;
- Display *x_dpy;
- Window win;
- char *dpyName = NULL;
- EGLint egl_major, egl_minor;
- const char *s;
-
- x_dpy = XOpenDisplay(dpyName);
- if (!x_dpy) {
- printf("Error: couldn't open display %s\n",
- dpyName ? dpyName : getenv("DISPLAY"));
- return -1;
- }
-
- dpy = eglGetDisplay(x_dpy);
- if (!dpy) {
- printf("Error: eglGetDisplay() failed\n");
- return -1;
- }
-
- if (!eglInitialize(dpy, &egl_major, &egl_minor)) {
- printf("Error: eglInitialize() failed\n");
- return -1;
- }
-
- s = eglQueryString(dpy, EGL_VERSION);
- printf("EGL_VERSION = %s\n", s);
-
- make_window(x_dpy, "color flow", 0, 0, winWidth, winHeight, &win);
- make_pbuffer(winWidth, winHeight);
-
- XMapWindow(x_dpy, win);
-
- reshape(winWidth, winHeight);
- event_loop(x_dpy, win);
-
- glDeleteTextures(1, &tex_pbuf);
-
- eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglTerminate(dpy);
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/egl/opengles1/drawtex.c b/progs/egl/opengles1/drawtex.c
deleted file mode 100644
index e9ac015340..0000000000
--- a/progs/egl/opengles1/drawtex.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * Test GL_OES_draw_texture
- * Brian Paul
- * August 2008
- */
-
-#define GL_GLEXT_PROTOTYPES
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-#include "eglut.h"
-
-
-static GLfloat view_posx = 10.0, view_posy = 20.0;
-static GLfloat width = 200, height = 200;
-static GLboolean animate = GL_FALSE;
-static int win;
-
-
-static void
-draw(void)
-{
- glClear(GL_COLOR_BUFFER_BIT);
-
- glDrawTexfOES(view_posx, view_posy, 0.0, width, height);
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
-#ifdef GL_VERSION_ES_CM_1_0
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-#else
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -15.0);
-}
-
-
-static float
-dist(GLuint i, GLuint j, float x, float y)
-{
- return sqrt((i-x) * (i-x) + (j-y) * (j-y));
-}
-
-static void
-make_smile_texture(void)
-{
-#define SZ 128
- GLenum Filter = GL_LINEAR;
- GLubyte image[SZ][SZ][4];
- GLuint i, j;
- GLint cropRect[4];
-
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
- GLfloat d_mouth = dist(i, j, SZ/2, SZ/2);
- GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4);
- GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4);
- if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) {
- image[i][j][0] = 20;
- image[i][j][1] = 50;
- image[i][j][2] = 255;
- image[i][j][3] = 255;
- }
- else if (i < SZ/2 && d_mouth < SZ/3) {
- image[i][j][0] = 255;
- image[i][j][1] = 20;
- image[i][j][2] = 20;
- image[i][j][3] = 255;
- }
- else {
- image[i][j][0] = 200;
- image[i][j][1] = 200;
- image[i][j][2] = 200;
- image[i][j][3] = 255;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0); /* unit 0 */
- glBindTexture(GL_TEXTURE_2D, 42);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
- cropRect[0] = 0;
- cropRect[1] = 0;
- cropRect[2] = SZ;
- cropRect[3] = SZ;
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
-#undef SZ
-}
-
-
-
-static void
-init(void)
-{
- const char *ext = (char *) glGetString(GL_EXTENSIONS);
-
- if (!strstr(ext, "GL_OES_draw_texture")) {
- fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture");
- exit(1);
- }
-
- glClearColor(0.4, 0.4, 0.4, 0.0);
-
- make_smile_texture();
- glEnable(GL_TEXTURE_2D);
-}
-
-
-static void
-idle(void)
-{
- if (animate) {
- view_posx += 1.0;
- view_posy += 2.0;
- eglutPostRedisplay();
- }
-}
-
-static void
-key(unsigned char key)
-{
- switch (key) {
- case ' ':
- animate = !animate;
- break;
- case 'w':
- width -= 1.0f;
- break;
- case 'W':
- width += 1.0f;
- break;
- case 'h':
- height -= 1.0f;
- break;
- case 'H':
- height += 1.0f;
- break;
- case 27:
- eglutDestroyWindow(win);
- exit(0);
- break;
- default:
- break;
- }
-}
-
-static void
-special_key(int key)
-{
- switch (key) {
- case EGLUT_KEY_LEFT:
- view_posx -= 1.0;
- break;
- case EGLUT_KEY_RIGHT:
- view_posx += 1.0;
- break;
- case EGLUT_KEY_UP:
- view_posy += 1.0;
- break;
- case EGLUT_KEY_DOWN:
- view_posy -= 1.0;
- break;
- default:
- break;
- }
-}
-
-int
-main(int argc, char *argv[])
-{
- eglutInitWindowSize(400, 300);
- eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
- eglutInit(argc, argv);
-
- win = eglutCreateWindow("drawtex");
-
- eglutIdleFunc(idle);
- eglutReshapeFunc(reshape);
- eglutDisplayFunc(draw);
- eglutKeyboardFunc(key);
- eglutSpecialFunc(special_key);
-
- init();
-
- eglutMainLoop();
-
- return 0;
-}
diff --git a/progs/egl/opengles1/es1_info.c b/progs/egl/opengles1/es1_info.c
deleted file mode 100644
index 93816b5215..0000000000
--- a/progs/egl/opengles1/es1_info.c
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * List OpenGL ES extensions.
- * Print ES 1 or ES 2 extensions depending on which library we're
- * linked with: libGLESv1_CM.so vs libGLESv2.so
- */
-
-#define GL_GLEXT_PROTOTYPES
-
-#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>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-
-
-/*
- * Print a list of extensions, with word-wrapping.
- */
-static void
-print_extension_list(const char *ext)
-{
- const char *indentString = " ";
- const int indent = 4;
- const int max = 79;
- int width, i, j;
-
- if (!ext || !ext[0])
- return;
-
- width = indent;
- printf(indentString);
- i = j = 0;
- while (1) {
- if (ext[j] == ' ' || ext[j] == 0) {
- /* found end of an extension name */
- const int len = j - i;
- if (width + len > max) {
- /* start a new line */
- printf("\n");
- width = indent;
- printf(indentString);
- }
- /* print the extension name between ext[i] and ext[j] */
- while (i < j) {
- printf("%c", ext[i]);
- i++;
- }
- /* either we're all done, or we'll continue with next extension */
- width += len + 1;
- if (ext[j] == 0) {
- break;
- }
- else {
- i++;
- j++;
- if (ext[j] == 0)
- break;
- printf(", ");
- width += 2;
- }
- }
- j++;
- }
- printf("\n");
-}
-
-
-static void
-info(EGLDisplay egl_dpy)
-{
- const char *s;
-
- 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);
-
- printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_EXTENSIONS:\n");
- print_extension_list((char *) glGetString(GL_EXTENSIONS));
-}
-
-
-/*
- * 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, int es_ver,
- Window *winRet,
- EGLContext *ctxRet,
- EGLSurface *surfRet)
-{
- EGLint attribs[] = {
- EGL_RENDERABLE_TYPE, 0x0,
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_NONE
- };
- EGLint ctx_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 0,
- 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 (es_ver == 1)
- attribs[1] = EGL_OPENGL_ES_BIT;
- else
- attribs[1] = EGL_OPENGL_ES2_BIT;
- ctx_attribs[1] = es_ver;
-
- 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);
- }
-
- eglBindAPI(EGL_OPENGL_ES_API);
-
- ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
- 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
-usage(void)
-{
- printf("Usage:\n");
- printf(" -display <displayname> set the display to run on\n");
-}
-
-
-int
-main(int argc, char *argv[])
-{
- const int winWidth = 400, winHeight = 300;
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- EGLint egl_major, egl_minor, es_ver;
- int i;
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-display") == 0) {
- dpyName = argv[i+1];
- i++;
- }
- else {
- usage();
- return -1;
- }
- }
-
- 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;
- }
-
- es_ver = 1;
- /* decide the version from the executable's name */
- if (argc > 0 && argv[0] && strstr(argv[0], "es2"))
- es_ver = 2;
- make_x_window(x_dpy, egl_dpy,
- "ES info", 0, 0, winWidth, winHeight, es_ver,
- &win, &egl_ctx, &egl_surf);
-
- /*XMapWindow(x_dpy, win);*/
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent() failed\n");
- return -1;
- }
-
- info(egl_dpy);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/egl/opengles1/gears.c b/progs/egl/opengles1/gears.c
deleted file mode 100644
index 8462a4871a..0000000000
--- a/progs/egl/opengles1/gears.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
- *
- * Based on eglgears by
- * Copyright (C) 1999-2001 Brian Paul 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 <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <assert.h>
-
-#include <GLES/gl.h>
-#include "eglut.h"
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-
-struct gear {
- GLuint vbo;
- GLfloat *vertices;
- GLsizei stride;
-
- GLint num_teeth;
-};
-
-static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
-static struct gear gears[3];
-static GLfloat angle = 0.0;
-
-/*
- * Initialize a gear wheel.
- *
- * Input: gear - gear to initialize
- * inner_radius - radius of hole at center
- * outer_radius - radius at center of teeth
- * width - width of gear
- * teeth - number of teeth
- * tooth_depth - depth of tooth
- */
-static void
-init_gear(struct gear *gear, GLfloat inner_radius, GLfloat outer_radius,
- GLfloat width, GLint teeth, GLfloat tooth_depth)
-{
- GLfloat r0, r1, r2;
- GLfloat a0, da;
- GLint verts_per_tooth, total_verts, total_size;
- GLint count, i;
- GLfloat *verts;
-
- r0 = inner_radius;
- r1 = outer_radius - tooth_depth / 2.0;
- r2 = outer_radius + tooth_depth / 2.0;
-
- a0 = 2.0 * M_PI / teeth;
- da = a0 / 4.0;
-
- gear->vbo = 0;
- gear->vertices = NULL;
- gear->stride = sizeof(GLfloat) * 6; /* XYZ + normal */
- gear->num_teeth = teeth;
-
- verts_per_tooth = 10 + 4;
- total_verts = teeth * verts_per_tooth;
- total_size = total_verts * gear->stride;
-
- verts = malloc(total_size);
- if (!verts) {
- printf("failed to allocate vertices\n");
- return;
- }
-
-#define GEAR_VERT(r, n, sign) \
- do { \
- verts[count * 6 + 0] = (r) * vx[n]; \
- verts[count * 6 + 1] = (r) * vy[n]; \
- verts[count * 6 + 2] = (sign) * width * 0.5; \
- verts[count * 6 + 3] = normal[0]; \
- verts[count * 6 + 4] = normal[1]; \
- verts[count * 6 + 5] = normal[2]; \
- count++; \
- } while (0)
-
- count = 0;
- for (i = 0; i < teeth; i++) {
- GLfloat normal[3];
- GLfloat vx[5], vy[5];
- GLfloat u, v;
-
- normal[0] = 0.0;
- normal[1] = 0.0;
- normal[2] = 0.0;
-
- vx[0] = cos(i * a0 + 0 * da);
- vy[0] = sin(i * a0 + 0 * da);
- vx[1] = cos(i * a0 + 1 * da);
- vy[1] = sin(i * a0 + 1 * da);
- vx[2] = cos(i * a0 + 2 * da);
- vy[2] = sin(i * a0 + 2 * da);
- vx[3] = cos(i * a0 + 3 * da);
- vy[3] = sin(i * a0 + 3 * da);
- vx[4] = cos(i * a0 + 4 * da);
- vy[4] = sin(i * a0 + 4 * da);
-
- /* outward faces of a tooth, 10 verts */
- normal[0] = vx[0];
- normal[1] = vy[0];
- GEAR_VERT(r1, 0, 1);
- GEAR_VERT(r1, 0, -1);
-
- u = r2 * vx[1] - r1 * vx[0];
- v = r2 * vy[1] - r1 * vy[0];
- normal[0] = v;
- normal[1] = -u;
- GEAR_VERT(r2, 1, 1);
- GEAR_VERT(r2, 1, -1);
-
- normal[0] = vx[0];
- normal[1] = vy[0];
- GEAR_VERT(r2, 2, 1);
- GEAR_VERT(r2, 2, -1);
-
- u = r1 * vx[3] - r2 * vx[2];
- v = r1 * vy[3] - r2 * vy[2];
- normal[0] = v;
- normal[1] = -u;
- GEAR_VERT(r1, 3, 1);
- GEAR_VERT(r1, 3, -1);
-
- normal[0] = vx[0];
- normal[1] = vy[0];
- GEAR_VERT(r1, 4, 1);
- GEAR_VERT(r1, 4, -1);
-
- /* inside radius cylinder, 4 verts */
- normal[0] = -vx[4];
- normal[1] = -vy[4];
- GEAR_VERT(r0, 4, 1);
- GEAR_VERT(r0, 4, -1);
-
- normal[0] = -vx[0];
- normal[1] = -vy[0];
- GEAR_VERT(r0, 0, 1);
- GEAR_VERT(r0, 0, -1);
-
- assert(count % verts_per_tooth == 0);
- }
- assert(count == total_verts);
-#undef GEAR_VERT
-
- gear->vertices = verts;
-
- /* setup VBO */
- glGenBuffers(1, &gear->vbo);
- if (gear->vbo) {
- glBindBuffer(GL_ARRAY_BUFFER, gear->vbo);
- glBufferData(GL_ARRAY_BUFFER, total_size, verts, GL_STATIC_DRAW);
- }
-}
-
-
-static void
-draw_gear(const struct gear *gear)
-{
- GLint i;
-
- if (!gear->vbo && !gear->vertices) {
- printf("nothing to be drawn\n");
- return;
- }
-
- if (gear->vbo) {
- glBindBuffer(GL_ARRAY_BUFFER, gear->vbo);
- glVertexPointer(3, GL_FLOAT, gear->stride, (const GLvoid *) 0);
- glNormalPointer(GL_FLOAT, gear->stride, (const GLvoid *) (sizeof(GLfloat) * 3));
- } else {
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glVertexPointer(3, GL_FLOAT, gear->stride, gear->vertices);
- glNormalPointer(GL_FLOAT, gear->stride, gear->vertices + 3);
- }
-
- glEnableClientState(GL_VERTEX_ARRAY);
-
- for (i = 0; i < gear->num_teeth; i++) {
- const GLint base = (10 + 4) * i;
- GLushort indices[7];
-
- glShadeModel(GL_FLAT);
-
- /* front face */
- indices[0] = base + 12;
- indices[1] = base + 0;
- indices[2] = base + 2;
- indices[3] = base + 4;
- indices[4] = base + 6;
- indices[5] = base + 8;
- indices[6] = base + 10;
-
- glNormal3f(0.0, 0.0, 1.0);
- glDrawElements(GL_TRIANGLE_FAN, 7, GL_UNSIGNED_SHORT, indices);
-
- /* back face */
- indices[0] = base + 13;
- indices[1] = base + 11;
- indices[2] = base + 9;
- indices[3] = base + 7;
- indices[4] = base + 5;
- indices[5] = base + 3;
- indices[6] = base + 1;
-
- glNormal3f(0.0, 0.0, -1.0);
- glDrawElements(GL_TRIANGLE_FAN, 7, GL_UNSIGNED_SHORT, indices);
-
- glEnableClientState(GL_NORMAL_ARRAY);
-
- /* outward face of a tooth */
- glDrawArrays(GL_TRIANGLE_STRIP, base, 10);
-
- /* inside radius cylinder */
- glShadeModel(GL_SMOOTH);
- glDrawArrays(GL_TRIANGLE_STRIP, base + 10, 4);
-
- glDisableClientState(GL_NORMAL_ARRAY);
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
-}
-
-
-static void
-gears_draw(void)
-{
- static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
- static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
- static const GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1.0, 0.0, 0.0);
- glRotatef(view_roty, 0.0, 1.0, 0.0);
- glRotatef(view_rotz, 0.0, 0.0, 1.0);
-
- glPushMatrix();
- glTranslatef(-3.0, -2.0, 0.0);
- glRotatef(angle, 0.0, 0.0, 1.0);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
- draw_gear(&gears[0]);
-
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(3.1, -2.0, 0.0);
- glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
- draw_gear(&gears[1]);
-
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(-3.1, 4.2, 0.0);
- glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
- draw_gear(&gears[2]);
-
- glPopMatrix();
-
- glPopMatrix();
-}
-
-
-static void gears_fini(void)
-{
- GLint i;
- for (i = 0; i < 3; i++) {
- struct gear *gear = &gears[i];
- if (gear->vbo) {
- glDeleteBuffers(1, &gear->vbo);
- gear->vbo = 0;
- }
- if (gear->vertices) {
- free(gear->vertices);
- gear->vertices = NULL;
- }
- }
-}
-
-
-static void gears_init(void)
-{
- static const GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
-
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glEnable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_NORMALIZE);
-
- init_gear(&gears[0], 1.0, 4.0, 1.0, 20, 0.7);
- init_gear(&gears[1], 0.5, 2.0, 2.0, 10, 0.7);
- init_gear(&gears[2], 1.3, 2.0, 0.5, 10, 0.7);
-}
-
-
-/* new window size or exposure */
-static void
-gears_reshape(int width, int height)
-{
- GLfloat h = (GLfloat) height / (GLfloat) width;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-1.0, 1.0, -h, h, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -40.0);
-}
-
-
-static void
-gears_idle(void)
-{
- static double t0 = -1.;
- double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
- if (t0 < 0.0)
- t0 = t;
- dt = t - t0;
- t0 = t;
-
- angle += 70.0 * dt; /* 70 degrees per second */
- angle = fmod(angle, 360.0); /* prevents eventual overflow */
-
- eglutPostRedisplay();
-}
-
-
-int
-main(int argc, char *argv[])
-{
- eglutInitWindowSize(300, 300);
- eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
- eglutInit(argc, argv);
-
- eglutCreateWindow("gears");
-
- eglutIdleFunc(gears_idle);
- eglutReshapeFunc(gears_reshape);
- eglutDisplayFunc(gears_draw);
-
- gears_init();
-
- eglutMainLoop();
-
- gears_fini();
-
- return 0;
-}
diff --git a/progs/egl/opengles1/msaa.c b/progs/egl/opengles1/msaa.c
deleted file mode 100644
index b4c6c63217..0000000000
--- a/progs/egl/opengles1/msaa.c
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Copyright (C) 2008 Brian Paul 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.
- */
-
-/*
- * Test MSAA with X/EGL and OpenGL ES 1.x
- * Brian Paul
- * 15 September 2008
- */
-
-#define USE_FULL_GL 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>
-
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-static GLboolean AA = 0*GL_TRUE;
-
-
-static void
-draw(void)
-{
- float a;
-
- static const GLfloat verts[4][2] = {
- { -1, -.1 },
- { 1, -.1 },
- { -1, .1 },
- { 1, .1 }
- };
- static const GLfloat colors[4][4] = {
- { 1, 0, 0, 1 },
- { 0, 1, 0, 1 },
- { 0, 0, 1, 1 },
- { 1, 0, 1, 1 }
- };
-
- if (AA) {
- printf("MSAA enabled\n");
- glEnable(GL_MULTISAMPLE);
- }
- else {
- printf("MSAA disabled\n");
- glDisable(GL_MULTISAMPLE);
- }
-
- 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);
-
- for (a = 0; a < 360; a += 20.0) {
- glPushMatrix();
-
- glRotatef(a, 0, 0, 1);
- glTranslatef(1.5, 0, 0);
-
- /* draw triangle */
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glPopMatrix();
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- glPopMatrix();
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ary = 3.0;
- GLfloat arx = ary * (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef GL_VERSION_ES_CM_1_0
- glOrthof(-arx, arx, -ary, ary, -1.0, 1.0);
-#else
- glOrtho(-arx, arx, -ary, ary, -1.0, 1.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-
-static void
-init(void)
-{
- printf("Press 'a' to toggle multisample antialiasing\n");
- printf("Press 'Esc' to exit\n");
-}
-
-
-/*
- * 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_SAMPLES, 1,
- EGL_SAMPLE_BUFFERS, 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);
- }
-
- if (num_configs < 1) {
- printf("Error: Unable to find multisample pixel format.\n");
- printf("Try running glxinfo to see if your server supports MSAA.\n");
- exit(1);
- }
-
- 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)
-{
- 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] == 'a') {
- AA = !AA;
- redraw = 1;
- }
- else if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
-
- if (redraw) {
- draw();
- eglSwapBuffers(egl_dpy, egl_surf);
- }
- }
-}
-
-
-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 = 600, winHeight = 600;
- 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;
- }
- }
-
- 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);
-
- make_x_window(x_dpy, egl_dpy,
- "msaa", 0, 0, winWidth, winHeight,
- &win, &egl_ctx, &egl_surf);
-
- 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);
-
- return 0;
-}
diff --git a/progs/egl/opengles1/pbuffer.c b/progs/egl/opengles1/pbuffer.c
deleted file mode 100644
index 1b4dbb666f..0000000000
--- a/progs/egl/opengles1/pbuffer.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * Test EGL Pbuffers
- * Brian Paul
- * August 2008
- */
-
-
-#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>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-static int WinWidth = 300, WinHeight = 300;
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-
-static void
-Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz)
-{
- n[0] = nx;
- n[1] = ny;
- n[2] = nz;
-}
-
-static void
-Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz)
-{
- v[0] = vx;
- v[1] = vy;
- v[2] = vz;
-}
-
-static void
-Texcoord(GLfloat *v, GLfloat s, GLfloat t)
-{
- v[0] = s;
- v[1] = t;
-}
-
-
-/* Borrowed from glut, adapted */
-static void
-draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings)
-{
- int i, j;
- GLfloat theta, phi, theta1;
- GLfloat cosTheta, sinTheta;
- GLfloat cosTheta1, sinTheta1;
- GLfloat ringDelta, sideDelta;
- GLfloat varray[100][3], narray[100][3], tarray[100][2];
- int vcount;
-
- glVertexPointer(3, GL_FLOAT, 0, varray);
- glNormalPointer(GL_FLOAT, 0, narray);
- glTexCoordPointer(2, GL_FLOAT, 0, tarray);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- ringDelta = 2.0 * M_PI / rings;
- sideDelta = 2.0 * M_PI / nsides;
-
- theta = 0.0;
- cosTheta = 1.0;
- sinTheta = 0.0;
- for (i = rings - 1; i >= 0; i--) {
- theta1 = theta + ringDelta;
- cosTheta1 = cos(theta1);
- sinTheta1 = sin(theta1);
-
- vcount = 0; /* glBegin(GL_QUAD_STRIP); */
-
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- GLfloat s0, s1, t;
- GLfloat cosPhi, sinPhi, dist;
-
- phi += sideDelta;
- cosPhi = cos(phi);
- sinPhi = sin(phi);
- dist = R + r * cosPhi;
-
- s0 = 20.0 * theta / (2.0 * M_PI);
- s1 = 20.0 * theta1 / (2.0 * M_PI);
- t = 8.0 * phi / (2.0 * M_PI);
-
- Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s1, t);
- Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
- vcount++;
-
- Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s0, t);
- Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi);
- vcount++;
- }
-
- /*glEnd();*/
- assert(vcount <= 100);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount);
-
- theta = theta1;
- cosTheta = cosTheta1;
- sinTheta = sinTheta1;
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-
-static void
-draw(void)
-{
- 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);
- glScalef(0.5, 0.5, 0.5);
-
- draw_torus(1.0, 3.0, 30, 60);
-
- glPopMatrix();
-
- glFinish();
-}
-
-
-/**
- * Draw to both the window and pbuffer and compare results.
- */
-static void
-draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
- EGLContext egl_ctx)
-{
- unsigned *wbuf, *pbuf;
- int x = 100, y = 110;
- int i, dif;
-
- wbuf = (unsigned *) malloc(WinWidth * WinHeight * 4);
- pbuf = (unsigned *) malloc(WinWidth * WinHeight * 4);
-
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
-
- /* first draw to window */
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent(window) failed\n");
- return;
- }
- draw();
- glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, wbuf);
- printf("Window[%d,%d] = 0x%08x\n", x, y, wbuf[y*WinWidth+x]);
-
- eglSwapBuffers(egl_dpy, egl_surf);
-
- /* then draw to pbuffer */
- if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) {
- printf("Error: eglMakeCurrent(pbuffer) failed\n");
- return;
- }
- draw();
- glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, pbuf);
- printf("Pbuffer[%d,%d] = 0x%08x\n", x, y, pbuf[y*WinWidth+x]);
-
-
- /* compare renderings */
- for (dif = i = 0; i < WinWidth * WinHeight; i++) {
- if (wbuf[i] != pbuf[i]) {
- dif = 1;
- break;
- }
- }
-
- if (dif)
- printf("Difference at %d: 0x%08x vs. 0x%08x\n", i, wbuf[i], pbuf[i]);
- else
- printf("Window rendering matches Pbuffer rendering!\n");
-
- free(wbuf);
- free(pbuf);
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- WinWidth = width;
- WinHeight = height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
-#ifdef GL_VERSION_ES_CM_1_0
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-#else
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -15.0);
-}
-
-
-static void
-make_texture(void)
-{
-#define SZ 64
- GLenum Filter = GL_LINEAR;
- GLubyte image[SZ][SZ][4];
- GLuint i, j;
-
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
- GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
- d = sqrt(d);
- if (d < SZ/3) {
- image[i][j][0] = 255;
- image[i][j][1] = 255;
- image[i][j][2] = 255;
- image[i][j][3] = 255;
- }
- else {
- image[i][j][0] = 127;
- image[i][j][1] = 127;
- image[i][j][2] = 127;
- image[i][j][3] = 255;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0); /* unit 0 */
- glBindTexture(GL_TEXTURE_2D, 42);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-#undef SZ
-}
-
-
-
-static void
-init(void)
-{
- static const GLfloat red[4] = {1, 0, 0, 0};
- static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
- static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
- static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
- static const GLfloat pos[4] = {20, 20, 50, 1};
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
-
- glClearColor(0.4, 0.4, 0.4, 0.0);
- glEnable(GL_DEPTH_TEST);
-
- make_texture();
- glEnable(GL_TEXTURE_2D);
-}
-
-
-/*
- * 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);
- }
-
- eglBindAPI(EGL_OPENGL_ES_API);
-
- 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 EGLSurface
-make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height)
-{
- static const EGLint config_attribs[] = {
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_DEPTH_SIZE, 1,
- EGL_NONE
- };
- EGLConfig config;
- EGLSurface pbuf;
- EGLint num_configs;
- EGLint pbuf_attribs[5];
-
- pbuf_attribs[0] = EGL_WIDTH;
- pbuf_attribs[1] = width;
- pbuf_attribs[2] = EGL_HEIGHT;
- pbuf_attribs[3] = height;
- pbuf_attribs[4] = EGL_NONE;
-
- if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) {
- printf("Error: couldn't get an EGL config for pbuffer\n");
- exit(1);
- }
-
- pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs);
-
- return pbuf;
-}
-
-
-static void
-event_loop(Display *dpy, Window win,
- EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
- EGLContext egl_ctx)
-{
- int anim = 0;
-
- while (1) {
- int redraw = 0;
-
- if (!anim || XPending(dpy)) {
- XEvent event;
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- if (event.xconfigure.window == win)
- 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] == ' ') {
- anim = !anim;
- }
- else if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
- }
-
- if (anim) {
- view_rotx += 1.0;
- view_roty += 2.0;
- redraw = 1;
- }
-
- if (redraw) {
- draw_both(egl_dpy, egl_surf, egl_pbuf, egl_ctx);
- }
- }
-}
-
-
-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[])
-{
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf, egl_pbuf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- GLboolean printInfo = GL_FALSE;
- EGLint egl_major, egl_minor;
- int i;
- const char *s;
-
- 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;
- }
- }
-
- 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);
-
- make_x_window(x_dpy, egl_dpy,
- "pbuffer", 0, 0, WinWidth, WinHeight,
- &win, &egl_ctx, &egl_surf);
-
- egl_pbuf = make_pbuffer(x_dpy, egl_dpy, WinWidth, WinHeight);
- if (!egl_pbuf) {
- printf("Error: eglCreatePBufferSurface() failed\n");
- return -1;
- }
-
- XMapWindow(x_dpy, win);
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent() failed\n");
- return -1;
- }
-
- 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));
- }
-
- 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, egl_pbuf, egl_ctx);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/egl/opengles1/render_tex.c b/progs/egl/opengles1/render_tex.c
deleted file mode 100644
index cd2abbd51b..0000000000
--- a/progs/egl/opengles1/render_tex.c
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * Test EGL render to texture.
- * Brian Paul
- * August 2008
- */
-
-
-#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>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-static int TexWidth = 256, TexHeight = 256;
-
-static int WinWidth = 300, WinHeight = 300;
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-static GLuint DotTexture, RenderTexture;
-
-
-static void
-Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz)
-{
- n[0] = nx;
- n[1] = ny;
- n[2] = nz;
-}
-
-static void
-Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz)
-{
- v[0] = vx;
- v[1] = vy;
- v[2] = vz;
-}
-
-static void
-Texcoord(GLfloat *v, GLfloat s, GLfloat t)
-{
- v[0] = s;
- v[1] = t;
-}
-
-
-/* Borrowed from glut, adapted */
-static void
-draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings)
-{
- int i, j;
- GLfloat theta, phi, theta1;
- GLfloat cosTheta, sinTheta;
- GLfloat cosTheta1, sinTheta1;
- GLfloat ringDelta, sideDelta;
- GLfloat varray[100][3], narray[100][3], tarray[100][2];
- int vcount;
-
- glVertexPointer(3, GL_FLOAT, 0, varray);
- glNormalPointer(GL_FLOAT, 0, narray);
- glTexCoordPointer(2, GL_FLOAT, 0, tarray);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- ringDelta = 2.0 * M_PI / rings;
- sideDelta = 2.0 * M_PI / nsides;
-
- theta = 0.0;
- cosTheta = 1.0;
- sinTheta = 0.0;
- for (i = rings - 1; i >= 0; i--) {
- theta1 = theta + ringDelta;
- cosTheta1 = cos(theta1);
- sinTheta1 = sin(theta1);
-
- vcount = 0; /* glBegin(GL_QUAD_STRIP); */
-
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- GLfloat s0, s1, t;
- GLfloat cosPhi, sinPhi, dist;
-
- phi += sideDelta;
- cosPhi = cos(phi);
- sinPhi = sin(phi);
- dist = R + r * cosPhi;
-
- s0 = 20.0 * theta / (2.0 * M_PI);
- s1 = 20.0 * theta1 / (2.0 * M_PI);
- t = 8.0 * phi / (2.0 * M_PI);
-
- Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s1, t);
- Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
- vcount++;
-
- Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s0, t);
- Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi);
- vcount++;
- }
-
- /*glEnd();*/
- assert(vcount <= 100);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount);
-
- theta = theta1;
- cosTheta = cosTheta1;
- sinTheta = sinTheta1;
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-
-static void
-draw_torus_to_texture(void)
-{
- glViewport(0, 0, TexWidth, TexHeight);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-1, 1, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -15.0);
-
- glClearColor(0.4, 0.4, 0.4, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glBindTexture(GL_TEXTURE_2D, DotTexture);
-
- glEnable(GL_LIGHTING);
-
- glPushMatrix();
- glRotatef(view_roty, 0, 1, 0);
- glScalef(0.5, 0.5, 0.5);
-
- draw_torus(1.0, 3.0, 30, 60);
-
- glPopMatrix();
-
- glDisable(GL_LIGHTING);
-
-#if 0
- glBindTexture(GL_TEXTURE_2D, RenderTexture);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight);
-#endif
-
- glFinish();
-}
-
-
-static void
-draw_textured_quad(void)
-{
- GLfloat ar = (GLfloat) WinWidth / (GLfloat) WinHeight;
-
- glViewport(0, 0, WinWidth, WinHeight);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -8.0);
-
- glClearColor(0.4, 0.4, 1.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glBindTexture(GL_TEXTURE_2D, RenderTexture);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- {
- static const GLfloat texcoord[4][2] = {
- { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 }
- };
- static const GLfloat vertex[4][2] = {
- { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 }
- };
-
- glVertexPointer(2, GL_FLOAT, 0, vertex);
- glTexCoordPointer(2, GL_FLOAT, 0, texcoord);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
-
- glPopMatrix();
-}
-
-
-
-static void
-draw(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
- EGLContext egl_ctx)
-{
- /*printf("Begin draw\n");*/
-
- /* first draw torus to pbuffer /texture */
-#if 01
- if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) {
-#else
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
-#endif
- printf("Error: eglMakeCurrent(pbuf) failed\n");
- return;
- }
- draw_torus_to_texture();
-
- /* draw textured quad to window */
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent(pbuffer) failed\n");
- return;
- }
-
- glBindTexture(GL_TEXTURE_2D, RenderTexture);
- eglBindTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER);
- draw_textured_quad();
- eglReleaseTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER);
-
- eglSwapBuffers(egl_dpy, egl_surf);
-
- /*printf("End draw\n");*/
-}
-
-
-
-static void
-make_dot_texture(void)
-{
-#define SZ 64
- GLenum Filter = GL_LINEAR;
- GLubyte image[SZ][SZ][4];
- GLuint i, j;
-
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
- GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
- d = sqrt(d);
- if (d < SZ/3) {
- image[i][j][0] = 255;
- image[i][j][1] = 255;
- image[i][j][2] = 255;
- image[i][j][3] = 255;
- }
- else {
- image[i][j][0] = 127;
- image[i][j][1] = 127;
- image[i][j][2] = 127;
- image[i][j][3] = 255;
- }
- }
- }
-
- glGenTextures(1, &DotTexture);
- glBindTexture(GL_TEXTURE_2D, DotTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-#undef SZ
-}
-
-
-static void
-make_render_texture(void)
-{
- GLenum Filter = GL_LINEAR;
- glGenTextures(1, &RenderTexture);
- glBindTexture(GL_TEXTURE_2D, RenderTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-}
-
-
-static void
-init(void)
-{
- static const GLfloat red[4] = {1, 0, 0, 0};
- static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
- static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
- static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
- static const GLfloat pos[4] = {20, 20, 50, 1};
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);
-
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
-
- glEnable(GL_DEPTH_TEST);
-
- make_dot_texture();
- make_render_texture();
-
- printf("DotTexture=%u RenderTexture=%u\n", DotTexture, RenderTexture);
-
- glEnable(GL_TEXTURE_2D);
-}
-
-
-/*
- * 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);
- }
-
- eglBindAPI(EGL_OPENGL_ES_API);
-
- 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 EGLSurface
-make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height)
-{
- static const EGLint config_attribs[] = {
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_DEPTH_SIZE, 1,
- EGL_NONE
- };
- EGLConfig config;
- EGLSurface pbuf;
- EGLint num_configs;
- EGLint pbuf_attribs[15];
- int i = 0;
-
- pbuf_attribs[i++] = EGL_WIDTH;
- pbuf_attribs[i++] = width;
- pbuf_attribs[i++] = EGL_HEIGHT;
- pbuf_attribs[i++] = height;
- pbuf_attribs[i++] = EGL_TEXTURE_FORMAT;
- pbuf_attribs[i++] = EGL_TEXTURE_RGBA;
- pbuf_attribs[i++] = EGL_TEXTURE_TARGET;
- pbuf_attribs[i++] = EGL_TEXTURE_2D;
- pbuf_attribs[i++] = EGL_MIPMAP_TEXTURE;
- pbuf_attribs[i++] = EGL_FALSE;
- pbuf_attribs[i++] = EGL_NONE;
- assert(i <= 15);
-
- if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) {
- printf("Error: couldn't get an EGL config for pbuffer\n");
- exit(1);
- }
-
- pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs);
-
- return pbuf;
-}
-
-
-static void
-event_loop(Display *dpy, Window win,
- EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
- EGLContext egl_ctx)
-{
- int anim = 0;
-
- while (1) {
- int redraw = 0;
-
- if (!anim || XPending(dpy)) {
- XEvent event;
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- if (event.xconfigure.window == win) {
- WinWidth = event.xconfigure.width;
- WinHeight = 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] == ' ') {
- anim = !anim;
- }
- else if (buffer[0] == 'z') {
- view_rotz += 5.0;
- }
- else if (buffer[0] == 'Z') {
- view_rotz -= 5.0;
- }
- else if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
- }
-
- if (anim) {
- view_rotx += 1.0;
- view_roty += 2.0;
- redraw = 1;
- }
-
- if (redraw) {
- draw(egl_dpy, egl_surf, egl_pbuf, egl_ctx);
- }
- }
-}
-
-
-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[])
-{
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf, egl_pbuf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- GLboolean printInfo = GL_FALSE;
- EGLint egl_major, egl_minor;
- int i;
- const char *s;
-
- 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;
- }
- }
-
- 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);
-
- make_x_window(x_dpy, egl_dpy,
- "render_tex", 0, 0, WinWidth, WinHeight,
- &win, &egl_ctx, &egl_surf);
-
- egl_pbuf = make_pbuffer(x_dpy, egl_dpy, TexWidth, TexHeight);
- if (!egl_pbuf) {
- printf("Error: eglCreatePBufferSurface() failed\n");
- return -1;
- }
-
- XMapWindow(x_dpy, win);
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent() failed\n");
- return -1;
- }
-
- 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));
- }
-
- init();
-
- event_loop(x_dpy, win, egl_dpy, egl_surf, egl_pbuf, egl_ctx);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/egl/opengles1/texture_from_pixmap.c b/progs/egl/opengles1/texture_from_pixmap.c
deleted file mode 100644
index 8e7e803d78..0000000000
--- a/progs/egl/opengles1/texture_from_pixmap.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.9
- *
- * Copyright (C) 2010 LunarG Inc.
- *
- * 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
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- *
- * Authors:
- * Chia-I Wu <olv@lunarg.com>
- */
-
-/*
- * This demo uses EGL_KHR_image_pixmap and GL_OES_EGL_image to demonstrate
- * texture-from-pixmap.
- */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h> /* for usleep */
-#include <sys/time.h> /* for gettimeofday */
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-struct app_data {
- /* native */
- Display *xdpy;
- Window canvas, cube;
- Pixmap pix;
- unsigned int width, height, depth;
- GC fg, bg;
-
- /* EGL */
- EGLDisplay dpy;
- EGLContext ctx;
- EGLSurface surf;
- EGLImageKHR img;
-
- /* OpenGL ES */
- GLuint texture;
-
- PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
- PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
- PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
-
- /* app state */
- Bool loop;
- Bool redraw, reshape;
-
- struct {
- Bool active;
- unsigned long next_frame; /* in ms */
- float view_rotx;
- float view_roty;
- float view_rotz;
-
- } animate;
-
- struct {
- Bool active;
- int x1, y1;
- int x2, y2;
- } paint;
-};
-
-static void
-gl_redraw(void)
-{
- const GLfloat verts[4][2] = {
- { -1, -1 },
- { 1, -1 },
- { 1, 1 },
- { -1, 1 }
- };
- const GLfloat texcoords[4][2] = {
- { 0, 1 },
- { 1, 1 },
- { 1, 0 },
- { 0, 0 }
- };
- const GLfloat faces[6][4] = {
- { 0, 0, 1, 0 },
- { 90, 0, 1, 0 },
- { 180, 0, 1, 0 },
- { 270, 0, 1, 0 },
- { 90, 1, 0, 0 },
- { -90, 1, 0, 0 }
- };
- GLint i;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- for (i = 0; i < 6; i++) {
- glPushMatrix();
- glRotatef(faces[i][0], faces[i][1], faces[i][2], faces[i][3]);
- glTranslatef(0, 0, 1.0);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- glPopMatrix();
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-static void
-gl_reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, width, 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
-app_redraw(struct app_data *data)
-{
- /* pixmap has changed */
- if (data->reshape || data->paint.active) {
- eglWaitNative(EGL_CORE_NATIVE_ENGINE);
-
- if (data->reshape) {
- data->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
- (GLeglImageOES) data->img);
- }
- }
-
- XCopyArea(data->xdpy, data->pix, data->canvas, data->fg,
- 0, 0, data->width, data->height, 0, 0);
-
- glPushMatrix();
- glRotatef(data->animate.view_rotx, 1, 0, 0);
- glRotatef(data->animate.view_roty, 0, 1, 0);
- glRotatef(data->animate.view_rotz, 0, 0, 1);
- gl_redraw();
- glPopMatrix();
-
- eglSwapBuffers(data->dpy, data->surf);
-}
-
-static void
-app_reshape(struct app_data *data)
-{
- const EGLint img_attribs[] = {
- EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
- EGL_NONE
- };
-
- XResizeWindow(data->xdpy, data->cube, data->width, data->height);
- XMoveWindow(data->xdpy, data->cube, data->width, 0);
-
- if (data->img)
- data->eglDestroyImageKHR(data->dpy, data->img);
- if (data->pix)
- XFreePixmap(data->xdpy, data->pix);
-
- data->pix = XCreatePixmap(data->xdpy, data->canvas, data->width, data->height, data->depth);
- XFillRectangle(data->xdpy, data->pix, data->bg, 0, 0, data->width, data->height);
-
- data->img = data->eglCreateImageKHR(data->dpy, EGL_NO_CONTEXT,
- EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer) data->pix, img_attribs);
-
- gl_reshape(data->width, data->height);
-}
-
-static void
-app_toggle_animate(struct app_data *data)
-{
- data->animate.active = !data->animate.active;
-
- if (data->animate.active) {
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- data->animate.next_frame = tv.tv_sec * 1000 + tv.tv_usec / 1000;
- }
-}
-
-static void
-app_next_event(struct app_data *data)
-{
- XEvent event;
-
- data->reshape = False;
- data->redraw = False;
- data->paint.active = False;
-
- if (data->animate.active) {
- struct timeval tv;
- unsigned long now;
-
- gettimeofday(&tv, NULL);
- now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
-
- /* wait for next frame */
- if (!XPending(data->xdpy) && now < data->animate.next_frame) {
- usleep((data->animate.next_frame - now) * 1000);
- gettimeofday(&tv, NULL);
- now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
- }
-
- while (now >= data->animate.next_frame) {
- data->animate.view_rotx += 1.0;
- data->animate.view_roty += 2.0;
- data->animate.view_rotz += 1.5;
-
- /* 30fps */
- data->animate.next_frame += 1000 / 30;
- }
-
- /* check again in case there were events when sleeping */
- if (!XPending(data->xdpy)) {
- data->redraw = True;
- return;
- }
- }
-
- XNextEvent(data->xdpy, &event);
-
- switch (event.type) {
- case ConfigureNotify:
- data->width = event.xconfigure.width / 2;
- data->height = event.xconfigure.height;
- data->reshape = True;
- break;
- case Expose:
- data->redraw = True;
- break;
- case KeyPress:
- {
- int code;
-
- code = XLookupKeysym(&event.xkey, 0);
- switch (code) {
- case XK_a:
- app_toggle_animate(data);
- break;
- case XK_Escape:
- data->loop = False;
- break;
- default:
- break;
- }
- }
- break;
- case ButtonPress:
- data->paint.x1 = data->paint.x2 = event.xbutton.x;
- data->paint.y1 = data->paint.y2 = event.xbutton.y;
- break;
- case ButtonRelease:
- data->paint.active = False;
- break;
- case MotionNotify:
- data->paint.x1 = data->paint.x2;
- data->paint.y1 = data->paint.y2;
- data->paint.x2 = event.xmotion.x;
- data->paint.y2 = event.xmotion.y;
- data->paint.active = True;
- break;
- default:
- break;
- }
-
- if (data->paint.active || data->reshape)
- data->redraw = True;
-}
-
-static void
-app_init_gl(struct app_data *data)
-{
- glClearColor(0.1, 0.1, 0.3, 0.0);
- glColor4f(1.0, 1.0, 1.0, 1.0);
-
- glGenTextures(1, &data->texture);
-
- glBindTexture(GL_TEXTURE_2D, data->texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-}
-
-static Bool
-app_init_exts(struct app_data *data)
-{
- const char *exts;
-
- exts = eglQueryString(data->dpy, EGL_EXTENSIONS);
- data->eglCreateImageKHR =
- (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
- data->eglDestroyImageKHR =
- (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
- if (!exts || !strstr(exts, "EGL_KHR_image_pixmap") ||
- !data->eglCreateImageKHR || !data->eglDestroyImageKHR) {
- printf("EGL does not support EGL_KHR_image_pixmap\n");
- return False;
- }
-
- exts = (const char *) glGetString(GL_EXTENSIONS);
- data->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
- eglGetProcAddress("glEGLImageTargetTexture2DOES");
- if (!exts || !strstr(exts, "GL_OES_EGL_image") ||
- !data->glEGLImageTargetTexture2DOES) {
- printf("OpenGL ES does not support GL_OES_EGL_image\n");
- return False;
- }
-
- return True;
-}
-
-static void
-app_run(struct app_data *data)
-{
- Window root;
- int x, y;
- unsigned int border;
-
- if (!eglMakeCurrent(data->dpy, data->surf, data->surf, data->ctx))
- return;
-
- if (!app_init_exts(data))
- return;
-
- printf("Draw something on the left with the mouse!\n");
-
- app_init_gl(data);
-
- if (!XGetGeometry(data->xdpy, data->canvas, &root, &x, &y,
- &data->width, &data->height, &border, &data->depth))
- return;
- data->width /= 2;
-
- app_reshape(data);
-
- XMapWindow(data->xdpy, data->canvas);
- XMapWindow(data->xdpy, data->cube);
-
- app_toggle_animate(data);
- data->loop = True;
-
- while (data->loop) {
- app_next_event(data);
-
- if (data->reshape)
- app_reshape(data);
- if (data->paint.active) {
- XDrawLine(data->xdpy, data->pix, data->fg,
- data->paint.x1, data->paint.y1,
- data->paint.x2, data->paint.y2);
- }
-
- if (data->redraw)
- app_redraw(data);
- }
-
- eglMakeCurrent(data->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-}
-
-static Bool
-make_x_window(struct app_data *data, const char *name,
- int x, int y, int width, int height)
-{
- static const EGLint attribs[] = {
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_DEPTH_SIZE, 1,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
- EGL_NONE
- };
- static const EGLint ctx_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 1,
- EGL_NONE
- };
- int scrnum;
- XSetWindowAttributes attr;
- unsigned long mask;
- Window root;
- Window win;
- XVisualInfo *visInfo, visTemplate;
- int num_visuals;
- EGLConfig config;
- EGLint num_configs;
- EGLint vid;
-
- scrnum = DefaultScreen( data->xdpy );
- root = RootWindow( data->xdpy, scrnum );
-
- if (!eglChooseConfig( data->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(data->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(data->xdpy, 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( data->xdpy, root, visInfo->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask |
- KeyPressMask | ButtonPressMask | ButtonMotionMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-
- win = XCreateWindow( data->xdpy, root, 0, 0, width * 2, 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(data->xdpy, win, &sizehints);
- XSetStandardProperties(data->xdpy, win, name, name,
- None, (char **)NULL, 0, &sizehints);
- }
-
- data->canvas = win;
-
- attr.event_mask = 0x0;
- win = XCreateWindow( data->xdpy, win, width, 0, width, height,
- 0, visInfo->depth, InputOutput,
- visInfo->visual, mask, &attr );
- data->cube = win;
-
- eglBindAPI(EGL_OPENGL_ES_API);
-
- data->ctx = eglCreateContext(data->dpy, config, EGL_NO_CONTEXT, ctx_attribs );
- if (!data->ctx) {
- printf("Error: eglCreateContext failed\n");
- exit(1);
- }
-
- data->surf = eglCreateWindowSurface(data->dpy, config, data->cube, NULL);
- if (!data->surf) {
- printf("Error: eglCreateWindowSurface failed\n");
- exit(1);
- }
-
- XFree(visInfo);
-
- return (data->canvas && data->cube && data->ctx && data->surf);
-}
-
-static void
-app_fini(struct app_data *data)
-{
- if (data->img)
- data->eglDestroyImageKHR(data->dpy, data->img);
- if (data->pix)
- XFreePixmap(data->xdpy, data->pix);
-
- if (data->fg)
- XFreeGC(data->xdpy, data->fg);
- if (data->bg)
- XFreeGC(data->xdpy, data->bg);
-
- if (data->surf)
- eglDestroySurface(data->dpy, data->surf);
- if (data->ctx)
- eglDestroyContext(data->dpy, data->ctx);
-
- if (data->cube)
- XDestroyWindow(data->xdpy, data->cube);
- if (data->canvas)
- XDestroyWindow(data->xdpy, data->canvas);
-
- if (data->dpy)
- eglTerminate(data->dpy);
- if (data->xdpy)
- XCloseDisplay(data->xdpy);
-}
-
-static Bool
-app_init(struct app_data *data, int argc, char **argv)
-{
- XGCValues gc_vals;
-
- memset(data, 0, sizeof(*data));
-
- data->xdpy = XOpenDisplay(NULL);
- if (!data->xdpy)
- goto fail;
-
- data->dpy = eglGetDisplay(data->xdpy);
- if (!data->dpy || !eglInitialize(data->dpy, NULL, NULL))
- goto fail;
-
- if (!make_x_window(data, "EGLImage TFP", 0, 0, 300, 300))
- goto fail;
-
- gc_vals.function = GXcopy;
- gc_vals.foreground = WhitePixel(data->xdpy, DefaultScreen(data->xdpy));
- gc_vals.line_width = 3;
- gc_vals.line_style = LineSolid;
- gc_vals.fill_style = FillSolid;
-
- data->fg = XCreateGC(data->xdpy, data->canvas,
- GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle,
- &gc_vals);
- gc_vals.foreground = BlackPixel(data->xdpy, DefaultScreen(data->xdpy));
- data->bg = XCreateGC(data->xdpy, data->canvas,
- GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle,
- &gc_vals);
- if (!data->fg || !data->bg)
- goto fail;
-
- return True;
-
-fail:
- app_fini(data);
- return False;
-}
-
-int
-main(int argc, char **argv)
-{
- struct app_data data;
-
- if (app_init(&data, argc, argv)) {
- app_run(&data);
- app_fini(&data);
- }
-
- return 0;
-}
diff --git a/progs/egl/opengles1/torus.c b/progs/egl/opengles1/torus.c
deleted file mode 100644
index 18ddff3fe4..0000000000
--- a/progs/egl/opengles1/torus.c
+++ /dev/null
@@ -1,452 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * Draw a lit, textured torus with X/EGL and OpenGL ES 1.x
- * Brian Paul
- * July 2008
- */
-
-
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <GLES/gl.h>
-
-#include "eglut.h"
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-static const struct {
- GLenum internalFormat;
- const char *name;
- GLuint num_entries;
- GLuint size;
-} cpal_formats[] = {
- { GL_PALETTE4_RGB8_OES, "GL_PALETTE4_RGB8_OES", 16, 3 },
- { GL_PALETTE4_RGBA8_OES, "GL_PALETTE4_RGBA8_OES", 16, 4 },
- { GL_PALETTE4_R5_G6_B5_OES, "GL_PALETTE4_R5_G6_B5_OES", 16, 2 },
- { GL_PALETTE4_RGBA4_OES, "GL_PALETTE4_RGBA4_OES", 16, 2 },
- { GL_PALETTE4_RGB5_A1_OES, "GL_PALETTE4_RGB5_A1_OES", 16, 2 },
- { GL_PALETTE8_RGB8_OES, "GL_PALETTE8_RGB8_OES", 256, 3 },
- { GL_PALETTE8_RGBA8_OES, "GL_PALETTE8_RGBA8_OES", 256, 4 },
- { GL_PALETTE8_R5_G6_B5_OES, "GL_PALETTE8_R5_G6_B5_OES", 256, 2 },
- { GL_PALETTE8_RGBA4_OES, "GL_PALETTE8_RGBA4_OES", 256, 2 },
- { GL_PALETTE8_RGB5_A1_OES, "GL_PALETTE8_RGB5_A1_OES", 256, 2 }
-};
-#define NUM_CPAL_FORMATS (sizeof(cpal_formats) / sizeof(cpal_formats[0]))
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-static GLint tex_format = NUM_CPAL_FORMATS;
-static GLboolean animate = GL_TRUE;
-static int win;
-
-
-static void
-Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz)
-{
- n[0] = nx;
- n[1] = ny;
- n[2] = nz;
-}
-
-static void
-Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz)
-{
- v[0] = vx;
- v[1] = vy;
- v[2] = vz;
-}
-
-static void
-Texcoord(GLfloat *v, GLfloat s, GLfloat t)
-{
- v[0] = s;
- v[1] = t;
-}
-
-
-/* Borrowed from glut, adapted */
-static void
-draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings)
-{
- int i, j;
- GLfloat theta, phi, theta1;
- GLfloat cosTheta, sinTheta;
- GLfloat cosTheta1, sinTheta1;
- GLfloat ringDelta, sideDelta;
- GLfloat varray[100][3], narray[100][3], tarray[100][2];
- int vcount;
-
- glVertexPointer(3, GL_FLOAT, 0, varray);
- glNormalPointer(GL_FLOAT, 0, narray);
- glTexCoordPointer(2, GL_FLOAT, 0, tarray);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- ringDelta = 2.0 * M_PI / rings;
- sideDelta = 2.0 * M_PI / nsides;
-
- theta = 0.0;
- cosTheta = 1.0;
- sinTheta = 0.0;
- for (i = rings - 1; i >= 0; i--) {
- theta1 = theta + ringDelta;
- cosTheta1 = cos(theta1);
- sinTheta1 = sin(theta1);
-
- vcount = 0; /* glBegin(GL_QUAD_STRIP); */
-
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- GLfloat s0, s1, t;
- GLfloat cosPhi, sinPhi, dist;
-
- phi += sideDelta;
- cosPhi = cos(phi);
- sinPhi = sin(phi);
- dist = R + r * cosPhi;
-
- s0 = 20.0 * theta / (2.0 * M_PI);
- s1 = 20.0 * theta1 / (2.0 * M_PI);
- t = 8.0 * phi / (2.0 * M_PI);
-
- Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s1, t);
- Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
- vcount++;
-
- Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
- Texcoord(tarray[vcount], s0, t);
- Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi);
- vcount++;
- }
-
- /*glEnd();*/
- assert(vcount <= 100);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount);
-
- theta = theta1;
- cosTheta = cosTheta1;
- sinTheta = sinTheta1;
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-
-static void
-draw(void)
-{
- 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);
- glScalef(0.5, 0.5, 0.5);
-
- draw_torus(1.0, 3.0, 30, 60);
-
- glPopMatrix();
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
-#ifdef GL_VERSION_ES_CM_1_0
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-#else
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -15.0);
-}
-
-
-static GLint
-make_cpal_texture(GLint idx)
-{
-#define SZ 64
- GLenum internalFormat = GL_PALETTE4_RGB8_OES + idx;
- GLenum Filter = GL_LINEAR;
- GLubyte palette[256 * 4 + SZ * SZ];
- GLubyte *indices;
- GLsizei image_size;
- GLuint i, j;
- GLuint packed_indices = 0;
-
- assert(cpal_formats[idx].internalFormat == internalFormat);
-
- /* init palette */
- switch (internalFormat) {
- case GL_PALETTE4_RGB8_OES:
- case GL_PALETTE8_RGB8_OES:
- /* first entry */
- palette[0] = 255;
- palette[1] = 255;
- palette[2] = 255;
- /* second entry */
- palette[3] = 127;
- palette[4] = 127;
- palette[5] = 127;
- break;
- case GL_PALETTE4_RGBA8_OES:
- case GL_PALETTE8_RGBA8_OES:
- /* first entry */
- palette[0] = 255;
- palette[1] = 255;
- palette[2] = 255;
- palette[3] = 255;
- /* second entry */
- palette[4] = 127;
- palette[5] = 127;
- palette[6] = 127;
- palette[7] = 255;
- break;
- case GL_PALETTE4_R5_G6_B5_OES:
- case GL_PALETTE8_R5_G6_B5_OES:
- {
- GLushort *pal = (GLushort *) palette;
- /* first entry */
- pal[0] = (31 << 11 | 63 << 5 | 31);
- /* second entry */
- pal[1] = (15 << 11 | 31 << 5 | 15);
- }
- break;
- case GL_PALETTE4_RGBA4_OES:
- case GL_PALETTE8_RGBA4_OES:
- {
- GLushort *pal = (GLushort *) palette;
- /* first entry */
- pal[0] = (15 << 12 | 15 << 8 | 15 << 4 | 15);
- /* second entry */
- pal[1] = (7 << 12 | 7 << 8 | 7 << 4 | 15);
- }
- break;
- case GL_PALETTE4_RGB5_A1_OES:
- case GL_PALETTE8_RGB5_A1_OES:
- {
- GLushort *pal = (GLushort *) palette;
- /* first entry */
- pal[0] = (31 << 11 | 31 << 6 | 31 << 1 | 1);
- /* second entry */
- pal[1] = (15 << 11 | 15 << 6 | 15 << 1 | 1);
- }
- break;
- }
-
- image_size = cpal_formats[idx].size * cpal_formats[idx].num_entries;
- indices = palette + image_size;
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
- GLfloat d;
- GLint index;
- d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
- d = sqrt(d);
- index = (d < SZ / 3) ? 0 : 1;
-
- if (cpal_formats[idx].num_entries == 16) {
- /* 4-bit indices packed in GLubyte */
- packed_indices |= index << (4 * (1 - (j % 2)));
- if (j % 2) {
- *(indices + (i * SZ + j - 1) / 2) = packed_indices & 0xff;
- packed_indices = 0;
- image_size += 1;
- }
- }
- else {
- /* 8-bit indices */
- *(indices + i * SZ + j) = index;
- image_size += 1;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0); /* unit 0 */
- glBindTexture(GL_TEXTURE_2D, 42);
- glCompressedTexImage2D(GL_TEXTURE_2D, 0, internalFormat, SZ, SZ, 0,
- image_size, palette);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-#undef SZ
-
- return image_size;
-}
-
-
-static GLint
-make_texture(void)
-{
-#define SZ 64
- GLenum Filter = GL_LINEAR;
- GLubyte image[SZ][SZ][4];
- GLuint i, j;
-
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
- GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
- d = sqrt(d);
- if (d < SZ/3) {
- image[i][j][0] = 255;
- image[i][j][1] = 255;
- image[i][j][2] = 255;
- image[i][j][3] = 255;
- }
- else {
- image[i][j][0] = 127;
- image[i][j][1] = 127;
- image[i][j][2] = 127;
- image[i][j][3] = 255;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0); /* unit 0 */
- glBindTexture(GL_TEXTURE_2D, 42);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-#undef SZ
-
- return sizeof(image);
-}
-
-
-
-static void
-init(void)
-{
- static const GLfloat red[4] = {1, 0, 0, 0};
- static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
- static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
- static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
- static const GLfloat pos[4] = {20, 20, 50, 1};
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
-
- glClearColor(0.4, 0.4, 0.4, 0.0);
- glEnable(GL_DEPTH_TEST);
-
- make_texture();
- glEnable(GL_TEXTURE_2D);
-}
-
-
-static void
-idle(void)
-{
- if (animate) {
- view_rotx += 1.0;
- view_roty += 2.0;
- eglutPostRedisplay();
- }
-}
-
-static void
-key(unsigned char key)
-{
- switch (key) {
- case ' ':
- animate = !animate;
- break;
- case 't':
- {
- GLint size;
- tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1);
- if (tex_format < NUM_CPAL_FORMATS) {
- size = make_cpal_texture(tex_format);
- printf("Using %s (%d bytes)\n",
- cpal_formats[tex_format].name, size);
- }
- else {
- size = make_texture();
- printf("Using uncompressed texture (%d bytes)\n", size);
- }
-
- eglutPostRedisplay();
- }
- break;
- case 27:
- eglutDestroyWindow(win);
- exit(0);
- break;
- default:
- break;
- }
-}
-
-static void
-special_key(int key)
-{
- switch (key) {
- 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;
- }
-}
-
-int
-main(int argc, char *argv[])
-{
- eglutInitWindowSize(300, 300);
- eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
- eglutInit(argc, argv);
-
- win = eglutCreateWindow("torus");
-
- eglutIdleFunc(idle);
- eglutReshapeFunc(reshape);
- eglutDisplayFunc(draw);
- eglutKeyboardFunc(key);
- eglutSpecialFunc(special_key);
-
- init();
-
- eglutMainLoop();
-
- return 0;
-}
diff --git a/progs/egl/opengles1/tri.c b/progs/egl/opengles1/tri.c
deleted file mode 100644
index 01ad9bd37e..0000000000
--- a/progs/egl/opengles1/tri.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (C) 2008 Brian Paul 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.
- */
-
-/*
- * Draw a triangle with X/EGL and OpenGL ES 1.x
- * Brian Paul
- * 5 June 2008
- */
-
-#define USE_FIXED_POINT 0
-
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <GLES/gl.h> /* use OpenGL ES 1.x */
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-
-#include "eglut.h"
-
-
-#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
-
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-
-static void
-draw(void)
-{
-#if USE_FIXED_POINT
- static const GLfixed verts[3][2] = {
- { -65536, -65536 },
- { 65536, -65536 },
- { 0, 65536 }
- };
- static const GLfixed colors[3][4] = {
- { 65536, 0, 0, 65536 },
- { 0, 65536, 0 , 65536},
- { 0, 0, 65536 , 65536}
- };
-#else
- 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 }
- };
-#endif
-
- 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);
-
- {
-#if USE_FIXED_POINT
- glVertexPointer(2, GL_FIXED, 0, verts);
- glColorPointer(4, GL_FIXED, 0, colors);
-#else
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(4, GL_FLOAT, 0, colors);
-#endif
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- /* draw triangle */
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- /* draw some points */
- glPointSizex(FLOAT_TO_FIXED(15.5));
- glDrawArrays(GL_POINTS, 0, 3);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- if (0) {
- /* test code */
- GLfixed size;
- glGetFixedv(GL_POINT_SIZE, &size);
- printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0);
- }
-
- glPopMatrix();
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef GL_VERSION_ES_CM_1_0
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-#else
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-
-static void
-test_query_matrix(void)
-{
- PFNGLQUERYMATRIXXOESPROC procQueryMatrixx;
- typedef void (*voidproc)();
- GLfixed mantissa[16];
- GLint exponent[16];
- GLbitfield rv;
- int i;
-
- procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES");
- assert(procQueryMatrixx);
- /* Actually try out this one */
- rv = (*procQueryMatrixx)(mantissa, exponent);
- for (i = 0; i < 16; i++) {
- if (rv & (1<<i)) {
- printf("matrix[%d] invalid\n", i);
- }
- else {
- printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]);
- }
- }
- assert(!eglGetProcAddress("glFoo"));
-}
-
-
-static void
-init(void)
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-
- if (0)
- test_query_matrix();
-}
-
-static void
-special_key(int special)
-{
- 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;
- }
-}
-
-int
-main(int argc, char *argv[])
-{
- eglutInitWindowSize(300, 300);
- eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
- eglutInit(argc, argv);
-
- eglutCreateWindow("tri");
-
- eglutReshapeFunc(reshape);
- eglutDisplayFunc(draw);
- eglutSpecialFunc(special_key);
-
- init();
-
- eglutMainLoop();
-
- return 0;
-}
diff --git a/progs/egl/opengles1/two_win.c b/progs/egl/opengles1/two_win.c
deleted file mode 100644
index 4785e5304d..0000000000
--- a/progs/egl/opengles1/two_win.c
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * Copyright (C) 2008 Brian Paul 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.
- */
-
-/*
- * Test drawing to two windows.
- * Brian Paul
- * August 2008
- */
-
-
-#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>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <EGL/egl.h>
-
-
-static int WinWidth[2] = {150, 300}, WinHeight[2] = {150, 300};
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef GL_VERSION_ES_CM_1_0
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
-#else
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-
-static void
-draw(int win)
-{
- 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 }
- };
-
- assert(win == 0 || win == 1);
-
- reshape(WinWidth[win], WinHeight[win]);
-
- 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);
-
- /* draw triangle */
- {
- 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
-init(void)
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-}
-
-
-/*
- * 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, x, y, 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
-
- if (ctxRet) {
- ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
- if (!ctx) {
- printf("Error: eglCreateContext failed\n");
- exit(1);
- }
- *ctxRet = ctx;
- }
-
- *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
-
- if (!*surfRet) {
- printf("Error: eglCreateWindowSurface failed\n");
- exit(1);
- }
-
- XFree(visInfo);
-
- *winRet = win;
-}
-
-
-static void
-event_loop(Display *dpy, Window win1, Window win2,
- EGLDisplay egl_dpy, EGLSurface egl_surf1, EGLSurface egl_surf2,
- EGLContext egl_ctx)
-{
- while (1) {
- int redraw = 0;
- int win;
- XEvent event;
-
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- if (event.xconfigure.window == win1)
- win = 0;
- else
- win = 1;
- WinWidth[win] = event.xconfigure.width;
- WinHeight[win] = 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) {
- /* win 1 */
- if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, egl_ctx)) {
- printf("Error: eglMakeCurrent(1) failed\n");
- return;
- }
- draw(0);
- eglSwapBuffers(egl_dpy, egl_surf1);
-
- /* win 2 */
- if (!eglMakeCurrent(egl_dpy, egl_surf2, egl_surf2, egl_ctx)) {
- printf("Error: eglMakeCurrent(2) failed\n");
- return;
- }
- draw(1);
- eglSwapBuffers(egl_dpy, egl_surf2);
- }
- }
-}
-
-
-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[])
-{
- Display *x_dpy;
- Window win1, win2;
- EGLSurface egl_surf1, egl_surf2;
- 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;
- }
- }
-
- 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);
-
- make_x_window(x_dpy, egl_dpy,
- "xegl_two_win #1", 0, 0, WinWidth[0], WinHeight[0],
- &win1, &egl_ctx, &egl_surf1);
-
- make_x_window(x_dpy, egl_dpy,
- "xegl_two_win #2", WinWidth[0] + 50, 0,
- WinWidth[1], WinHeight[1],
- &win2, NULL, &egl_surf2);
-
- XMapWindow(x_dpy, win1);
-
- XMapWindow(x_dpy, win2);
-
- if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, 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();
-
- event_loop(x_dpy, win1, win2, egl_dpy, egl_surf1, egl_surf2, egl_ctx);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf1);
- eglDestroySurface(egl_dpy, egl_surf2);
- eglTerminate(egl_dpy);
-
- XDestroyWindow(x_dpy, win1);
- XDestroyWindow(x_dpy, win2);
- XCloseDisplay(x_dpy);
-
- return 0;
-}