| Flutter Impeller |

Functions
example_gl.c File Reference
`#include <assert.h>`
`#include <stdio.h>`
`#include "GLFW/glfw3.h"`
`#include "impeller.h"`

Go to the source code of this file.

## Functions
void | GLFWErrorCallback (int error, const char *description)
void * | ProcAddressCallback (const char *proc_name, void *user_data)
int | main (int argc, char const *argv[])

## Function Documentation

## ◆ GLFWErrorCallback()

void GLFWErrorCallback | ( | int | error,
|  | const char * | description
| ) |  |

Definition at line 11 of file example_gl.c.

11 {
12 // NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
13 fprintf(stderr, "GLFW Error (%d): %s\n", error, description);
14 fflush(stderr);
15 }

Referenced by main().

## ◆ main()

int main | ( | int | argc,
|  | char const * | argv[]
| ) |  |

Definition at line 21 of file example_gl.c.

21 {
22 glfwSetErrorCallback(GLFWErrorCallback);
23 [[maybe_unused]] int result = glfwInit();
24 assert(result == GLFW_TRUE);
25
26 if (glfwGetPlatform() == GLFW_PLATFORM_COCOA) {
27 // NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
28 fprintf(stderr,
29 "OpenGL(ES) is not available on macOS. Please use Metal or Vulkan "
30 "instead.\n");
31 fflush(stderr);
32 return -1;
33 }
34
35 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
36
37 GLFWwindow* window =
38 glfwCreateWindow(800, 600, "Impeller Example (OpenGL)", NULL, NULL);
39 assert(window != NULL);
40
41 int framebuffer_width, framebuffer_height;
42 glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
43
44 // The GL context must be current on the calling thread.
45 glfwMakeContextCurrent(window);
46
47 ImpellerContext context = ImpellerContextCreateOpenGLESNew(
48 IMPELLER_VERSION, ProcAddressCallback, NULL);
49 assert(context != NULL);
50
51 ImpellerISize surface_size = {};
52 surface_size.width = framebuffer_width;
53 surface_size.height = framebuffer_height;
54
55 ImpellerSurface surface = ImpellerSurfaceCreateWrappedFBONew(
56 context, 0u, kImpellerPixelFormatRGBA8888, &surface_size);
57 assert(surface != NULL);
58
59 ImpellerDisplayList dl = NULL;
60
61 {
62 ImpellerDisplayListBuilder builder = ImpellerDisplayListBuilderNew(NULL);
63 ImpellerPaint paint = ImpellerPaintNew();
64
65 // Clear the background to a white color.
66 ImpellerColor clear_color = {1.0, 1.0, 1.0, 1.0};
67 ImpellerPaintSetColor(paint, &clear_color);
68 ImpellerDisplayListBuilderDrawPaint(builder, paint);
69
70 // Draw a red box.
71 ImpellerColor box_color = {1.0, 0.0, 0.0, 1.0};
72 ImpellerPaintSetColor(paint, &box_color);
73 ImpellerRect box_rect = {10, 10, 100, 100};
74 ImpellerDisplayListBuilderDrawRect(builder, &box_rect, paint);
75
76 dl = ImpellerDisplayListBuilderCreateDisplayListNew(builder);
77
78 ImpellerPaintRelease(paint);
79 ImpellerDisplayListBuilderRelease(builder);
80 }
81
82 assert(dl != NULL);
83
84 while (!glfwWindowShouldClose(window)) {
85 glfwWaitEvents();
86 ImpellerSurfaceDrawDisplayList(surface, dl);
87 glfwSwapBuffers(window);
88 }
89
90 ImpellerDisplayListRelease(dl);
91 ImpellerSurfaceRelease(surface);
92 ImpellerContextRelease(context);
93
94 glfwMakeContextCurrent(NULL);
95
96 glfwDestroyWindow(window);
97
98 glfwTerminate();
99 return 0;
100 }
ProcAddressCallback
void * ProcAddressCallback(const char *proc_name, void *user_data)
Definition: example_gl.c:17
GLFWErrorCallback
void GLFWErrorCallback(int error, const char *description)
Definition: example_gl.c:11
ImpellerPaintRelease
IMPELLER_EXPORT void ImpellerPaintRelease(ImpellerPaint IMPELLER_NULLABLE paint)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
ImpellerSurfaceRelease
IMPELLER_EXPORT void ImpellerSurfaceRelease(ImpellerSurface IMPELLER_NULLABLE surface)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
ImpellerDisplayListBuilderDrawRect
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawRect(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerRect *IMPELLER_NONNULL rect, ImpellerPaint IMPELLER_NONNULL paint)
Draws a rectangle.
ImpellerPaintNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerPaint IMPELLER_NULLABLE ImpellerPaintNew()
Create a new paint with default values.
ImpellerDisplayListBuilderCreateDisplayListNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayList IMPELLER_NULLABLE ImpellerDisplayListBuilderCreateDisplayListNew(ImpellerDisplayListBuilder IMPELLER_NONNULL builder)
Create a new display list using the rendering intent already encoded in the builder....
ImpellerDisplayListBuilderRelease
IMPELLER_EXPORT void ImpellerDisplayListBuilderRelease(ImpellerDisplayListBuilder IMPELLER_NULLABLE builder)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
ImpellerPaintSetColor
IMPELLER_EXPORT void ImpellerPaintSetColor(ImpellerPaint IMPELLER_NONNULL paint, const ImpellerColor *IMPELLER_NONNULL color)
Set the paint color.
ImpellerDisplayListRelease
IMPELLER_EXPORT void ImpellerDisplayListRelease(ImpellerDisplayList IMPELLER_NULLABLE display_list)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_VERSION
#define IMPELLER_VERSION
Definition: impeller.h:103
ImpellerSurfaceDrawDisplayList
IMPELLER_EXPORT bool ImpellerSurfaceDrawDisplayList(ImpellerSurface IMPELLER_NONNULL surface, ImpellerDisplayList IMPELLER_NONNULL display_list)
Draw a display list onto the surface. The same display list can be drawn multiple times to different ...
ImpellerDisplayListBuilderDrawPaint
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawPaint(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, ImpellerPaint IMPELLER_NONNULL paint)
Fills the current clip with the specified paint.
ImpellerContextCreateOpenGLESNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerContext IMPELLER_NULLABLE ImpellerContextCreateOpenGLESNew(uint32_t version, ImpellerProcAddressCallback IMPELLER_NONNULL gl_proc_address_callback, void *IMPELLER_NULLABLE gl_proc_address_callback_user_data)
Create an OpenGL(ES) Impeller context.
ImpellerContextRelease
IMPELLER_EXPORT void ImpellerContextRelease(ImpellerContext IMPELLER_NULLABLE context)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
ImpellerSurfaceCreateWrappedFBONew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerSurface IMPELLER_NULLABLE ImpellerSurfaceCreateWrappedFBONew(ImpellerContext IMPELLER_NONNULL context, uint64_t fbo, ImpellerPixelFormat format, const ImpellerISize *IMPELLER_NONNULL size)
Create a new surface by wrapping an existing framebuffer object. The framebuffer must be complete as ...
ImpellerDisplayListBuilderNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayListBuilder IMPELLER_NULLABLE ImpellerDisplayListBuilderNew(const ImpellerRect *IMPELLER_NULLABLE cull_rect)
Create a new display list builder.
kImpellerPixelFormatRGBA8888
@ kImpellerPixelFormatRGBA8888
Definition: impeller.h:425
ImpellerColor
Definition: impeller.h:612
ImpellerISize
Definition: impeller.h:519
ImpellerISize::height
int64_t height
Definition: impeller.h:521
ImpellerISize::width
int64_t width
Definition: impeller.h:520
ImpellerRect
Definition: impeller.h:502

References GLFWErrorCallback(), ImpellerISize::height, IMPELLER_VERSION, ImpellerContextCreateOpenGLESNew(), ImpellerContextRelease(), ImpellerDisplayListBuilderCreateDisplayListNew(), ImpellerDisplayListBuilderDrawPaint(), ImpellerDisplayListBuilderDrawRect(), ImpellerDisplayListBuilderNew(), ImpellerDisplayListBuilderRelease(), ImpellerDisplayListRelease(), ImpellerPaintNew(), ImpellerPaintRelease(), ImpellerPaintSetColor(), ImpellerSurfaceCreateWrappedFBONew(), ImpellerSurfaceDrawDisplayList(), ImpellerSurfaceRelease(), kImpellerPixelFormatRGBA8888, ProcAddressCallback(), and ImpellerISize::width.

## ◆ ProcAddressCallback()

void* ProcAddressCallback | ( | const char * | proc_name,
|  | void * | user_data
| ) |  |

Definition at line 17 of file example_gl.c.

17 {
18 return glfwGetProcAddress(proc_name);
19 }

Referenced by main().