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 const EGLint screenAttribs
[] = {
120 EGLScreenMESA screen
;
123 EGLDisplay d
= eglGetDisplay(EGL_DEFAULT_DISPLAY
);
126 if (!eglInitialize(d
, &maj
, &min
)) {
127 printf("demo: eglInitialize failed\n");
131 printf("EGL version = %d.%d\n", maj
, min
);
132 printf("EGL_VENDOR = %s\n", eglQueryString(d
, EGL_VENDOR
));
133 if (!strstr(eglQueryString(d
, EGL_EXTENSIONS
),
134 "EGL_MESA_screen_surface")) {
135 printf("EGL_MESA_screen_surface is not supported\n");
139 eglGetConfigs(d
, configs
, 10, &numConfigs
);
140 printf("Got %d EGL configs:\n", numConfigs
);
141 for (i
= 0; i
< numConfigs
; i
++) {
142 EGLint id
, red
, depth
;
143 eglGetConfigAttrib(d
, configs
[i
], EGL_CONFIG_ID
, &id
);
144 eglGetConfigAttrib(d
, configs
[i
], EGL_RED_SIZE
, &red
);
145 eglGetConfigAttrib(d
, configs
[i
], EGL_DEPTH_SIZE
, &depth
);
146 printf("%2d: Red Size = %d Depth Size = %d\n", id
, red
, depth
);
149 eglGetScreensMESA(d
, &screen
, 1, &count
);
150 eglGetModesMESA(d
, screen
, &mode
, 1, &count
);
152 ctx
= eglCreateContext(d
, configs
[0], EGL_NO_CONTEXT
, NULL
);
153 if (ctx
== EGL_NO_CONTEXT
) {
154 printf("failed to create context\n");
158 pbuffer
= eglCreatePbufferSurface(d
, configs
[0], pbufAttribs
);
159 if (pbuffer
== EGL_NO_SURFACE
) {
160 printf("failed to create pbuffer\n");
164 b
= eglMakeCurrent(d
, pbuffer
, pbuffer
, ctx
);
166 printf("make current failed\n");
170 b
= eglMakeCurrent(d
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
172 screen_surf
= eglCreateScreenSurfaceMESA(d
, configs
[0], screenAttribs
);
173 if (screen_surf
== EGL_NO_SURFACE
) {
174 printf("failed to create screen surface\n");
178 eglShowScreenSurfaceMESA(d
, screen
, screen_surf
, mode
);
180 b
= eglMakeCurrent(d
, screen_surf
, screen_surf
, ctx
);
182 printf("make current failed\n");
186 glViewport(0, 0, 1024, 768);
193 glClear( GL_COLOR_BUFFER_BIT
);
198 glShadeModel( GL_FLAT
);
200 for (i
= 0; i
< 6; i
++) {
201 redraw(d
, screen_surf
, i
*10 );
203 printf("sleep(1)\n");
207 eglDestroySurface(d
, pbuffer
);
208 eglDestroyContext(d
, ctx
);