6 n__atlas_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_atlas.h

Multi-page sprite atlas: random-access cell blitting from a grid. More...

Structures

Name
struct N_ATLAS_PAGE
one atlas page: a bitmap holding cols*rows equally sized cells
struct N_ATLAS
a set of atlas pages addressed as (page, cell index)

Detailed Description

Multi-page sprite atlas: random-access cell blitting from a grid.

Author: Castagnier Mickael aka Gull Ra Driel

Version: 1.0

Date: 21/08/2026

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __N_ATLAS_HEADER
#define __N_ATLAS_HEADER

#ifdef __cplusplus
extern "C" {
#endif

#include "n_common.h"
#include "n_log.h"
#include "allegro5/allegro.h"


typedef struct N_ATLAS_PAGE {
    ALLEGRO_BITMAP* bmp;
    uint16_t cols;
    uint16_t rows;
} N_ATLAS_PAGE;

typedef struct N_ATLAS {
    N_ATLAS_PAGE* pages;
    size_t npages;
} N_ATLAS;

N_ATLAS* new_n_atlas(size_t npages);
void n_atlas_destroy(N_ATLAS** atlas);
int n_atlas_set_page(N_ATLAS* atlas, size_t page, const void* bytes, size_t len, const char* ext, uint16_t cols, uint16_t rows);
int n_atlas_page_ready(const N_ATLAS* atlas, size_t page);
int n_atlas_draw_cell(N_ATLAS* atlas, size_t page, size_t index, float x, float y, float size);
int n_atlas_cell_rect(const N_ATLAS* atlas, size_t page, size_t index, float* sx, float* sy, float* sw, float* sh);
int n_atlas_max_bitmap_size(void);


#ifdef __cplusplus
}
#endif

#endif  // __N_ATLAS_HEADER