WIP: Rewrite with LLGL

This commit is contained in:
n0ffie 2025-04-13 17:54:14 +02:00
parent 002d97ee27
commit f337ff9f0d
24 changed files with 377 additions and 390 deletions

View file

@ -6,20 +6,33 @@ function(add_cigui_example NAME)
find_files(EXAMPLE_${NAME}_SOURCES "${NAME}/src" cpp c cxx hpp h hxx inl)
add_executable(EXAMPLE_${NAME} ${EXAMPLE_${NAME}_SOURCES})
target_link_libraries(EXAMPLE_${NAME} PRIVATE cigui)
link_libraries_in_directory(EXAMPLE_${NAME} ${LLGL_LIB_PATH})
target_include_directories(EXAMPLE_${NAME} PRIVATE ${LLGL_INCLUDE_PATH})
set_target_properties(EXAMPLE_${NAME} PROPERTIES OUTPUT_NAME "${NAME}")
# Copy SFML DLLs to output directory on Windows when building shared
if(WIN32 AND CIGUI_BUILD_SHARED)
add_custom_command(TARGET EXAMPLE_${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-graphics>
$<TARGET_FILE:sfml-window>
$<TARGET_FILE:sfml-system>
$<TARGET_FILE:cigui>
$<TARGET_FILE_DIR:EXAMPLE_${NAME}>
)
endif()
add_custom_command(TARGET EXAMPLE_${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${LLGL_BIN_PATH}
$<TARGET_FILE_DIR:EXAMPLE_${NAME}>
COMMENT "Coppied LLGL binaries to example directory"
)
add_custom_command(TARGET EXAMPLE_${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/${NAME}/src/shader
$<TARGET_FILE_DIR:EXAMPLE_${NAME}>/shader
COMMENT "Coppied shaders to example directory"
)
# Copy DLLs to output directory on Windows when building shared
if(WIN32 AND CIGUI_BUILD_SHARED)
add_custom_command(TARGET EXAMPLE_${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:cigui>
$<TARGET_FILE_DIR:EXAMPLE_${NAME}>
)
endif()
endfunction()
# Basic example

View file

@ -1,73 +1,6 @@
//
// Created by n0ffie on 08/04/25.
//
#include <cigui/core/App.hpp>
#include <iostream>
int main() {
cig::App::GetInstance().Run();
}
#include <cigui/cigui.hpp>
#include <cigui/utils/List.hpp>
// WIP - not working yet
// Layout unsupported
struct HStack final : cig::View {
using Stack = cig::List<View*>;
Stack views;
void append(View* view) { views.push_back(view); }
bool update() override {
bool needs_redraw = false;
views.iterate([this, &needs_redraw](View*& view) { if (view->update()) needs_redraw = true; });
return needs_redraw;
}
View* body() override {
views.iterate<>([this](View*& view) { view->draw(); });
views.iterate([this](View*& view) {
this->m_RenderCalls.expand(view->renderCalls());
});
return nullptr;
}
};
struct NewView final : cig::View {
View* body() override {
auto List = new HStack();
auto view = new cig::Rectangle({400, 400});
view->setBorderColor(sf::Color::Red)->setBorderThickness(5)->setColor(sf::Color::Green);
List->append(view);
view = new cig::Rectangle({100, 100});
view->setBorderColor(sf::Color::Blue)->setBorderThickness(5)->setColor(sf::Color::Yellow);
List->append(view);
return List;
}
};
int main(int argc, char** argv) {
sf::RenderWindow window(sf::VideoMode({800, 600}), "Hello World!");
const auto view = new NewView();
const cig::Renderer renderer(view);
while (window.isOpen()) {
while (const std::optional event = window.pollEvent())
{
if (event->is<sf::Event::Closed>())
{
window.close();
}
}
renderer.update();
window.clear();
renderer.render(window, sf::RenderStates());
window.display();
}
return 0;
}

View file

@ -0,0 +1,18 @@
// GLSL shader version 1.30 (for OpenGL 3.1)
#version 130
#ifdef GL_ES
precision mediump float;
#endif
// Fragment input from the vertex shader
in vec3 vertexColor;
// Fragment output color
out vec4 fragColor;
// Fragment shader main function
void main()
{
fragColor = vec4(vertexColor, 1);
}

View file

@ -0,0 +1,28 @@
// HLSL shader version 4.0 (for Direct3D 11/ 12)
struct InputVS
{
float2 position : POSITION;
float3 color : COLOR;
};
struct OutputVS
{
float4 position : SV_Position;
float3 color : COLOR;
};
// Vertex shader main function
OutputVS VS(InputVS inp)
{
OutputVS outp;
outp.position = float4(inp.position, 0, 1);
outp.color = inp.color;
return outp;
}
// Pixel shader main function
float4 PS(OutputVS inp) : SV_Target
{
return float4(inp.color, 1);
};

View file

@ -0,0 +1,20 @@
// GLSL shader version 1.30 (for OpenGL 3.1)
#version 130
#ifdef GL_ES
precision mediump float;
#endif
// Vertex attributes (these names must match our vertex format attributes)
in vec2 position;
in vec3 color;
// Vertex output to the fragment shader
out vec3 vertexColor;
// Vertex shader main function
void main()
{
gl_Position = vec4(position, 0, 1);
vertexColor = color;
}