1 // Copyright 2012, 2014 Intel Corporation
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
8 // - Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
11 // - Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 /// This little example program renders to an X11 window with EGL and an OpenGL
29 /// ES2 context. The program does not include any OpenGL headers and does not
30 /// need to link to libGL. It declares the needed OpenGL symbols itself and
31 /// obtains the OpenGL functions with waffle_dl_sym().
33 /// This example is too simple; it does not perform proper error checking. For
34 /// a complete example with error checking, see gl_basic.c.
36 #define WAFFLE_API_VERSION 0x0106
37 #define WAFFLE_API_EXPERIMENTAL
44 // ---------------------------------------------
46 // ---------------------------------------------
48 typedef float GLclampf
;
49 typedef unsigned int GLbitfield
;
52 GL_COLOR_BUFFER_BIT
= 0x00004000,
59 #define APIENTRY __stdcall
63 static void (APIENTRY
*glClearColor
)(GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
);
64 static void (APIENTRY
*glClear
)(GLbitfield mask
);
66 // ---------------------------------------------
71 struct waffle_display
*dpy
;
72 struct waffle_config
*config
;
73 struct waffle_window
*window
;
74 struct waffle_context
*ctx
;
76 const int32_t init_attrs
[] = {
77 WAFFLE_PLATFORM
, WAFFLE_PLATFORM_X11_EGL
,
81 const int32_t config_attrs
[] = {
82 WAFFLE_CONTEXT_API
, WAFFLE_CONTEXT_OPENGL_ES2
,
91 const int32_t window_width
= 320;
92 const int32_t window_height
= 240;
94 waffle_init(init_attrs
);
95 dpy
= waffle_display_connect(NULL
);
97 // Exit if OpenGL ES2 is unsupported.
98 if (!waffle_display_supports_context_api(dpy
, WAFFLE_CONTEXT_OPENGL_ES2
)
99 || !waffle_dl_can_open(WAFFLE_DL_OPENGL_ES2
))
104 // Get OpenGL functions.
105 glClearColor
= waffle_dl_sym(WAFFLE_DL_OPENGL_ES2
, "glClearColor");
106 glClear
= waffle_dl_sym(WAFFLE_DL_OPENGL_ES2
, "glClear");
108 config
= waffle_config_choose(dpy
, config_attrs
);
109 window
= waffle_window_create(config
, window_width
, window_height
);
110 ctx
= waffle_context_create(config
, NULL
);
112 waffle_window_show(window
);
113 waffle_make_current(dpy
, window
, ctx
);
116 glClearColor(1.0, 0.0, 0.0, 1.0);
117 glClear(GL_COLOR_BUFFER_BIT
);
118 waffle_window_swap_buffers(window
);
119 sleep(1); // Sleep so that user can see window.
122 glClearColor(0.0, 1.0, 0.0, 1.0);
123 glClear(GL_COLOR_BUFFER_BIT
);
124 waffle_window_swap_buffers(window
);
128 glClearColor(0.0, 0.0, 1.0, 1.0);
129 glClear(GL_COLOR_BUFFER_BIT
);
130 waffle_window_swap_buffers(window
);
134 waffle_make_current(dpy
, NULL
, NULL
);
135 waffle_window_destroy(window
);
136 waffle_context_destroy(ctx
);
137 waffle_config_destroy(config
);
138 waffle_display_disconnect(dpy
);