Compare commits

...

19 Commits

Author SHA1 Message Date
e1b6d826e9 fixed stb_image.h 2020-07-19 16:16:27 +02:00
b3003a44cb stb_image 2020-07-19 15:34:28 +02:00
4f80df9520 Texture settings 2020-07-19 15:33:41 +02:00
64a7602c26 Updated gitignore 2020-07-19 15:33:18 +02:00
5a80a3761b update acl 2020-06-24 21:52:32 +02:00
2a9a9273e3 Squashed 'lib/advanced_C_standard_liberary/' changes from cea7d71..cf9856d
cf9856d fixed file.h

git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: cf9856d0614a5a4ac4b27c1f5b615a9fb0fb4d0e
2020-06-24 21:52:32 +02:00
8b2983c3c4 Update acl 2020-06-24 21:48:10 +02:00
b873d87511 Squashed 'lib/advanced_C_standard_liberary/' changes from a87fc37..cea7d71
cea7d71 acl_ReadTextFile takes now a const char *filePath as argument
59740ea fixed acl_ReadtextFile

git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: cea7d71b8c9379347770153ab5b7643cbdf7601d
2020-06-24 21:48:10 +02:00
eee534d816 triangle 2020-06-24 21:47:26 +02:00
cfb9251890 Squashed 'lib/advanced_C_standard_liberary/' changes from 59accca..a87fc37
a87fc37 acl dir to include

git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: a87fc373ba579da68d784d17431c35cf438b094f
2020-06-22 19:23:10 +02:00
63eb97b908 Merge commit 'cfb92518908a98e1e04cf559d44a454fa3f9527b' 2020-06-22 19:23:10 +02:00
6a2a10b5cd Merge commit 'f41cba863448c6c18649077f7c3e82d23587149c' 2020-06-22 19:19:24 +02:00
f41cba8634 Squashed 'lib/advanced_C_standard_liberary/' changes from 68f0bb5..59accca
59accca ReadTextFile renamed

git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: 59acccac883425c4d25158a26c2c126ccb4bff05
2020-06-22 19:19:23 +02:00
dba6b159f5 Merge commit '882fa6e3d40e75b48306b20aeee8d14b5937e8da' 2020-06-22 15:08:56 +02:00
882fa6e3d4 Squashed 'lib/advanced_C_standard_liberary/' changes from 7f81bd3..68f0bb5
68f0bb5 exclude main.c

git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: 68f0bb51db9829ef16e07f01ed52dd6ac5b3aec3
2020-06-22 15:08:56 +02:00
c85906be64 subtree 2020-06-22 15:08:33 +02:00
fefbf7a3f4 Squashed 'lib/advanced_C_standard_liberary/' content from commit 7f81bd3
git-subtree-dir: lib/advanced_C_standard_liberary
git-subtree-split: 7f81bd361e4b3ad0ce89d7052cb448cee5d32a21
2020-06-22 14:52:28 +02:00
4fc14ab35f Merge commit 'fefbf7a3f45ca244ac1ad685b6628900d0fa0652' as 'lib/advanced_C_standard_liberary' 2020-06-22 14:52:28 +02:00
6a1bbc27f4 restructuring 2020-06-22 14:51:43 +02:00
23 changed files with 8147 additions and 10 deletions

3
.gitignore vendored
View File

@ -65,3 +65,6 @@ compile_commands.json
CTestTestfile.cmake
_deps
# other stuff
update_subtree.sh
.clangd

View File

@ -1,8 +1,8 @@
project(minecraft-clone C)
cmake_minimum_required(VERSION 3.9)
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
include_directories(lib/include)
file(GLOB SOURCES "src/*.c" "lib/src/*.c")
include_directories(lib/glad/include lib/advanced_C_standard_liberary/include include lib/stb/include)
file(GLOB SOURCES "src/*.c" "lib/*/src/*.c")
find_program(CCACHE_PROGRAM ccache)
add_executable(test.out ${SOURCES})
set_property(TARGET test.out PROPERTY C_STANDARD 11)

View File

@ -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
Version 3, 29 June 2007

9
include/main.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef main_h
#define main_h
#include <glad/glad.h>
#include <GLFW/glfw3.h>
void glfwError(int id, const char *description);
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
unsigned int parseShader(const char *filePath, const GLenum shaderType);
unsigned int linkShader(unsigned int vertexShader, unsigned int fragmentShader);
#endif

View File

@ -0,0 +1,69 @@
# ---> 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.*
src/main.c

View 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 )

View 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.

View File

@ -0,0 +1,3 @@
# advanced C standard library
A collection of C functions, I commonly use.

View File

@ -0,0 +1,5 @@
#!/bin/sh
rm -rf build
cmake .
make
./build/test.out

View 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

View File

@ -0,0 +1,5 @@
#ifndef acl_file_h
#define acl_file_h
#include <stdbool.h>
char* acl_ReadTextFile(const char *filePath, bool *sucess);
#endif

View 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;
}

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char* acl_ReadTextFile(const 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);
*sucess = readReturn == 1;
return buffer;
}

63
lib/glad/LICENSE Normal file
View 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.

37
lib/stb/LICENSE Normal file
View File

@ -0,0 +1,37 @@
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
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.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
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 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.

7762
lib/stb/include/stb_image.h Normal file

File diff suppressed because it is too large Load Diff

7
shader/test.frag Normal file
View File

@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}

7
shader/test.vert Normal file
View File

@ -0,0 +1,7 @@
#version 330 core
layout (location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}

View File

@ -4,7 +4,9 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "main.h"
#include <acl/file.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
int main() {
if(!glfwInit()) {
printf("Faild to initalize GLFW\n");
@ -31,9 +33,39 @@ int main() {
glViewport(0, 0, 1920, 1080);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// texture settings
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
float borderColor[] = { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f };
glad_glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
float vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
// parse shader
unsigned int vertexShader = parseShader("shader/test.vert", GL_VERTEX_SHADER);
unsigned int fragmentShader = parseShader("shader/test.frag", GL_FRAGMENT_SHADER);
unsigned int shaderProgram = linkShader(vertexShader, fragmentShader);
glUseProgram(shaderProgram);
unsigned int VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
unsigned int VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
while(!glfwWindowShouldClose(window)) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
@ -47,3 +79,44 @@ void glfwError(int id, const char* description) {
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
}
unsigned int parseShader(const char *filePath, const GLenum shaderType) {
bool success;
unsigned int ShaderId;
char *ShaderSrc = acl_ReadTextFile(filePath, &success);
if(!success) {
printf("Failed to read Shader: %s", filePath);
glfwTerminate();
exit(-1);
}
ShaderId = glCreateShader(shaderType);
const char *tmpShaderSrc = ShaderSrc;
glShaderSource(ShaderId, 1, &tmpShaderSrc, NULL);
glCompileShader(ShaderId);
free(ShaderSrc);
int compileSuccess;
glGetShaderiv(ShaderId, GL_COMPILE_STATUS, &compileSuccess);
if(!compileSuccess) {
char infoLog[512];
glGetShaderInfoLog(ShaderId, 512, NULL, infoLog);
printf("Failed to compile Shader: %s Error: %s", filePath, infoLog);
}
return ShaderId;
}
unsigned int linkShader(unsigned int vertexShader, unsigned int fragmentShader) {
unsigned int shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
int success;
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
char infoLog[512];
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
printf("Failed to link Shader. Error: %s", infoLog);
glfwTerminate();
exit(-1);
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
return shaderProgram;
}

View File

@ -1,7 +0,0 @@
#ifndef main_h
#define main_h
#include <glad/glad.h>
#include <GLFW/glfw3.h>
void glfwError(int id, const char* description);
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
#endif