2 * Exercise EGL API functions
5 #define EGL_EGLEXT_PROTOTYPES
13 #include <EGL/eglext.h>
16 /*#define FRONTBUFFER*/
18 static void _subset_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
,
19 GLfloat r
, GLfloat g
, GLfloat b
)
21 GLfloat v
[4][2], c
[4][4];
24 v
[0][0] = x1
; v
[0][1] = y1
;
25 v
[1][0] = x2
; v
[1][1] = y1
;
26 v
[2][0] = x2
; v
[2][1] = y2
;
27 v
[3][0] = x1
; v
[3][1] = y2
;
29 for (i
= 0; i
< 4; i
++) {
36 glVertexPointer(2, GL_FLOAT
, 0, v
);
37 glColorPointer(4, GL_FLOAT
, 0, v
);
38 glEnableClientState(GL_VERTEX_ARRAY
);
39 glEnableClientState(GL_COLOR_ARRAY
);
41 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
43 glDisableClientState(GL_VERTEX_ARRAY
);
44 glDisableClientState(GL_COLOR_ARRAY
);
48 static void redraw(EGLDisplay dpy
, EGLSurface surf
, int rot
)
52 printf("Redraw event\n");
54 glClearColor( rand()/(float)RAND_MAX
,
55 rand()/(float)RAND_MAX
,
56 rand()/(float)RAND_MAX
,
59 glClear( GL_COLOR_BUFFER_BIT
);
61 r
= rand()/(float)RAND_MAX
;
62 g
= rand()/(float)RAND_MAX
;
63 b
= rand()/(float)RAND_MAX
;
66 glRotatef(rot
, 0, 0, 1);
68 _subset_Rectf( -1, -1, 1, 1, r
, g
, b
);
74 eglSwapBuffers( dpy
, surf
);
81 * Test EGL_MESA_screen_surface functions
84 TestScreens(EGLDisplay dpy
)
87 EGLScreenMESA screens
[MAX
];
91 eglGetScreensMESA(dpy
, screens
, MAX
, &numScreens
);
92 printf("Found %d screens\n", numScreens
);
93 for (i
= 0; i
< numScreens
; i
++) {
94 printf(" Screen %d handle: %d\n", i
, (int) screens
[i
]);
100 main(int argc
, char *argv
[])
104 EGLSurface pbuffer
, screen_surf
;
105 EGLConfig configs
[10];
106 EGLint numConfigs
, i
;
108 const EGLint pbufAttribs
[] = {
113 const EGLint screenAttribs
[] = {
119 EGLScreenMESA screen
;
123 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
125 EGLDisplay d
= eglGetDisplay((EGLNativeDisplayType
) "!EGL_i915");
128 if (!eglInitialize(d
, &maj
, &min
)) {
129 printf("demo: eglInitialize failed\n");
133 printf("EGL version = %d.%d\n", maj
, min
);
134 printf("EGL_VENDOR = %s\n", eglQueryString(d
, EGL_VENDOR
));
136 eglGetConfigs(d
, configs
, 10, &numConfigs
);
137 printf("Got %d EGL configs:\n", numConfigs
);
138 for (i
= 0; i
< numConfigs
; i
++) {
139 EGLint id
, red
, depth
;
140 eglGetConfigAttrib(d
, configs
[i
], EGL_CONFIG_ID
, &id
);
141 eglGetConfigAttrib(d
, configs
[i
], EGL_RED_SIZE
, &red
);
142 eglGetConfigAttrib(d
, configs
[i
], EGL_DEPTH_SIZE
, &depth
);
143 printf("%2d: Red Size = %d Depth Size = %d\n", id
, red
, depth
);
146 eglGetScreensMESA(d
, &screen
, 1, &count
);
147 eglGetModesMESA(d
, screen
, &mode
, 1, &count
);
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
);
169 screen_surf
= eglCreateScreenSurfaceMESA(d
, configs
[0], screenAttribs
);
170 if (screen_surf
== EGL_NO_SURFACE
) {
171 printf("failed to create screen surface\n");
175 eglShowScreenSurfaceMESA(d
, screen
, screen_surf
, mode
);
177 b
= eglMakeCurrent(d
, screen_surf
, screen_surf
, ctx
);
179 printf("make current failed\n");
183 glViewport(0, 0, 1024, 768);
190 glClear( GL_COLOR_BUFFER_BIT
);
195 glShadeModel( GL_FLAT
);
197 for (i
= 0; i
< 6; i
++) {
198 redraw(d
, screen_surf
, i
*10 );
200 printf("sleep(1)\n");
204 eglDestroySurface(d
, pbuffer
);
205 eglDestroyContext(d
, ctx
);