Compare commits
4 Commits
5365d44f9c
...
c85906be64
| Author | SHA1 | Date | |
|---|---|---|---|
| c85906be64 | |||
| 4fc14ab35f | |||
| fefbf7a3f4 | |||
| 6a1bbc27f4 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -65,3 +65,5 @@ compile_commands.json
|
|||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
|
||||||
|
# other stuff
|
||||||
|
update_subtree.sh
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
project(minecraft-clone C)
|
project(minecraft-clone C)
|
||||||
cmake_minimum_required(VERSION 3.9)
|
cmake_minimum_required(VERSION 3.9)
|
||||||
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||||
include_directories(lib/include)
|
include_directories(lib/glad/include lib/advanced_C_standard_liberary/include)
|
||||||
file(GLOB SOURCES "src/*.c" "lib/src/*.c")
|
file(GLOB SOURCES "src/*.c" "lib/*/src/*.c")
|
||||||
find_program(CCACHE_PROGRAM ccache)
|
find_program(CCACHE_PROGRAM ccache)
|
||||||
add_executable(test.out ${SOURCES})
|
add_executable(test.out ${SOURCES})
|
||||||
set_property(TARGET test.out PROPERTY C_STANDARD 11)
|
set_property(TARGET test.out PROPERTY C_STANDARD 11)
|
||||||
|
|||||||
4
LICENSE
4
LICENSE
@ -1,3 +1,7 @@
|
|||||||
|
The license of the libraries are located in the directory lib/<name of the liberay>
|
||||||
|
|
||||||
|
License of any other files:
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
|
||||||
Version 3, 29 June 2007
|
Version 3, 29 June 2007
|
||||||
|
|||||||
68
lib/advanced_C_standard_liberary/.gitignore
vendored
Normal file
68
lib/advanced_C_standard_liberary/.gitignore
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# ---> C
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Linker output
|
||||||
|
*.ilk
|
||||||
|
*.map
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.dSYM/
|
||||||
|
*.su
|
||||||
|
*.idb
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# Kernel Module Compile Results
|
||||||
|
*.mod*
|
||||||
|
*.cmd
|
||||||
|
.tmp_versions/
|
||||||
|
modules.order
|
||||||
|
Module.symvers
|
||||||
|
Mkfile.old
|
||||||
|
dkms.conf
|
||||||
|
|
||||||
|
# ---> CMake
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
# ---> Extra
|
||||||
|
vgcore.*
|
||||||
11
lib/advanced_C_standard_liberary/CMakeLists.txt
Normal file
11
lib/advanced_C_standard_liberary/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
project(advanced_C_standard_library C)
|
||||||
|
set_property(GLOBAL PROPERTY C_STANDARD)
|
||||||
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
include_directories("include")
|
||||||
|
file(GLOB SOURCES "src/*.c")
|
||||||
|
add_executable(test.out ${SOURCES})
|
||||||
|
find_program(CCACHE_PROGRAM ccache)
|
||||||
|
if(CCACHE_PROGRAM)
|
||||||
|
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
|
||||||
|
endif()
|
||||||
|
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||||
19
lib/advanced_C_standard_liberary/LICENSE
Normal file
19
lib/advanced_C_standard_liberary/LICENSE
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
MIT License Copyright (c) 2020 Marcel Zinkel
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice (including the next
|
||||||
|
paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||||
|
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||||
|
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
3
lib/advanced_C_standard_liberary/README.md
Normal file
3
lib/advanced_C_standard_liberary/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# advanced C standard library
|
||||||
|
|
||||||
|
A collection of C functions, I commonly use.
|
||||||
5
lib/advanced_C_standard_liberary/build_and_run.sh
Executable file
5
lib/advanced_C_standard_liberary/build_and_run.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm -rf build
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
./build/test.out
|
||||||
5
lib/advanced_C_standard_liberary/include/array.h
Normal file
5
lib/advanced_C_standard_liberary/include/array.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#ifndef array_h
|
||||||
|
#define array_h
|
||||||
|
void* acl_arraylist_create(size_t array_size, size_t sizeof_one_element);
|
||||||
|
void* acl_arraylist_append(void *arraylist_void, void *element_void);
|
||||||
|
#endif
|
||||||
5
lib/advanced_C_standard_liberary/include/file.h
Normal file
5
lib/advanced_C_standard_liberary/include/file.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#ifndef acl_file_h
|
||||||
|
#define acl_file_h
|
||||||
|
#include <stdbool.h>
|
||||||
|
char* acl_ReadFileString(char *filePath, bool *sucess);
|
||||||
|
#endif
|
||||||
37
lib/advanced_C_standard_liberary/src/array.c
Normal file
37
lib/advanced_C_standard_liberary/src/array.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
union arraylist_meta {
|
||||||
|
double dummy_double;
|
||||||
|
long double dummy_long_double;
|
||||||
|
long long dummy_long_long;
|
||||||
|
void *dummy_ptr;
|
||||||
|
void (*dummy_func_ptr)(void);
|
||||||
|
struct {
|
||||||
|
size_t len;
|
||||||
|
size_t cap;
|
||||||
|
size_t sizeof_one_element;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void* acl_arraylist_create(size_t array_size, size_t sizeof_one_element) {
|
||||||
|
union arraylist_meta *arraylist_new = malloc(array_size * sizeof_one_element + sizeof*arraylist_new);
|
||||||
|
arraylist_new->len = array_size;
|
||||||
|
arraylist_new->cap = array_size;
|
||||||
|
arraylist_new->sizeof_one_element = sizeof_one_element;
|
||||||
|
return arraylist_new+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* acl_arraylist_append(void *arraylist_void, void *element) {
|
||||||
|
union arraylist_meta *arraylist = arraylist_void;
|
||||||
|
--arraylist;
|
||||||
|
if(arraylist->len == arraylist->cap) {
|
||||||
|
arraylist->cap = arraylist->len + 10;
|
||||||
|
arraylist = realloc(arraylist, arraylist->cap * arraylist->sizeof_one_element + sizeof *arraylist);
|
||||||
|
}
|
||||||
|
memcpy((char*)(arraylist + 1) + arraylist->sizeof_one_element * arraylist->len, element, arraylist->sizeof_one_element);
|
||||||
|
++arraylist->len;
|
||||||
|
return arraylist+1;
|
||||||
|
}
|
||||||
28
lib/advanced_C_standard_liberary/src/file.c
Normal file
28
lib/advanced_C_standard_liberary/src/file.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
char* acl_ReadFileString(char *filePath, bool *sucess){
|
||||||
|
FILE *fp = fopen(filePath, "rb");
|
||||||
|
size_t lSize;
|
||||||
|
char *buffer;
|
||||||
|
if(!fp) {
|
||||||
|
*sucess = false;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
fseek(fp, 0L, SEEK_END);
|
||||||
|
lSize = ftell(fp);
|
||||||
|
rewind(fp);
|
||||||
|
buffer = malloc(lSize + 1);
|
||||||
|
if(!buffer) {
|
||||||
|
fclose(fp);
|
||||||
|
*sucess = false;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
size_t readReturn = fread(buffer, lSize, 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if(readReturn != 1) {
|
||||||
|
*sucess = false;
|
||||||
|
}
|
||||||
|
*sucess = true;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
13
lib/advanced_C_standard_liberary/src/main.c
Normal file
13
lib/advanced_C_standard_liberary/src/main.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "array.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "file.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
int main() {
|
||||||
|
bool sucess;
|
||||||
|
char *content = acl_ReadFileString("LICENSE", &sucess);
|
||||||
|
if(sucess) {
|
||||||
|
printf("%s", content);
|
||||||
|
}
|
||||||
|
else printf("Erorror\n");
|
||||||
|
}
|
||||||
63
lib/glad/LICENSE
Normal file
63
lib/glad/LICENSE
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
The glad source code:
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013-2020 David Herberth
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
The Khronos Specifications:
|
||||||
|
|
||||||
|
Copyright (c) 2013-2020 The Khronos Group Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
The EGL Specification and various headers:
|
||||||
|
|
||||||
|
Copyright (c) 2007-2016 The Khronos Group Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and/or associated documentation files (the
|
||||||
|
"Materials"), to deal in the Materials without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Materials.
|
||||||
|
|
||||||
|
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
34
src/main.c
34
src/main.c
@ -31,6 +31,15 @@ int main() {
|
|||||||
glViewport(0, 0, 1920, 1080);
|
glViewport(0, 0, 1920, 1080);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
float vertices[] = {
|
||||||
|
-0.5f, -0.5f, 0.0f,
|
||||||
|
0.5f, -0.5f, 0.0f,
|
||||||
|
0.0f, 0.5f, 0.0f
|
||||||
|
};
|
||||||
|
unsigned int VBO;
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
@ -47,3 +56,28 @@ void glfwError(int id, const char* description) {
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
unsigned int parseShader(const char *filePath) {
|
||||||
|
FILE *fp = fopen(filePath, "rb");
|
||||||
|
size_t lSize;
|
||||||
|
char *buffer;
|
||||||
|
if(!fp) {
|
||||||
|
perror(filePath);
|
||||||
|
}
|
||||||
|
fseek(fp, 0L, SEEK_END);
|
||||||
|
lSize = ftell(fp);
|
||||||
|
rewind(fp);
|
||||||
|
buffer = malloc(lSize + 1);
|
||||||
|
if(!buffer) {
|
||||||
|
fclose(fp);
|
||||||
|
printf("out of memory");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
size_t readReturn = fread(buffer, lSize, 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if(readReturn != 1) {
|
||||||
|
printf("Can't read Shader");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("%s", buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define main_h
|
#define main_h
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
void glfwError(int id, const char* description);
|
void glfwError(int id, const char *description);
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
||||||
|
unsigned int parseShader(const char *filePath);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user