Skip to content

Commit 77bf9ed

Browse files
author
nechaara
committed
Adding graphic lib to project
1 parent 2b9f1bc commit 77bf9ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+27411
-17
lines changed

MLX42/.gitattributes

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# See https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
2+
3+
# Set the default behavior, in case people don't have core.autocrlf set
4+
* text=auto
5+
6+
# Declare files that will always have a certain EOL
7+
*.sh text eol=lf
8+
shaders/** text eol=lf
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: "[BUG]"
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**NOTE**
11+
Before creating a bug report! Make sure you git pull from master and check if the bug still exists!
12+
13+
**Describe the bug**
14+
A clear and concise description of what the bug is.
15+
16+
**To Reproduce**
17+
Steps to reproduce the behavior:
18+
1. Go to '...'
19+
2. Click on '...'
20+
3. Scroll down to '...'
21+
4. See error
22+
23+
**Expected behavior**
24+
A clear and concise description of what you expected to happen.
25+
26+
**Screenshots**
27+
If applicable, add screenshots to help explain your problem.
28+
29+
**Desktop (please complete the following information):**
30+
- OS: [e.g. MacOS]
31+
- Version: [e.g. BigSur]
32+
33+
**Additional context**
34+
Add any other context about the problem here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: "[REQUEST]"
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

MLX42/.github/workflows/ci.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -----------------------------------------------------------------------------
2+
# Codam Coding College, Amsterdam @ 2022-2023-2023 by W2Wizard.
3+
# See README in the root project for more information.
4+
# -----------------------------------------------------------------------------
5+
6+
name: Build
7+
8+
#=============================================================================#
9+
10+
on:
11+
push:
12+
branches: [ master ]
13+
pull_request:
14+
branches: [ master ]
15+
16+
#=============================================================================#
17+
18+
jobs:
19+
20+
# Tests
21+
#=============================================================================#
22+
23+
unit-test:
24+
timeout-minutes: 10
25+
runs-on: ubuntu-latest
26+
needs: build
27+
env:
28+
DISPLAY: ":99"
29+
30+
steps:
31+
- name: Clone repository
32+
uses: actions/checkout@v3
33+
34+
- name: Install Dependencies
35+
run: |
36+
sudo apt-get update -qq
37+
sudo apt-get install -y -qq xorg-dev xvfb
38+
39+
- name: Setup virtual screen
40+
run: Xvfb $DISPLAY -screen 0 1280x1024x24 &
41+
42+
- name: Build MLX42 & tests
43+
run: cmake -DBUILD_TESTS=YES -B ${{github.workspace}}/build && cmake --build ${{github.workspace}}/build --parallel
44+
45+
- name: Run tests
46+
run: ctest --output-on-failure --test-dir ${{github.workspace}}/build
47+
# Unix
48+
#=============================================================================#
49+
50+
build:
51+
timeout-minutes: 10
52+
runs-on: ${{ matrix.os }}
53+
strategy:
54+
matrix:
55+
os: [ubuntu-latest, macos-latest, windows-latest]
56+
57+
steps:
58+
- name: Clone repository
59+
uses: actions/checkout@v3
60+
61+
# Windows will just fetch glfw with cmake automatically.
62+
# This avoids doing extra work like installing a package manager.
63+
- name: Install Dependencies
64+
if: matrix.os != 'windows-latest'
65+
run: |
66+
set -x
67+
if [ "$RUNNER_OS" == "Linux" ]; then
68+
sudo apt-get update -qq
69+
sudo apt-get install -y -qq xorg-dev
70+
elif [ "$RUNNER_OS" == "macOS" ]; then
71+
brew update
72+
brew install glfw
73+
fi
74+
75+
- name: Build
76+
run: cmake -B build && cmake --build build --parallel
77+
78+
#=============================================================================#

MLX42/.gitignore

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# Misc
55+
main.c
56+
temp/
57+
.vscode/
58+
lib/glfw/
59+
.DS_Store
60+
61+
# Special shader files
62+
mlx_*_shader.c
63+
build/
64+
main.c
65+
test
66+
67+
# Automatic downloaded deps
68+
_deps/

MLX42/CMakeLists.txt

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# -----------------------------------------------------------------------------
2+
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
3+
# See README in the root project for more information.
4+
# -----------------------------------------------------------------------------
5+
6+
# CMake specifications
7+
# -----------------------------------------------------------------------------
8+
cmake_minimum_required (VERSION 3.18.0)
9+
project(mlx42 VERSION 2.3.3)
10+
message(STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION}")
11+
12+
# Variables
13+
# -----------------------------------------------------------------------------
14+
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
15+
set(TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)
16+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
17+
set(CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
18+
set(CMAKE_C_STANDARD 11)
19+
set(CMAKE_C_EXTENSIONS OFF)
20+
set(CMAKE_C_STANDARD_REQUIRED ON)
21+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
22+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
23+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
24+
25+
# Options
26+
set(DEBUG OFF CACHE BOOL "Build MLX42 in debug mode, enabling assertions")
27+
set(GLFW_FETCH ON CACHE BOOL "Clone and install GLFW")
28+
set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the lib")
29+
30+
# Compile Options
31+
# -----------------------------------------------------------------------------
32+
33+
# Reduce the size of LodePNG, we don't need these things.
34+
add_definitions(-D LODEPNG_NO_COMPILE_ENCODER)
35+
add_definitions(-D LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS)
36+
37+
if(UNIX)
38+
set(CCSHADER ${PROJECT_SOURCE_DIR}/tools/compile_shader.sh)
39+
add_compile_options(
40+
-Wextra
41+
-Wall
42+
-Werror
43+
-Wunreachable-code
44+
45+
# Some low priority warnings that are annoying.
46+
-Wno-char-subscripts
47+
-Wno-sign-compare
48+
-Wno-unused-parameter
49+
-Wno-missing-field-initializers
50+
)
51+
if(DEBUG)
52+
message(STATUS "Building in DEBUG mode")
53+
add_compile_options(-g)
54+
else()
55+
message(STATUS "Building in RELEASE mode")
56+
add_definitions(-D NDEBUG)
57+
add_compile_options(-Ofast)
58+
endif(DEBUG)
59+
else()
60+
# TODO: Figure out what we need for windows.
61+
set(CCSHADER ${PROJECT_SOURCE_DIR}/tools/compile_shader.bat)
62+
endif()
63+
64+
# Build specific files
65+
# @see https://cmake.org/cmake/help/latest/command/add_custom_command.html
66+
# -----------------------------------------------------------------------------
67+
68+
add_custom_command(
69+
COMMENT "Building fragment shader"
70+
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.frag
71+
OUTPUT mlx_frag_shader.c
72+
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.frag > mlx_frag_shader.c
73+
VERBATIM
74+
PRE_BUILD
75+
USES_TERMINAL
76+
)
77+
78+
add_custom_command(
79+
COMMENT "Building vertex shader"
80+
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.vert
81+
OUTPUT mlx_vert_shader.c
82+
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.vert > mlx_vert_shader.c
83+
VERBATIM
84+
PRE_BUILD
85+
USES_TERMINAL
86+
)
87+
88+
# Sources
89+
# -----------------------------------------------------------------------------
90+
add_library(mlx42 STATIC
91+
92+
# Root
93+
${SOURCE_DIR}/mlx_cursor.c
94+
${SOURCE_DIR}/mlx_exit.c
95+
${SOURCE_DIR}/mlx_images.c
96+
${SOURCE_DIR}/mlx_init.c
97+
${SOURCE_DIR}/mlx_keys.c
98+
${SOURCE_DIR}/mlx_loop.c
99+
${SOURCE_DIR}/mlx_monitor.c
100+
${SOURCE_DIR}/mlx_mouse.c
101+
${SOURCE_DIR}/mlx_put_pixel.c
102+
${SOURCE_DIR}/mlx_window.c
103+
104+
# Utils
105+
${SOURCE_DIR}/utils/mlx_error.c
106+
${SOURCE_DIR}/utils/mlx_list.c
107+
${SOURCE_DIR}/utils/mlx_utils.c
108+
${SOURCE_DIR}/utils/mlx_compare.c
109+
110+
# Textures
111+
${SOURCE_DIR}/font/mlx_font.c
112+
${SOURCE_DIR}/textures/mlx_png.c
113+
${SOURCE_DIR}/textures/mlx_texture.c
114+
${SOURCE_DIR}/textures/mlx_xpm42.c
115+
116+
# Libs
117+
lib/png/lodepng.c
118+
lib/glad/glad.c
119+
120+
mlx_vert_shader.c
121+
mlx_frag_shader.c
122+
)
123+
target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
124+
125+
# Dependencies
126+
# -----------------------------------------------------------------------------
127+
128+
find_package(glfw3)
129+
find_package(OpenGL REQUIRED)
130+
131+
target_link_libraries(mlx42 OpenGL::GL)
132+
if (NOT glfw3_FOUND AND GLFW_FETCH)
133+
message(STATUS "Install GLFW to suppress this message")
134+
message(STATUS "Please wait, fetching GLFW ...")
135+
include(${CMAKE_DIR}/LinkGLFW.cmake)
136+
LinkGLFW(mlx42)
137+
elseif(NOT glfw3_FOUND AND NOT GLFW_FETCH)
138+
message(FATAL_ERROR "Unable to build: GLFW can't be found nor fetched.")
139+
endif()
140+
141+
if (glfw3_FOUND)
142+
target_link_libraries(mlx42 ${GLFW3_LIBRARY})
143+
endif()
144+
if(APPLE)
145+
target_link_libraries(mlx42 "-framework Cocoa" "-framework IOKit")
146+
endif()
147+
148+
# Testing
149+
# -----------------------------------------------------------------------------
150+
# Only build tests if we are the main project or explicitly told to, make sure
151+
# tests are not built when mlx42 is included as a subproject, use MLX42_BUILD_TESTS to overwrite this
152+
# use cmake -DBUILD_TESTS=ON/-DMLX42_BUILD_TESTS=ON to build tests
153+
154+
if ((PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME AND BUILD_TESTS) OR MLX42_BUILD_TESTS)
155+
add_subdirectory(tests)
156+
enable_testing()
157+
endif()
158+
159+
# Installation
160+
# -----------------------------------------------------------------------------
161+
# Convenience feature to install the library and headers to the system.
162+
# Use cmake -DCMAKE_INSTALL_PREFIX=/usr/local for example to install to /usr/local
163+
# or any other directory that you want to install to.
164+
#
165+
# This only really useful if you are a system administrator and want to install
166+
# the library to the system, if you are a developer you should just use the
167+
# library as a subproject as you probably don't have (nor really should) have any
168+
# ambitions to use this for anything other than your own school projects.
169+
170+
install(
171+
DIRECTORY ./include/MLX42 DESTINATION ${CMAKE_INSTALL_PREFIX}/include
172+
FILES_MATCHING PATTERN MLX42.h
173+
)
174+
175+
install(TARGETS mlx42
176+
EXPORT mlx42Targets
177+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
178+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
179+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
180+
)

0 commit comments

Comments
 (0)