2
* Exercise EGL API functions
5
#define EGL_EGLEXT_PROTOTYPES
14
#include <EGL/eglext.h>
17
/*#define FRONTBUFFER*/
19
static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
20
GLfloat r, GLfloat g, GLfloat b)
22
GLfloat v[4][2], c[4][4];
25
v[0][0] = x1; v[0][1] = y1;
26
v[1][0] = x2; v[1][1] = y1;
27
v[2][0] = x2; v[2][1] = y2;
28
v[3][0] = x1; v[3][1] = y2;
30
for (i = 0; i < 4; i++) {
37
glVertexPointer(2, GL_FLOAT, 0, v);
38
glColorPointer(4, GL_FLOAT, 0, v);
39
glEnableClientState(GL_VERTEX_ARRAY);
40
glEnableClientState(GL_COLOR_ARRAY);
42
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
44
glDisableClientState(GL_VERTEX_ARRAY);
45
glDisableClientState(GL_COLOR_ARRAY);
49
static void redraw(EGLDisplay dpy, EGLSurface surf, int rot)
53
printf("Redraw event\n");
55
glClearColor( rand()/(float)RAND_MAX,
56
rand()/(float)RAND_MAX,
57
rand()/(float)RAND_MAX,
60
glClear( GL_COLOR_BUFFER_BIT );
62
r = rand()/(float)RAND_MAX;
63
g = rand()/(float)RAND_MAX;
64
b = rand()/(float)RAND_MAX;
67
glRotatef(rot, 0, 0, 1);
69
_subset_Rectf( -1, -1, 1, 1, r, g, b );
75
eglSwapBuffers( dpy, surf );
82
* Test EGL_MESA_screen_surface functions
85
TestScreens(EGLDisplay dpy)
88
EGLScreenMESA screens[MAX];
92
eglGetScreensMESA(dpy, screens, MAX, &numScreens);
93
printf("Found %d screens\n", numScreens);
94
for (i = 0; i < numScreens; i++) {
95
printf(" Screen %d handle: %d\n", i, (int) screens[i]);
101
main(int argc, char *argv[])
105
EGLSurface pbuffer, screen_surf;
106
EGLConfig configs[10];
107
EGLint numConfigs, i;
109
const EGLint pbufAttribs[] = {
114
EGLint screenAttribs[32];
116
EGLScreenMESA screen;
119
EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
122
if (!eglInitialize(d, &maj, &min)) {
123
printf("demo: eglInitialize failed\n");
127
printf("EGL version = %d.%d\n", maj, min);
128
printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
129
if (!strstr(eglQueryString(d, EGL_EXTENSIONS),
130
"EGL_MESA_screen_surface")) {
131
printf("EGL_MESA_screen_surface is not supported\n");
135
eglGetConfigs(d, configs, 10, &numConfigs);
136
printf("Got %d EGL configs:\n", numConfigs);
137
for (i = 0; i < numConfigs; i++) {
138
EGLint id, red, depth;
139
eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
140
eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
141
eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
142
printf("%2d: Red Size = %d Depth Size = %d\n", id, red, depth);
145
eglGetScreensMESA(d, &screen, 1, &count);
146
eglGetModesMESA(d, screen, &mode, 1, &count);
148
eglBindAPI(EGL_OPENGL_API);
149
ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
150
if (ctx == EGL_NO_CONTEXT) {
151
printf("failed to create context\n");
155
pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
156
if (pbuffer == EGL_NO_SURFACE) {
157
printf("failed to create pbuffer\n");
161
b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
163
printf("make current failed\n");
167
b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
170
screenAttribs[i++] = EGL_WIDTH;
171
eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]);
172
screenAttribs[i++] = EGL_HEIGHT;
173
eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]);
174
screenAttribs[i] = EGL_NONE;
176
screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
177
if (screen_surf == EGL_NO_SURFACE) {
178
printf("failed to create screen surface\n");
182
eglShowScreenSurfaceMESA(d, screen, screen_surf, mode);
184
b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
186
printf("make current failed\n");
190
glViewport(0, 0, 1024, 768);
197
glClear( GL_COLOR_BUFFER_BIT );
202
glShadeModel( GL_FLAT );
204
for (i = 0; i < 6; i++) {
205
redraw(d, screen_surf, i*10 );
207
printf("sleep(1)\n");
211
eglDestroySurface(d, pbuffer);
212
eglDestroyContext(d, ctx);