mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-12-22 06:30:05 +00:00
Compare commits
3 Commits
6663804c88
...
20fad92e4f
Author | SHA1 | Date | |
---|---|---|---|
|
20fad92e4f | ||
|
7c0c02b9af | ||
|
1a1f4e8b13 |
@ -20,7 +20,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
lfs: true
|
||||
- run: cd prev && git checkout 10a90a5f6a
|
||||
- run: cd prev && git checkout 7c0c02b9af
|
||||
- name: Build current
|
||||
run: cmake -S curr -B curr/build -DGLERMINAL_TEST=ON && cmake --build curr/build
|
||||
- name: Build previous
|
||||
|
@ -42,7 +42,7 @@ void glerminal_flush();
|
||||
* @param layer layer of the cell in the range [0, LAYER_COUNT)
|
||||
* @param sprite sprite's index in the range [0, 4096)
|
||||
*/
|
||||
void glerminal_set(unsigned char x, unsigned char y, unsigned char layer, unsigned short sprite);
|
||||
void glerminal_set(int x, int y, int layer, unsigned short sprite);
|
||||
/**
|
||||
* @brief Get a cell's sprite
|
||||
* @param x position of the cell in the range [0, GRID_WIDTH)
|
||||
@ -50,7 +50,7 @@ void glerminal_set(unsigned char x, unsigned char y, unsigned char layer, unsign
|
||||
* @param layer layer of the cell in the range [0, LAYER_COUNT)
|
||||
* @return sprite index currently assigned to the cell
|
||||
*/
|
||||
unsigned short glerminal_get(unsigned char x, unsigned char y, unsigned short layer);
|
||||
unsigned short glerminal_get(int x, int y, int layer);
|
||||
/**
|
||||
* @brief Set a cell's offset
|
||||
* @param x position of the cell in the range [0, GRID_WIDTH)
|
||||
@ -59,7 +59,7 @@ unsigned short glerminal_get(unsigned char x, unsigned char y, unsigned short la
|
||||
* @param x_offset offset of the cell on the x axis in cells
|
||||
* @param y_offset offset of the cell on the y axis in cells
|
||||
*/
|
||||
void glerminal_offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset);
|
||||
void glerminal_offset(int x, int y, int layer, float x_offset, float y_offset);
|
||||
|
||||
/**
|
||||
* @brief Set a cell's color
|
||||
@ -68,7 +68,7 @@ void glerminal_offset(unsigned char x, unsigned char y, unsigned char layer, flo
|
||||
* @param layer layer of the cell in the range [0, LAYER_COUNT)
|
||||
* @param color The new color
|
||||
*/
|
||||
void glerminal_color(unsigned char x, unsigned char y, unsigned char layer, unsigned int color);
|
||||
void glerminal_color(int x, int y, int layer, unsigned int color);
|
||||
/**
|
||||
* @brief Set a cell's scale
|
||||
* @param x position of the cell in the range [0, GRID_WIDTH)
|
||||
@ -76,7 +76,7 @@ void glerminal_color(unsigned char x, unsigned char y, unsigned char layer, unsi
|
||||
* @param layer layer of the cell in the range [0, LAYER_COUNT)
|
||||
* @param scale The new scale
|
||||
*/
|
||||
void glerminal_scale(unsigned char x, unsigned char y, unsigned char layer, float scale);
|
||||
void glerminal_scale(int x, int y, int layer, float scale);
|
||||
|
||||
/**
|
||||
* @brief Load sprites from a png file
|
||||
|
@ -38,9 +38,9 @@ namespace
|
||||
|
||||
int lglerminal_set(lua_State* L)
|
||||
{
|
||||
const unsigned char x = luaL_checkinteger(L, 1);
|
||||
const unsigned char y = luaL_checkinteger(L, 2);
|
||||
const unsigned char layer = luaL_checkinteger(L, 3) - 1;
|
||||
const int x = luaL_checkinteger(L, 1);
|
||||
const int y = luaL_checkinteger(L, 2);
|
||||
const int layer = luaL_checkinteger(L, 3) - 1;
|
||||
const unsigned short sprite = luaL_checkinteger(L, 4) - 1;
|
||||
glerminal_set(x, y, layer, sprite);
|
||||
|
||||
@ -49,9 +49,9 @@ namespace
|
||||
|
||||
int lglerminal_get(lua_State* L)
|
||||
{
|
||||
const unsigned char x = luaL_checkinteger(L, 1);
|
||||
const unsigned char y = luaL_checkinteger(L, 2);
|
||||
const unsigned char layer = luaL_checkinteger(L, 3) - 1;
|
||||
const int x = luaL_checkinteger(L, 1);
|
||||
const int y = luaL_checkinteger(L, 2);
|
||||
const int layer = luaL_checkinteger(L, 3) - 1;
|
||||
lua_pushnumber(L, glerminal_get(x, y, layer) + 1);
|
||||
|
||||
return 1;
|
||||
@ -59,9 +59,9 @@ namespace
|
||||
|
||||
int lglerminal_offset(lua_State* L)
|
||||
{
|
||||
const unsigned char x = luaL_checkinteger(L, 1);
|
||||
const unsigned char y = luaL_checkinteger(L, 2);
|
||||
const unsigned char layer = luaL_checkinteger(L, 3) - 1;
|
||||
const int x = luaL_checkinteger(L, 1);
|
||||
const int y = luaL_checkinteger(L, 2);
|
||||
const int layer = luaL_checkinteger(L, 3) - 1;
|
||||
const float ox = luaL_checknumber(L, 4);
|
||||
const float oy = luaL_checknumber(L, 5);
|
||||
glerminal_offset(x, y, layer, ox, oy);
|
||||
@ -71,9 +71,9 @@ namespace
|
||||
|
||||
int lglerminal_layer_color(lua_State* L)
|
||||
{
|
||||
const unsigned char x = luaL_checkinteger(L, 1);
|
||||
const unsigned char y = luaL_checkinteger(L, 2);
|
||||
const unsigned char layer = luaL_checkinteger(L, 3) - 1;
|
||||
const int x = luaL_checkinteger(L, 1);
|
||||
const int y = luaL_checkinteger(L, 2);
|
||||
const int layer = luaL_checkinteger(L, 3) - 1;
|
||||
const float r = luaL_checknumber(L, 4);
|
||||
const float g = luaL_checknumber(L, 5);
|
||||
const float b = luaL_checknumber(L, 6);
|
||||
@ -87,14 +87,14 @@ namespace
|
||||
if (ri > 255) { ri = 255; }
|
||||
if (ri < 0) { ri = 0; }
|
||||
|
||||
if (gi > 255) { ri = 255; }
|
||||
if (gi < 0) { ri = 0; }
|
||||
if (gi > 255) { gi = 255; }
|
||||
if (gi < 0) { gi = 0; }
|
||||
|
||||
if (bi > 255) { ri = 255; }
|
||||
if (bi < 0) { ri = 0; }
|
||||
if (bi > 255) { bi = 255; }
|
||||
if (bi < 0) { bi = 0; }
|
||||
|
||||
if (ai > 255) { ri = 255; }
|
||||
if (ai < 0) { ri = 0; }
|
||||
if (ai > 255) { ai = 255; }
|
||||
if (ai < 0) { ai = 0; }
|
||||
|
||||
const unsigned int color = ri | (gi << 8) | (bi << 16) | (ai << 24);
|
||||
|
||||
@ -105,9 +105,9 @@ namespace
|
||||
|
||||
int lglerminal_layer_scale(lua_State* L)
|
||||
{
|
||||
const unsigned char x = luaL_checkinteger(L, 1);
|
||||
const unsigned char y = luaL_checkinteger(L, 2);
|
||||
const unsigned char layer = luaL_checkinteger(L, 3) - 1;
|
||||
const int x = luaL_checkinteger(L, 1);
|
||||
const int y = luaL_checkinteger(L, 2);
|
||||
const int layer = luaL_checkinteger(L, 3) - 1;
|
||||
const float scale = luaL_checknumber(L, 4);
|
||||
glerminal_scale(x, y, layer, scale);
|
||||
|
||||
|
@ -47,11 +47,11 @@ namespace glerminal
|
||||
|
||||
void flush();
|
||||
|
||||
void set(unsigned char x, unsigned char y, unsigned char layer, unsigned short sprite);
|
||||
unsigned short get(unsigned char x, unsigned char y, unsigned char layer) const;
|
||||
void offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset);
|
||||
void color(unsigned char x, unsigned char y, unsigned char layer, unsigned int color);
|
||||
void scale(unsigned char x, unsigned char y, unsigned char layer, float scale);
|
||||
void set(int x, int y, int layer, unsigned short sprite);
|
||||
unsigned short get(int x, int y, int layer) const;
|
||||
void offset(int x, int y, int layer, float x_offset, float y_offset);
|
||||
void color(int x, int y, int layer, unsigned int color);
|
||||
void scale(int x,int y, int layer, float scale);
|
||||
void load_atlas(unsigned char w, unsigned char h, const unsigned int* data);
|
||||
bool load_sound(const char* name);
|
||||
void play_sound(const char* name);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ONLY_PNG
|
||||
#define STBI_MAX_DIMENSIONS 512
|
||||
#define STBI_MAX_DIMENSIONS 2048
|
||||
#include "glerminal-private.h"
|
||||
|
||||
#define GRID_SIZE_UNIFORM_NAME "grid_size"
|
||||
@ -285,26 +285,21 @@ namespace glerminal
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glfwSwapInterval(0);
|
||||
glfwSwapBuffers(m_window);
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glfwSwapInterval(1);
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
|
||||
void glerminal::set(unsigned char x, unsigned char y, unsigned char layer, unsigned short sprite)
|
||||
void glerminal::set(int x, int y, int layer, unsigned short sprite)
|
||||
{
|
||||
if (x < GRID_WIDTH + 2 && y < GRID_HEIGHT + 2 && layer < LAYER_COUNT)
|
||||
if (x >= 0 && x < GRID_WIDTH + 2 && y >= 0 && y < GRID_HEIGHT + 2 && layer >= 0 && layer < LAYER_COUNT)
|
||||
{
|
||||
m_cells[x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2] = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short glerminal::get(unsigned char x, unsigned char y, unsigned char layer) const
|
||||
unsigned short glerminal::get(int x, int y, int layer) const
|
||||
{
|
||||
if (x < GRID_WIDTH + 2 && y < GRID_HEIGHT + 2 && layer < LAYER_COUNT)
|
||||
if (x >= 0 && x < GRID_WIDTH + 2 && y >= 0 && y < GRID_HEIGHT + 2 && layer >= 0 && layer < LAYER_COUNT)
|
||||
{
|
||||
return m_cells[x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2];
|
||||
}
|
||||
@ -314,18 +309,18 @@ namespace glerminal
|
||||
}
|
||||
}
|
||||
|
||||
void glerminal::offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset)
|
||||
void glerminal::offset(int x, int y, int layer, float x_offset, float y_offset)
|
||||
{
|
||||
if (x < GRID_WIDTH + 2 && y < GRID_HEIGHT + 2 && layer < LAYER_COUNT)
|
||||
if (x >= 0 && x < GRID_WIDTH + 2 && y >= 0 && y < GRID_HEIGHT + 2 && layer >= 0 && layer < LAYER_COUNT)
|
||||
{
|
||||
m_offsets[2 * (x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2) + 0] = x_offset;
|
||||
m_offsets[2 * (x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2) + 1] = y_offset;
|
||||
}
|
||||
}
|
||||
|
||||
void glerminal::color(unsigned char x, unsigned char y, unsigned char layer, unsigned int color)
|
||||
void glerminal::color(int x, int y, int layer, unsigned int color)
|
||||
{
|
||||
if (x < GRID_WIDTH + 2 && y < GRID_HEIGHT + 2 && layer < LAYER_COUNT)
|
||||
if (x >= 0 && x < GRID_WIDTH + 2 && y >= 0 && y < GRID_HEIGHT + 2 && layer >= 0 && layer < LAYER_COUNT)
|
||||
{
|
||||
m_colors[4 * (x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2) + 0] = (color >> 0) & 0xFF;
|
||||
m_colors[4 * (x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2) + 1] = (color >> 8) & 0xFF;
|
||||
@ -334,9 +329,12 @@ namespace glerminal
|
||||
}
|
||||
}
|
||||
|
||||
void glerminal::scale(unsigned char x, unsigned char y, unsigned char layer, float scale)
|
||||
void glerminal::scale(int x, int y, int layer, float scale)
|
||||
{
|
||||
m_scales[x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2] = scale;
|
||||
if (x >= 0 && x < GRID_WIDTH + 2 && y >= 0 && y < GRID_HEIGHT + 2 && layer >= 0 && layer < LAYER_COUNT)
|
||||
{
|
||||
m_scales[x + y * (GRID_WIDTH + 2) + layer * GRID_AREA_2] = scale;
|
||||
}
|
||||
}
|
||||
|
||||
void glerminal::load_atlas(unsigned char w, unsigned char h, const unsigned int* data)
|
||||
@ -505,7 +503,7 @@ namespace glerminal
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glViewport(0, 0, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
|
||||
// -- setup vertex data --
|
||||
// create vertex buffer object
|
||||
@ -735,7 +733,6 @@ namespace glerminal
|
||||
update_sprites();
|
||||
|
||||
glBindTextureUnit(2, m_sprites_texture);
|
||||
const auto err = glGetError();
|
||||
|
||||
// -- setup framebuffer --
|
||||
glGenFramebuffers(1, &m_framebuffer);
|
||||
@ -753,7 +750,7 @@ namespace glerminal
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, SCREEN_WIDTH, SCREEN_HEIGHT, LAYER_COUNT);
|
||||
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE, LAYER_COUNT);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_framebuffer_backing_texture, 0);
|
||||
|
||||
glBindTextureUnit(1, m_framebuffer_backing_texture);
|
||||
@ -774,7 +771,7 @@ namespace glerminal
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_screen_framebuffer_backing_texture, 0);
|
||||
}
|
||||
|
||||
@ -908,39 +905,39 @@ void glerminal_flush()
|
||||
GLERMINAL_G->flush();
|
||||
}
|
||||
|
||||
void glerminal_set(unsigned char x, unsigned char y, unsigned char layer, unsigned short sprite)
|
||||
void glerminal_set(int x, int y, int layer, unsigned short sprite)
|
||||
{
|
||||
if (!GLERMINAL_G) { return; }
|
||||
|
||||
GLERMINAL_G->set(x, y, layer, sprite);
|
||||
GLERMINAL_G->set(x + 1, y + 1, layer, sprite);
|
||||
}
|
||||
|
||||
unsigned short glerminal_get(unsigned char x, unsigned char y, unsigned short layer)
|
||||
unsigned short glerminal_get(int x, int y, int layer)
|
||||
{
|
||||
if (!GLERMINAL_G) { return 0; }
|
||||
|
||||
return GLERMINAL_G->get(x, y, layer);
|
||||
return GLERMINAL_G->get(x + 1, y + 1, layer);
|
||||
}
|
||||
|
||||
void glerminal_offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset)
|
||||
void glerminal_offset(int x, int y, int layer, float x_offset, float y_offset)
|
||||
{
|
||||
if (!GLERMINAL_G) { return; }
|
||||
|
||||
GLERMINAL_G->offset(x, y, layer, x_offset, y_offset);
|
||||
GLERMINAL_G->offset(x + 1, y + 1, layer, x_offset, y_offset);
|
||||
}
|
||||
|
||||
void glerminal_color(unsigned char x, unsigned char y, unsigned char layer, unsigned int color)
|
||||
void glerminal_color(int x, int y, int layer, unsigned int color)
|
||||
{
|
||||
if (!GLERMINAL_G) { return; }
|
||||
|
||||
GLERMINAL_G->color(x, y, layer, color);
|
||||
GLERMINAL_G->color(x + 1, y + 1, layer, color);
|
||||
}
|
||||
|
||||
void glerminal_scale(unsigned char x, unsigned char y, unsigned char layer, float scale)
|
||||
void glerminal_scale(int x, int y, int layer, float scale)
|
||||
{
|
||||
if (!GLERMINAL_G) { return; }
|
||||
|
||||
GLERMINAL_G->scale(x, y, layer, scale);
|
||||
GLERMINAL_G->scale(x + 1, y + 1, layer, scale);
|
||||
}
|
||||
|
||||
int glerminal_load_sprites_file(const char* filename)
|
||||
|
@ -15,7 +15,7 @@ namespace
|
||||
|
||||
for (int i = 0; i < GRID_HEIGHT; i++)
|
||||
{
|
||||
glerminal_set(i + 1, i + 1, 0, 1);
|
||||
glerminal_set(i, i, 0, 1);
|
||||
}
|
||||
|
||||
glerminal_flush();
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned char pixels[(GRID_WIDTH * CELL_SCALE * 8) * (GRID_HEIGHT * CELL_SCALE * 8) * 3];
|
||||
unsigned char pixels[(GRID_WIDTH * 8) * (GRID_HEIGHT * 8) * 3];
|
||||
}
|
||||
|
||||
void glerminal_test_save_image()
|
||||
@ -21,5 +21,5 @@ void glerminal_test_save_image()
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
stbi_flip_vertically_on_write(true);
|
||||
stbi_write_png("image.png", GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, 3, pixels, GRID_WIDTH * CELL_SCALE * 8 * 3);
|
||||
stbi_write_png("image.png", GRID_WIDTH * 8, GRID_HEIGHT * 8, 3, pixels, GRID_WIDTH * 8 * 3);
|
||||
}
|
Loading…
Reference in New Issue
Block a user