Skip to content

Commit

Permalink
Can compile alt.frag shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
JopjeKnopje committed Jan 27, 2024
1 parent 9a89751 commit bba9c3c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
12 changes: 12 additions & 0 deletions MLX42/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion MLX42/include/MLX42/MLX42_Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions MLX42/shaders/alt.frag
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 5 additions & 2 deletions MLX42/src/mlx_init.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* mlx_init.c :+: :+: */
/* mlx_init.c :+: :+: */
/* +:+ */
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* 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 <stdio.h>

//= Private =//

Expand Down Expand Up @@ -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);
Expand Down
46 changes: 46 additions & 0 deletions MLX42/tools/compile_shader_alt.sh
Original file line number Diff line number Diff line change
@@ -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 <ShaderFile>" 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/game/render_viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit bba9c3c

Please sign in to comment.