| Flutter Impeller |

Functions
example.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.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.c.

21 {
22 glfwSetErrorCallback(GLFWErrorCallback);
23 [[maybe_unused]] int result = glfwInit();
24 assert(result == GLFW_TRUE);
25
26 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
27
28 GLFWwindow* window =
29 glfwCreateWindow(800, 600, "Impeller Example", NULL, NULL);
30 assert(window != NULL);
31
32 int framebuffer_width, framebuffer_height;
33 glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
34
35 // The GL context must be current on the calling thread.
36 glfwMakeContextCurrent(window);
37
38 ImpellerContext context = ImpellerContextCreateOpenGLESNew(
39 IMPELLER_VERSION, ProcAddressCallback, NULL);
40 assert(context != NULL);
41
42 ImpellerISize surface_size = {};
43 surface_size.width = framebuffer_width;
44 surface_size.height = framebuffer_height;
45
46 ImpellerSurface surface = ImpellerSurfaceCreateWrappedFBONew(
47 context, 0u, kImpellerPixelFormatRGBA8888, &surface_size);
48 assert(surface != NULL);
49
50 ImpellerDisplayList dl = NULL;
51
52 {
53 ImpellerDisplayListBuilder builder = ImpellerDisplayListBuilderNew(NULL);
54 ImpellerPaint paint = ImpellerPaintNew();
55
56 // Clear the background to a white color.
57 ImpellerColor clear_color = {1.0, 1.0, 1.0, 1.0};
58 ImpellerPaintSetColor(paint, &clear_color);
59 ImpellerDisplayListBuilderDrawPaint(builder, paint);
60
61 // Draw a red box.
62 ImpellerColor box_color = {1.0, 0.0, 0.0, 1.0};
63 ImpellerPaintSetColor(paint, &box_color);
64 ImpellerRect box_rect = {10, 10, 100, 100};
65 ImpellerDisplayListBuilderDrawRect(builder, &box_rect, paint);
66
67 dl = ImpellerDisplayListBuilderCreateDisplayListNew(builder);
68
69 ImpellerPaintRelease(paint);
70 ImpellerDisplayListBuilderRelease(builder);
71 }
72
73 assert(dl != NULL);
74
75 while (!glfwWindowShouldClose(window)) {
76 glfwWaitEvents();
77 ImpellerSurfaceDrawDisplayList(surface, dl);
78 glfwSwapBuffers(window);
79 }
80
81 ImpellerDisplayListRelease(dl);
82 ImpellerSurfaceRelease(surface);
83 ImpellerContextRelease(context);
84
85 glfwMakeContextCurrent(NULL);
86
87 glfwDestroyWindow(window);
88
89 glfwTerminate();
90 return 0;
91 }

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.c.

17 {
18 return glfwGetProcAddress(proc_name);
19 }

Referenced by main().

ImpellerISize::height
int64_t height
Definition: impeller.h:459
ImpellerSurfaceCreateWrappedFBONew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerSurface IMPELLER_NULLABLE ImpellerSurfaceCreateWrappedFBONew(ImpellerContext IMPELLER_NULLABLE context, uint64_t fbo, ImpellerPixelFormat format, const ImpellerISize *IMPELLER_NULLABLE size)
Create a new surface by wrapping an existing framebuffer object. The framebuffer must be complete as ...
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...
ImpellerISize
Definition: impeller.h:457
ImpellerDisplayListBuilderDrawRect
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawRect(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerRect *IMPELLER_NONNULL rect, ImpellerPaint IMPELLER_NONNULL paint)
Draws a rectangle.
ImpellerColor
Definition: impeller.h:545
ImpellerRect
Definition: impeller.h:440
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...
ImpellerSurfaceDrawDisplayList
IMPELLER_EXPORT bool ImpellerSurfaceDrawDisplayList(ImpellerSurface IMPELLER_NULLABLE surface, ImpellerDisplayList IMPELLER_NONNULL display_list)
Draw a display list onto the surface. The same display list can be drawn multiple times to different ...
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...
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...
GLFWErrorCallback
void GLFWErrorCallback(int error, const char *description)
Definition: example.c:11
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....
kImpellerPixelFormatRGBA8888
@ kImpellerPixelFormatRGBA8888
Definition: impeller.h:378
ImpellerPaintSetColor
IMPELLER_EXPORT void ImpellerPaintSetColor(ImpellerPaint IMPELLER_NONNULL paint, const ImpellerColor *IMPELLER_NONNULL color)
Set the paint color.
ImpellerDisplayListBuilderNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayListBuilder IMPELLER_NULLABLE ImpellerDisplayListBuilderNew(const ImpellerRect *IMPELLER_NULLABLE cull_rect)
Create a new display list builder.
IMPELLER_VERSION
#define IMPELLER_VERSION
Definition: impeller.h:101
ImpellerPaintNew
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerPaint IMPELLER_NULLABLE ImpellerPaintNew()
Create a new paint with default values.
Definition: impeller.cc:340
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...
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.
ImpellerISize::width
int64_t width
Definition: impeller.h:458
ImpellerDisplayListBuilderDrawPaint
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawPaint(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, ImpellerPaint IMPELLER_NONNULL paint)
Fills the current clip with the specified paint.
ProcAddressCallback
void * ProcAddressCallback(const char *proc_name, void *user_data)
Definition: example.c:17