From bba9c3c2ba274d10b85ef4da8416ed2a72b913bc Mon Sep 17 00:00:00 2001 From: joppe Date: Sat, 27 Jan 2024 18:14:30 +0100 Subject: [PATCH] Can compile alt.frag shader. --- MLX42/CMakeLists.txt | 12 ++++++++ MLX42/include/MLX42/MLX42_Int.h | 3 +- MLX42/shaders/alt.frag | 29 +++++++++++++++++++ MLX42/src/mlx_init.c | 7 +++-- MLX42/tools/compile_shader_alt.sh | 46 +++++++++++++++++++++++++++++++ Makefile | 2 +- src/game/render_viewport.c | 2 +- 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 MLX42/shaders/alt.frag create mode 100755 MLX42/tools/compile_shader_alt.sh diff --git a/MLX42/CMakeLists.txt b/MLX42/CMakeLists.txt index 1e14414..f4eb52e 100644 --- a/MLX42/CMakeLists.txt +++ b/MLX42/CMakeLists.txt @@ -36,6 +36,7 @@ add_definitions(-D LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS) if(UNIX) set(CCSHADER ${PROJECT_SOURCE_DIR}/tools/compile_shader.sh) + set(CCSHADERALT ${PROJECT_SOURCE_DIR}/tools/compile_shader_alt.sh) add_compile_options( -Wextra -Wall @@ -85,6 +86,16 @@ add_custom_command( USES_TERMINAL ) +add_custom_command( + COMMENT "Building alt fragment shader" + DEPENDS ${PROJECT_SOURCE_DIR}/shaders/alt.frag + OUTPUT mlx_alt_frag_shader.c + COMMAND ${CCSHADERALT} ${PROJECT_SOURCE_DIR}/shaders/alt.frag > mlx_alt_frag_shader.c + VERBATIM + PRE_BUILD + USES_TERMINAL +) + # Sources # ----------------------------------------------------------------------------- add_library(mlx42 STATIC @@ -119,6 +130,7 @@ add_library(mlx42 STATIC mlx_vert_shader.c mlx_frag_shader.c + mlx_alt_frag_shader.c ) target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/MLX42/include/MLX42/MLX42_Int.h b/MLX42/include/MLX42/MLX42_Int.h index f59c8ef..aa2396f 100644 --- a/MLX42/include/MLX42/MLX42_Int.h +++ b/MLX42/include/MLX42/MLX42_Int.h @@ -6,7 +6,7 @@ /* By: W2Wizard +#+ */ /* +#+ */ /* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */ -/* Updated: 2024/01/20 00:49:21 by joppe ######## odam.nl */ +/* Updated: 2024/01/27 18:09:12 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -61,6 +61,7 @@ extern const char* vert_shader; extern const char* frag_shader; +extern const char* alt_frag_shader; // Flag to indicate if the render queue has to be sorted. extern bool sort_queue; diff --git a/MLX42/shaders/alt.frag b/MLX42/shaders/alt.frag new file mode 100644 index 0000000..a170a42 --- /dev/null +++ b/MLX42/shaders/alt.frag @@ -0,0 +1,29 @@ +#version 330 core + +in vec2 TexCoord; +flat in int TexIndex; + +out vec4 FragColor; + +uniform sampler2D Texture0; +uniform sampler2D Texture1; +uniform sampler2D Texture2; +uniform sampler2D Texture3; +uniform sampler2D Texture4; +uniform sampler2D Texture5; +uniform sampler2D Texture6; +uniform sampler2D Texture7; +uniform sampler2D Texture8; +uniform sampler2D Texture9; +uniform sampler2D Texture10; +uniform sampler2D Texture11; +uniform sampler2D Texture12; +uniform sampler2D Texture13; +uniform sampler2D Texture14; +uniform sampler2D Texture15; + +void main() +{ + vec4 outColor = vec4(1.0, 1.0, 1.0, 1.0); + FragColor = outColor; +} diff --git a/MLX42/src/mlx_init.c b/MLX42/src/mlx_init.c index f8a41a9..f663753 100644 --- a/MLX42/src/mlx_init.c +++ b/MLX42/src/mlx_init.c @@ -1,16 +1,17 @@ /* ************************************************************************** */ /* */ /* :::::::: */ -/* mlx_init.c :+: :+: */ +/* mlx_init.c :+: :+: */ /* +:+ */ /* By: W2Wizard +#+ */ /* +#+ */ /* Created: 2021/12/28 00:24:30 by W2Wizard #+# #+# */ -/* Updated: 2023/06/08 18:16:19 by XEDGit ######## odam.nl */ +/* Updated: 2024/01/27 18:09:20 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ #include "MLX42/MLX42_Int.h" +#include //= Private =// @@ -128,6 +129,8 @@ static bool mlx_init_render(mlx_t* mlx) glAttachShader(mlxctx->shaderprogram, fshader); glLinkProgram(mlxctx->shaderprogram); + printf("ALT SHADER [%s]\n", alt_frag_shader); + glDeleteShader(vshader); glDeleteShader(fshader); glDetachShader(mlxctx->shaderprogram, vshader); diff --git a/MLX42/tools/compile_shader_alt.sh b/MLX42/tools/compile_shader_alt.sh new file mode 100755 index 0000000..85d2b60 --- /dev/null +++ b/MLX42/tools/compile_shader_alt.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. +# See README in the root project for more information. +# ----------------------------------------------------------------------------- + +# If no arguments have been given, exit with error code 1 +if [ "$#" -ne 1 ]; then + echo "ERROR: missing arguments, use as follows: $0 " 1>&2 + exit 1 +fi + +# If file cannot be found, exit with error code 2 +if [ ! -f "$1" ]; then + echo "ERROR: shader file not found: $1" 1>&2 + exit 2 +fi + +SHADERTYPE="${1##*.}" + +echo alt_${SHADERTYPE}_shader >> poep.txt + +echo "// -----------------------------------------------------------------------------" +echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. " +echo "// See README in the root project for more information. " +echo "// -----------------------------------------------------------------------------" +echo "" +echo "// If you wish to modify this file edit the .vert or .frag file!" +echo "" +echo "#include \"MLX42/MLX42_Int.h\"" +echo "" +echo "const char* alt_${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\"" +{ + # Skip over first line + read + while IFS= read -r LINE; do + if [ ! "${LINE}" = "" ]; then + if [ "${LINE}" = "}" ]; then + echo " \"${LINE}\";" + else + echo " \"${LINE}\"" + fi + fi + done +} < "$1" +exit 0 diff --git a/Makefile b/Makefile index d3a91c8..8118c33 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ RUN_CMD := ./$(NAME) test_maps/valid_tex.cub # CFLAGS += -Wall -Wextra -Werror # CFLAGS += -Wall -Wextra -CFLAGS += -g -fsanitize=address +# CFLAGS += -g -fsanitize=address # CFLAGS += -g # CFLAGS += -Ofast -flto -march=native diff --git a/src/game/render_viewport.c b/src/game/render_viewport.c index 666a5bd..8cf25a3 100644 --- a/src/game/render_viewport.c +++ b/src/game/render_viewport.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */ -/* Updated: 2024/01/20 01:18:16 by joppe ######## odam.nl */ +/* Updated: 2024/01/27 16:54:11 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */