Runara is a simple, well documented, bloatless 2D rendering library
Runara is a high level abstraction over both Vulkan and OpenGL that renders and manages 2D textures and rectangles. It implements an instanced batch renderer that efficiently draws queued lists of textures and rectangles in an immediate-mode manner. One can upload texture data into Runara's managed texture atlas or to directly to a dedicated texture.
- Vulkan 1.0 backend implementation
- OpenGL 3.3 backend implementation
- Efficient instanced & batched 2D renderer
- Merging of adjacent render batches
- Optimized 3D texture atlas
- Ability to supply custom shaders
#include <stdlib.h>
#define GLFW_INCLUDE_NONE
#include "runara/runara.h"
#include <GLFW/glfw3.h>
struct rn_state_t *state = NULL;
static void *_gl_load_proc(const char *name) {
union {
GLFWglproc function;
void *pointer;
} proc = {.function = glfwGetProcAddress(name)};
return proc.pointer;
}
void resize_cb(GLFWwindow *window, int width, int height) {
(void)window;
struct rn_box_u32_t bounds = {.width = width, .height = height};
rn_canvas_set_bounds(state, &bounds);
}
int main(void) {
if (!glfwInit())
return EXIT_FAILURE;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow *window = glfwCreateWindow(800, 600, "Runara rect", NULL, NULL);
if (!window) {
glfwTerminate();
return EXIT_FAILURE;
}
glfwSetFramebufferSizeCallback(window, resize_cb);
glfwMakeContextCurrent(window);
struct rn_init_options_t options = {
.render_backend = RN_RENDER_BACKEND_OPENGL,
.gl_load_proc = _gl_load_proc,
};
state = rn_state_init(&options, 800, 600);
if (!state) {
glfwDestroyWindow(window);
glfwTerminate();
return EXIT_FAILURE;
}
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
rn_begin(state);
rn_clear_color(state, (rn_color_t){0.2, 0.2, 0.2, 1.0});
rn_draw_rect(state, (struct rn_rect_t){50, 50, 100, 100},
(rn_color_t){1, 0, 0, 1});
rn_end(state);
glfwSwapBuffers(window);
}
rn_state_fini(state);
glfwDestroyWindow(window);
glfwTerminate();
return EXIT_SUCCESS;
}Runara 2.0 uses Meson as its build system and supports both OpenGL and Vulkan rendering backends.
Make sure you have the following build dependencies installed before building Runara:
meson, ninja, gcc, pkg-config, cglm
Depending on the rendering backends you want, you will also need:
- OpenGL: OpenGL development libraries:
libgl-dev - Vulkan: Vulkan development libraries, GLSL, Python:
libvulkan-dev,glslang-tools,python3 - Examples: GLFW3, X11 & GL development libraries:
libglfw3-dev,libx11-dev,libgl-dev
Clone the repository:
git clone https://github.com/cococry/runara.git
cd runaraConfigure the build with both rendering backends and examples enabled:
meson setup build -Dbackends=all -Dexamples=trueCompile Runara:
meson compile -C buildAlternatively, you can build only one rendering backend:
meson setup build -Dbackends=opengl -Dexamples=trueOr:
meson setup build -Dbackends=vulkan -Dexamples=falseAfter building Runara, install the library, headers and pkg-config file with:
sudo meson install -C buildYou can then link Runara in your own projects using pkg-config.
You can take a look at the examples or read the header file to get started with using Runara. For Vulkan specific documentation, see the Vulkan header file or the GLFW Vulkan example
