summaryrefslogtreecommitdiffstats
path: root/progs/egl/opengles2
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2010-05-21 09:32:38 -0700
committerEric Anholt <[email protected]>2010-05-21 12:20:39 -0700
commit68fc4b415e322f6744299e39864fbc377c6eff74 (patch)
tree4bafffd8b0105174f3c5c0ae327a005be9145990 /progs/egl/opengles2
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/opengles2')
-rw-r--r--progs/egl/opengles2/.gitignore3
-rw-r--r--progs/egl/opengles2/Makefile56
-rw-r--r--progs/egl/opengles2/es2gears.c425
-rw-r--r--progs/egl/opengles2/tri.c520
4 files changed, 0 insertions, 1004 deletions
diff --git a/progs/egl/opengles2/.gitignore b/progs/egl/opengles2/.gitignore
deleted file mode 100644
index 6158cc6e680..00000000000
--- a/progs/egl/opengles2/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-es2_info.c
-es2_info
-tri
diff --git a/progs/egl/opengles2/Makefile b/progs/egl/opengles2/Makefile
deleted file mode 100644
index bf14513d7fb..00000000000
--- a/progs/egl/opengles2/Makefile
+++ /dev/null
@@ -1,56 +0,0 @@
-# progs/egl/opengles2/Makefile
-
-TOP = ../../..
-include $(TOP)/configs/current
-
-
-INCLUDE_DIRS = \
- -I$(TOP)/include \
- -I$(TOP)/progs/egl/eglut \
- $(X11_CFLAGS) \
-
-
-HEADERS = $(TOP)/include/GLES/egl.h
-
-
-ES2_LIB_DEPS = \
- $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) \
- $(TOP)/$(LIB_DIR)/$(GLESv2_LIB_NAME)
-
-
-ES2_LIBS = \
- -L$(TOP)/$(LIB_DIR) -l$(EGL_LIB) -l$(GLESv2_LIB) \
- $(LIBDRM_LIB) $(X11_LIBS)
-
-PROGRAMS = \
- es2_info \
- tri \
- es2gears
-
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS)
-
-
-
-es2_info.c: ../opengles1/es1_info.c
- cp -f $^ $@
-
-es2_info: es2_info.o $(ES2_LIB_DEPS)
- $(CC) $(CFLAGS) es2_info.o $(ES2_LIBS) -o $@
-
-tri: tri.o $(ES2_LIB_DEPS)
- $(CC) $(CFLAGS) tri.o $(ES2_LIBS) -o $@
-
-es2gears: es2gears.o $(ES2_LIB_DEPS)
- $(CC) $(CFLAGS) es2gears.o ../eglut/libeglut-x11.a $(ES2_LIBS) -lm -o $@
-
-clean:
- rm -f *.o *~
- rm -f $(PROGRAMS)
- rm -f es2_info.c
-
diff --git a/progs/egl/opengles2/es2gears.c b/progs/egl/opengles2/es2gears.c
deleted file mode 100644
index 6bd6594320a..00000000000
--- a/progs/egl/opengles2/es2gears.c
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * Ported to GLES2.
- * Kristian Høgsberg <[email protected]>
- * May 3, 2010
- */
-
-/*
- * Command line options:
- * -info print GL implementation information
- *
- */
-
-
-#define GL_GLEXT_PROTOTYPES
-#define EGL_EGLEXT_PROTOTYPES
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <GLES2/gl2.h>
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include "eglut.h"
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-struct gear {
- GLfloat *vertices;
- GLuint vbo;
- int count;
-};
-
-static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
-static struct gear *gear1, *gear2, *gear3;
-static GLfloat angle = 0.0;
-static GLuint proj_location, light_location, color_location;
-static GLfloat proj[16];
-
-static GLfloat *
-vert(GLfloat *p, GLfloat x, GLfloat y, GLfloat z, GLfloat *n)
-{
- p[0] = x;
- p[1] = y;
- p[2] = z;
- p[3] = n[0];
- p[4] = n[1];
- p[5] = n[2];
-
- return p + 6;
-}
-
-/* Draw a gear wheel. You'll probably want to call this function when
- * building a display list since we do a lot of trig here.
- *
- * Input: 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 struct gear *
-gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
- GLint teeth, GLfloat tooth_depth)
-{
- GLint i;
- GLfloat r0, r1, r2;
- GLfloat da;
- GLfloat *p, *v;
- struct gear *gear;
- double s[5], c[5];
- GLfloat verts[3 * 14], normal[3];
- const int tris_per_tooth = 20;
-
- gear = malloc(sizeof *gear);
- if (gear == NULL)
- return NULL;
-
- r0 = inner_radius;
- r1 = outer_radius - tooth_depth / 2.0;
- r2 = outer_radius + tooth_depth / 2.0;
-
- da = 2.0 * M_PI / teeth / 4.0;
-
- gear->vertices = calloc(teeth * tris_per_tooth * 3 * 6,
- sizeof *gear->vertices);
- s[4] = 0;
- c[4] = 1;
- v = gear->vertices;
- for (i = 0; i < teeth; i++) {
- s[0] = s[4];
- c[0] = c[4];
- sincos(i * 2.0 * M_PI / teeth + da, &s[1], &c[1]);
- sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]);
- sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]);
- sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]);
-
- normal[0] = 0.0;
- normal[1] = 0.0;
- normal[2] = 1.0;
-
- v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal);
-
- v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal);
- v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal);
- v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal);
- v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal);
- v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal);
- v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal);
- v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal);
-
- v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal);
- v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal);
- v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal);
- v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal);
-
- normal[0] = 0.0;
- normal[1] = 0.0;
- normal[2] = -1.0;
-
- v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal);
-
- v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal);
- v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal);
- v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal);
- v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal);
- v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal);
- v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal);
- v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal);
-
- v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal);
-
- v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal);
- v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal);
- v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal);
- v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal);
- v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal);
- v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal);
- v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal);
- v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal);
- v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal);
- v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal);
-
- v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal);
- }
-
- gear->count = (v - gear->vertices) / 6;
-
- glGenBuffers(1, &gear->vbo);
- glBindBuffer(GL_ARRAY_BUFFER, gear->vbo);
- glBufferData(GL_ARRAY_BUFFER, gear->count * 6 * 4,
- gear->vertices, GL_STATIC_DRAW);
-
- return gear;
-}
-
-static void
-multiply(GLfloat *m, const GLfloat *n)
-{
- GLfloat tmp[16];
- const GLfloat *row, *column;
- div_t d;
- int i, j;
-
- for (i = 0; i < 16; i++) {
- tmp[i] = 0;
- d = div(i, 4);
- row = n + d.quot * 4;
- column = m + d.rem;
- for (j = 0; j < 4; j++)
- tmp[i] += row[j] * column[j * 4];
- }
- memcpy(m, &tmp, sizeof tmp);
-}
-
-static void
-rotate(GLfloat *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
-{
- double s, c;
-
- sincos(angle, &s, &c);
- GLfloat r[16] = {
- x * x * (1 - c) + c, y * x * (1 - c) + z * s, x * z * (1 - c) - y * s, 0,
- x * y * (1 - c) - z * s, y * y * (1 - c) + c, y * z * (1 - c) + x * s, 0,
- x * z * (1 - c) + y * s, y * z * (1 - c) - x * s, z * z * (1 - c) + c, 0,
- 0, 0, 0, 1
- };
-
- multiply(m, r);
-}
-
-static void
-translate(GLfloat *m, GLfloat x, GLfloat y, GLfloat z)
-{
- GLfloat t[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 };
-
- multiply(m, t);
-}
-
-static const GLfloat light[3] = { 1.0, 1.0, -1.0 };
-
-static void
-draw_gear(struct gear *gear, GLfloat *m,
- GLfloat x, GLfloat y, GLfloat angle, const GLfloat *color)
-{
- GLfloat tmp[16];
-
- memcpy(tmp, m, sizeof tmp);
- translate(tmp, x, y, 0);
- rotate(tmp, 2 * M_PI * angle / 360.0, 0, 0, 1);
- glUniformMatrix4fv(proj_location, 1, GL_FALSE, tmp);
- glUniform3fv(light_location, 1, light);
- glUniform4fv(color_location, 1, color);
-
- glBindBuffer(GL_ARRAY_BUFFER, gear->vbo);
-
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
- 6 * sizeof(GLfloat), NULL);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
- 6 * sizeof(GLfloat), (GLfloat *) 0 + 3);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->count);
-}
-
-static void
-gears_draw(void)
-{
- const static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
- const static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
- const static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
- GLfloat m[16];
-
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- memcpy(m, proj, sizeof m);
- rotate(m, 2 * M_PI * view_rotx / 360.0, 1, 0, 0);
- rotate(m, 2 * M_PI * view_roty / 360.0, 0, 1, 0);
- rotate(m, 2 * M_PI * view_rotz / 360.0, 0, 0, 1);
-
- draw_gear(gear1, m, -3.0, -2.0, angle, red);
- draw_gear(gear2, m, 3.1, -2.0, -2 * angle - 9.0, green);
- draw_gear(gear3, m, -3.1, 4.2, -2 * angle - 25.0, blue);
-}
-
-/* new window size or exposure */
-static void
-gears_reshape(int width, int height)
-{
- GLfloat ar, m[16] = {
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 0.1, 0.0,
- 0.0, 0.0, 0.0, 1.0,
- };
-
- if (width < height)
- ar = width;
- else
- ar = height;
-
- m[0] = 0.1 * ar / width;
- m[5] = 0.1 * ar / height;
- memcpy(proj, m, sizeof proj);
- glViewport(0, 0, (GLint) width, (GLint) height);
-}
-
-static void
-gears_special(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;
- }
-}
-
-static void
-gears_idle(void)
-{
- static double tRot0 = -1.0;
- double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
-
- if (tRot0 < 0.0)
- tRot0 = t;
- dt = t - tRot0;
- tRot0 = t;
-
- /* advance rotation for next frame */
- angle += 70.0 * dt; /* 70 degrees per second */
- if (angle > 3600.0)
- angle -= 3600.0;
-
- eglutPostRedisplay();
-}
-
-static const char vertex_shader[] =
- "uniform mat4 proj;\n"
- "attribute vec4 position;\n"
- "attribute vec4 normal;\n"
- "varying vec3 rotated_normal;\n"
- "varying vec3 rotated_position;\n"
- "vec4 tmp;\n"
- "void main()\n"
- "{\n"
- " gl_Position = proj * position;\n"
- " rotated_position = gl_Position.xyz;\n"
- " tmp = proj * normal;\n"
- " rotated_normal = tmp.xyz;\n"
- "}\n";
-
- static const char fragment_shader[] =
- //"precision mediump float;\n"
- "uniform vec4 color;\n"
- "uniform vec3 light;\n"
- "varying vec3 rotated_normal;\n"
- "varying vec3 rotated_position;\n"
- "vec3 light_direction;\n"
- "vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
- "void main()\n"
- "{\n"
- " light_direction = normalize(light - rotated_position);\n"
- " gl_FragColor = color + white * dot(light_direction, rotated_normal);\n"
- "}\n";
-
-static void
-gears_init(void)
-{
- GLuint v, f, program;
- const char *p;
- char msg[512];
-
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
-
- p = vertex_shader;
- v = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(v, 1, &p, NULL);
- glCompileShader(v);
- glGetShaderInfoLog(v, sizeof msg, NULL, msg);
- printf("vertex shader info: %s\n", msg);
-
- p = fragment_shader;
- f = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(f, 1, &p, NULL);
- glCompileShader(f);
- glGetShaderInfoLog(f, sizeof msg, NULL, msg);
- printf("fragment shader info: %s\n", msg);
-
- program = glCreateProgram();
- glAttachShader(program, v);
- glAttachShader(program, f);
- glBindAttribLocation(program, 0, "position");
- glBindAttribLocation(program, 1, "normal");
-
- glLinkProgram(program);
- glGetProgramInfoLog(program, sizeof msg, NULL, msg);
- printf("info: %s\n", msg);
-
- glUseProgram(program);
- proj_location = glGetUniformLocation(program, "proj");
- light_location = glGetUniformLocation(program, "light");
- color_location = glGetUniformLocation(program, "color");
-
- /* make the gears */
- gear1 = gear(1.0, 4.0, 1.0, 20, 0.7);
- gear2 = gear(0.5, 2.0, 2.0, 10, 0.7);
- gear3 = gear(1.3, 2.0, 0.5, 10, 0.7);
-}
-
-int
-main(int argc, char *argv[])
-{
- eglutInitWindowSize(300, 300);
- eglutInitAPIMask(EGLUT_OPENGL_ES2_BIT);
- eglutInit(argc, argv);
-
- eglutCreateWindow("es2gears");
-
- eglutIdleFunc(gears_idle);
- eglutReshapeFunc(gears_reshape);
- eglutDisplayFunc(gears_draw);
- eglutSpecialFunc(gears_special);
-
- gears_init();
-
- eglutMainLoop();
-
- return 0;
-}
diff --git a/progs/egl/opengles2/tri.c b/progs/egl/opengles2/tri.c
deleted file mode 100644
index 812dbf031e4..00000000000
--- a/progs/egl/opengles2/tri.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- **************************************************************************/
-
-/*
- * Draw a triangle with X/EGL and OpenGL ES 2.x
- */
-
-#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 <GLES2/gl2.h> /* use OpenGL ES 2.x */
-#endif
-#include <EGL/egl.h>
-
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
-
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0;
-
-static GLint u_matrix = -1;
-static GLint attr_pos = 0, attr_color = 1;
-
-
-static void
-make_z_rot_matrix(GLfloat angle, GLfloat *m)
-{
- float c = cos(angle * M_PI / 180.0);
- float s = sin(angle * M_PI / 180.0);
- int i;
- for (i = 0; i < 16; i++)
- m[i] = 0.0;
- m[0] = m[5] = m[10] = m[15] = 1.0;
-
- m[0] = c;
- m[1] = s;
- m[4] = -s;
- m[5] = c;
-}
-
-static void
-make_scale_matrix(GLfloat xs, GLfloat ys, GLfloat zs, GLfloat *m)
-{
- int i;
- for (i = 0; i < 16; i++)
- m[i] = 0.0;
- m[0] = xs;
- m[5] = ys;
- m[10] = zs;
- m[15] = 1.0;
-}
-
-
-static void
-mul_matrix(GLfloat *prod, const GLfloat *a, const GLfloat *b)
-{
-#define A(row,col) a[(col<<2)+row]
-#define B(row,col) b[(col<<2)+row]
-#define P(row,col) p[(col<<2)+row]
- GLfloat p[16];
- GLint i;
- for (i = 0; i < 4; i++) {
- const GLfloat ai0=A(i,0), ai1=A(i,1), ai2=A(i,2), ai3=A(i,3);
- P(i,0) = ai0 * B(0,0) + ai1 * B(1,0) + ai2 * B(2,0) + ai3 * B(3,0);
- P(i,1) = ai0 * B(0,1) + ai1 * B(1,1) + ai2 * B(2,1) + ai3 * B(3,1);
- P(i,2) = ai0 * B(0,2) + ai1 * B(1,2) + ai2 * B(2,2) + ai3 * B(3,2);
- P(i,3) = ai0 * B(0,3) + ai1 * B(1,3) + ai2 * B(2,3) + ai3 * B(3,3);
- }
- memcpy(prod, p, sizeof(p));
-#undef A
-#undef B
-#undef PROD
-}
-
-
-static void
-draw(void)
-{
- static const GLfloat verts[3][2] = {
- { -1, -1 },
- { 1, -1 },
- { 0, 1 }
- };
- static const GLfloat colors[3][3] = {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 }
- };
- GLfloat mat[16], rot[16], scale[16];
-
- /* Set modelview/projection matrix */
- make_z_rot_matrix(view_rotx, rot);
- make_scale_matrix(0.5, 0.5, 0.5, scale);
- mul_matrix(mat, rot, scale);
- glUniformMatrix4fv(u_matrix, 1, GL_FALSE, mat);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- {
- glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(attr_color, 3, GL_FLOAT, GL_FALSE, 0, colors);
- glEnableVertexAttribArray(attr_pos);
- glEnableVertexAttribArray(attr_color);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableVertexAttribArray(attr_pos);
- glDisableVertexAttribArray(attr_color);
- }
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- glViewport(0, 0, (GLint) width, (GLint) height);
-}
-
-
-static void
-create_shaders(void)
-{
- static const char *fragShaderText =
- "varying vec4 v_color;\n"
- "void main() {\n"
- " gl_FragColor = v_color;\n"
- "}\n";
- static const char *vertShaderText =
- "uniform mat4 modelviewProjection;\n"
- "attribute vec4 pos;\n"
- "attribute vec4 color;\n"
- "varying vec4 v_color;\n"
- "void main() {\n"
- " gl_Position = modelviewProjection * pos;\n"
- " v_color = color;\n"
- "}\n";
-
- GLuint fragShader, vertShader, program;
- GLint stat;
-
- fragShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragShader, 1, (const char **) &fragShaderText, NULL);
- glCompileShader(fragShader);
- glGetShaderiv(fragShader, GL_COMPILE_STATUS, &stat);
- if (!stat) {
- printf("Error: fragment shader did not compile!\n");
- exit(1);
- }
-
- vertShader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vertShader, 1, (const char **) &vertShaderText, NULL);
- glCompileShader(vertShader);
- glGetShaderiv(vertShader, GL_COMPILE_STATUS, &stat);
- if (!stat) {
- printf("Error: vertex shader did not compile!\n");
- exit(1);
- }
-
- program = glCreateProgram();
- glAttachShader(program, fragShader);
- glAttachShader(program, vertShader);
- glLinkProgram(program);
-
- glGetProgramiv(program, GL_LINK_STATUS, &stat);
- if (!stat) {
- char log[1000];
- GLsizei len;
- glGetProgramInfoLog(program, 1000, &len, log);
- printf("Error: linking:\n%s\n", log);
- exit(1);
- }
-
- glUseProgram(program);
-
- if (1) {
- /* test setting attrib locations */
- glBindAttribLocation(program, attr_pos, "pos");
- glBindAttribLocation(program, attr_color, "color");
- glLinkProgram(program); /* needed to put attribs into effect */
- }
- else {
- /* test automatic attrib locations */
- attr_pos = glGetAttribLocation(program, "pos");
- attr_color = glGetAttribLocation(program, "color");
- }
-
- u_matrix = glGetUniformLocation(program, "modelviewProjection");
- printf("Uniform modelviewProjection at %d\n", u_matrix);
- printf("Attrib pos at %d\n", attr_pos);
- printf("Attrib color at %d\n", attr_color);
-}
-
-
-static void
-init(void)
-{
- typedef void (*proc)();
-
-#if 1 /* test code */
- proc p = eglGetProcAddress("glMapBufferOES");
- assert(p);
-#endif
-
- glClearColor(0.4, 0.4, 0.4, 0.0);
-
- create_shaders();
-}
-
-
-/*
- * 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_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
- static const EGLint ctx_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
- int scrnum;
- XSetWindowAttributes attr;
- unsigned long mask;
- Window root;
- Window win;
- XVisualInfo *visInfo, visTemplate;
- int num_visuals;
- EGLContext ctx;
- EGLConfig config;
- EGLint num_configs;
- EGLint vid;
-
- scrnum = DefaultScreen( x_dpy );
- root = RootWindow( x_dpy, scrnum );
-
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- assert(config);
- assert(num_configs > 0);
-
- if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
- printf("Error: eglGetConfigAttrib() failed\n");
- exit(1);
- }
-
- /* The X window visual must match the EGL config */
- visTemplate.visualid = vid;
- visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
- if (!visInfo) {
- printf("Error: couldn't get X visual\n");
- exit(1);
- }
-
- /* window attributes */
- attr.background_pixel = 0;
- attr.border_pixel = 0;
- attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-
- win = XCreateWindow( x_dpy, root, 0, 0, width, height,
- 0, visInfo->depth, InputOutput,
- visInfo->visual, mask, &attr );
-
- /* set hints and properties */
- {
- XSizeHints sizehints;
- sizehints.x = x;
- sizehints.y = y;
- sizehints.width = width;
- sizehints.height = height;
- sizehints.flags = USSize | USPosition;
- XSetNormalHints(x_dpy, win, &sizehints);
- XSetStandardProperties(x_dpy, win, name, name,
- None, (char **)NULL, 0, &sizehints);
- }
-
-#if USE_FULL_GL /* XXX fix this when eglBindAPI() works */
- eglBindAPI(EGL_OPENGL_API);
-#else
- eglBindAPI(EGL_OPENGL_ES_API);
-#endif
-
- ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
- if (!ctx) {
- printf("Error: eglCreateContext failed\n");
- exit(1);
- }
-
- /* test eglQueryContext() */
- {
- EGLint val;
- eglQueryContext(egl_dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &val);
- assert(val == 2);
- }
-
- *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
- if (!*surfRet) {
- printf("Error: eglCreateWindowSurface failed\n");
- exit(1);
- }
-
- /* sanity checks */
- {
- EGLint val;
- eglQuerySurface(egl_dpy, *surfRet, EGL_WIDTH, &val);
- assert(val == width);
- eglQuerySurface(egl_dpy, *surfRet, EGL_HEIGHT, &val);
- assert(val == height);
- assert(eglGetConfigAttrib(egl_dpy, config, EGL_SURFACE_TYPE, &val));
- assert(val & EGL_WINDOW_BIT);
- }
-
- 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] == 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 = 300, winHeight = 300;
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- GLboolean printInfo = GL_FALSE;
- EGLint egl_major, egl_minor;
- int i;
- const char *s;
-
- 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,
- "OpenGL ES 2.x tri", 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) {
- 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);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}