Compare commits
2 Commits
b2164b76cf
...
c8e7a28837
Author | SHA1 | Date | |
---|---|---|---|
c8e7a28837 | |||
b4427a0c88 |
@ -6,6 +6,7 @@ project(glerminal
|
|||||||
)
|
)
|
||||||
|
|
||||||
option(GLERMINAL_OPENGL_DEBUG_CONTEXT "" OFF)
|
option(GLERMINAL_OPENGL_DEBUG_CONTEXT "" OFF)
|
||||||
|
option(GLERMINAL_TEST "" OFF)
|
||||||
set(GLERMINAL_GRID_WIDTH 40 CACHE STRING "")
|
set(GLERMINAL_GRID_WIDTH 40 CACHE STRING "")
|
||||||
set(GLERMINAL_GRID_HEIGHT 25 CACHE STRING "")
|
set(GLERMINAL_GRID_HEIGHT 25 CACHE STRING "")
|
||||||
set(GLERMINAL_LAYER_COUNT 64 CACHE STRING "")
|
set(GLERMINAL_LAYER_COUNT 64 CACHE STRING "")
|
||||||
@ -63,3 +64,7 @@ endif()
|
|||||||
if (PROJECT_IS_TOP_LEVEL)
|
if (PROJECT_IS_TOP_LEVEL)
|
||||||
add_subdirectory(examples examples)
|
add_subdirectory(examples examples)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (GLERMINAL_TEST)
|
||||||
|
add_subdirectory(tests tests)
|
||||||
|
endif()
|
@ -1,6 +1,7 @@
|
|||||||
#include <glerminal.h>
|
#include <glerminal.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,8 @@ namespace
|
|||||||
{
|
{
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
srand(0);
|
||||||
|
|
||||||
glerminal_load_sprites_file("resources/towers.png");
|
glerminal_load_sprites_file("resources/towers.png");
|
||||||
|
|
||||||
for (int i = 0; i < LAYER_COUNT; i++)
|
for (int i = 0; i < LAYER_COUNT; i++)
|
||||||
|
@ -18,6 +18,8 @@ typedef void (*glerminal_main_cb)(float dt);
|
|||||||
*/
|
*/
|
||||||
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main);
|
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main);
|
||||||
|
|
||||||
|
void glerminal_quit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update the displayed screen contents to the current state of the library
|
* @brief Update the displayed screen contents to the current state of the library
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef TERMG_PRIVATE_H
|
#ifndef GLERMINAL_PRIVATE_H
|
||||||
#define TERMG_PRIVATE_H
|
#define GLERMINAL_PRIVATE_H
|
||||||
|
|
||||||
#include "glerminal.h"
|
#include "glerminal.h"
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ namespace glerminal
|
|||||||
glerminal& operator=(glerminal&&) = delete;
|
glerminal& operator=(glerminal&&) = delete;
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
void quit();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
@ -98,4 +99,4 @@ namespace glerminal
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif//TERMG_PRIVATE_H
|
#endif//GLERMINAL_PRIVATE_H
|
@ -194,6 +194,11 @@ namespace glerminal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glerminal::quit()
|
||||||
|
{
|
||||||
|
glfwSetWindowShouldClose(m_window, GLFW_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
void glerminal::flush()
|
void glerminal::flush()
|
||||||
{
|
{
|
||||||
glNamedBufferData(m_sprites_instance_vbo, sizeof(m_cells), m_cells, GL_STREAM_DRAW);
|
glNamedBufferData(m_sprites_instance_vbo, sizeof(m_cells), m_cells, GL_STREAM_DRAW);
|
||||||
@ -664,6 +669,13 @@ void glerminal_run(glerminal_init_cb init, glerminal_main_cb main)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glerminal_quit()
|
||||||
|
{
|
||||||
|
if (!GLERMINAL_G) { return; }
|
||||||
|
|
||||||
|
GLERMINAL_G->quit();
|
||||||
|
}
|
||||||
|
|
||||||
void glerminal_flush()
|
void glerminal_flush()
|
||||||
{
|
{
|
||||||
if (!GLERMINAL_G) { return; }
|
if (!GLERMINAL_G) { return; }
|
||||||
|
56
tests/CMakeLists.txt
Normal file
56
tests/CMakeLists.txt
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
|
||||||
|
set(CMAKE_FOLDER tests)
|
||||||
|
|
||||||
|
add_library(test-common STATIC
|
||||||
|
${CMAKE_SOURCE_DIR}/source/glad/glad.h
|
||||||
|
|
||||||
|
test-common/test-common.h
|
||||||
|
test-common/stb_image_write.h
|
||||||
|
test-common/test-common.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(test-common
|
||||||
|
PUBLIC
|
||||||
|
test-common
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/source
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(test-common PRIVATE glerminal)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE
|
||||||
|
TEST_RESOURCES
|
||||||
|
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/resources/**.png
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(RESOURCE_FILE ${TEST_RESOURCES})
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_FILE}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_FILE}
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_FILE}
|
||||||
|
DEPENDS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_FILE}
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(GLOB_RECURSE
|
||||||
|
TEST_SOURCES
|
||||||
|
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
list(REMOVE_ITEM TEST_SOURCES test-common/test-common.cpp)
|
||||||
|
list(TRANSFORM TEST_RESOURCES PREPEND ${CMAKE_CURRENT_BINARY_DIR}/)
|
||||||
|
|
||||||
|
foreach(SOURCE_FILE ${TEST_SOURCES})
|
||||||
|
get_filename_component(SOURCE_FILENAME ${SOURCE_FILE} NAME_WLE)
|
||||||
|
add_executable(test-${SOURCE_FILENAME} WIN32 ${SOURCE_FILE} ${TEST_RESOURCES})
|
||||||
|
target_link_libraries(test-${SOURCE_FILENAME} PRIVATE glerminal test-common)
|
||||||
|
endforeach()
|
31
tests/basic.cpp
Normal file
31
tests/basic.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <glerminal.h>
|
||||||
|
|
||||||
|
#include <test-common.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
glerminal_load_sprites_file("resources/image.png");
|
||||||
|
|
||||||
|
for (int i = 0; i < GRID_HEIGHT; i++)
|
||||||
|
{
|
||||||
|
glerminal_set(i, i, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glerminal_flush();
|
||||||
|
|
||||||
|
glerminal_test_save_image();
|
||||||
|
|
||||||
|
glerminal_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainloop(float) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
glerminal_run(init, mainloop);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
tests/resources/image.png
(Stored with Git LFS)
Normal file
BIN
tests/resources/image.png
(Stored with Git LFS)
Normal file
Binary file not shown.
1724
tests/test-common/stb_image_write.h
Normal file
1724
tests/test-common/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load Diff
21
tests/test-common/test-common.cpp
Normal file
21
tests/test-common/test-common.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <test-common.h>
|
||||||
|
|
||||||
|
#include <glerminal.h>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include <stb_image_write.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
unsigned char pixels[1280 * 800 * 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
void glerminal_test_save_image()
|
||||||
|
{
|
||||||
|
glReadBuffer(GL_LEFT);
|
||||||
|
glReadPixels(0, 0, GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, 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, 1280 * 3);
|
||||||
|
}
|
6
tests/test-common/test-common.h
Normal file
6
tests/test-common/test-common.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef GLERMINAL_TEST_COMMON_H
|
||||||
|
#define GLERMINAL_TEST_COMMON_H
|
||||||
|
|
||||||
|
void glerminal_test_save_image();
|
||||||
|
|
||||||
|
#endif//GLERMINAL_TEST_COMMON_H
|
Loading…
Reference in New Issue
Block a user