Compare commits
15 Commits
c85906be64
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e1b6d826e9 | |||
| b3003a44cb | |||
| 4f80df9520 | |||
| 64a7602c26 | |||
| 5a80a3761b | |||
| 2a9a9273e3 | |||
| 8b2983c3c4 | |||
| b873d87511 | |||
| eee534d816 | |||
| cfb9251890 | |||
| 63eb97b908 | |||
| 6a2a10b5cd | |||
| f41cba8634 | |||
| dba6b159f5 | |||
| 882fa6e3d4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -67,3 +67,4 @@ _deps
|
|||||||
|
|
||||||
# other stuff
|
# other stuff
|
||||||
update_subtree.sh
|
update_subtree.sh
|
||||||
|
.clangd
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
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/glad/include lib/advanced_C_standard_liberary/include)
|
include_directories(lib/glad/include lib/advanced_C_standard_liberary/include include lib/stb/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})
|
||||||
|
|||||||
@ -4,5 +4,6 @@
|
|||||||
#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);
|
unsigned int parseShader(const char *filePath, const GLenum shaderType);
|
||||||
|
unsigned int linkShader(unsigned int vertexShader, unsigned int fragmentShader);
|
||||||
#endif
|
#endif
|
||||||
1
lib/advanced_C_standard_liberary/.gitignore
vendored
1
lib/advanced_C_standard_liberary/.gitignore
vendored
@ -66,3 +66,4 @@ CTestTestfile.cmake
|
|||||||
_deps
|
_deps
|
||||||
# ---> Extra
|
# ---> Extra
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
src/main.c
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
project(advanced_C_standard_library C)
|
project(advanced_C_standard_library C)
|
||||||
set_property(GLOBAL PROPERTY C_STANDARD)
|
set_property(GLOBAL PROPERTY C_STANDARD)
|
||||||
cmake_minimum_required(VERSION 3.9)
|
cmake_minimum_required(VERSION 3.9)
|
||||||
include_directories("include")
|
include_directories(include)
|
||||||
file(GLOB SOURCES "src/*.c")
|
file(GLOB SOURCES "src/*.c")
|
||||||
add_executable(test.out ${SOURCES})
|
add_executable(test.out ${SOURCES})
|
||||||
find_program(CCACHE_PROGRAM ccache)
|
find_program(CCACHE_PROGRAM ccache)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef acl_file_h
|
#ifndef acl_file_h
|
||||||
#define acl_file_h
|
#define acl_file_h
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
char* acl_ReadFileString(char *filePath, bool *sucess);
|
char* acl_ReadTextFile(const char *filePath, bool *sucess);
|
||||||
#endif
|
#endif
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
char* acl_ReadFileString(char *filePath, bool *sucess){
|
char* acl_ReadTextFile(const char *filePath, bool *sucess){
|
||||||
FILE *fp = fopen(filePath, "rb");
|
FILE *fp = fopen(filePath, "rb");
|
||||||
size_t lSize;
|
size_t lSize;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
@ -20,9 +20,6 @@ char* acl_ReadFileString(char *filePath, bool *sucess){
|
|||||||
}
|
}
|
||||||
size_t readReturn = fread(buffer, lSize, 1, fp);
|
size_t readReturn = fread(buffer, lSize, 1, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if(readReturn != 1) {
|
*sucess = readReturn == 1;
|
||||||
*sucess = false;
|
|
||||||
}
|
|
||||||
*sucess = true;
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
#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");
|
|
||||||
}
|
|
||||||
37
lib/stb/LICENSE
Normal file
37
lib/stb/LICENSE
Normal 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
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
7
shader/test.frag
Normal 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
7
shader/test.vert
Normal 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);
|
||||||
|
}
|
||||||
83
src/main.c
83
src/main.c
@ -4,7 +4,9 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include <acl/file.h>
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include <stb_image.h>
|
||||||
int main() {
|
int main() {
|
||||||
if(!glfwInit()) {
|
if(!glfwInit()) {
|
||||||
printf("Faild to initalize GLFW\n");
|
printf("Faild to initalize GLFW\n");
|
||||||
@ -31,18 +33,39 @@ 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);
|
||||||
|
// 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[] = {
|
float vertices[] = {
|
||||||
-0.5f, -0.5f, 0.0f,
|
-0.5f, -0.5f, 0.0f,
|
||||||
0.5f, -0.5f, 0.0f,
|
0.5f, -0.5f, 0.0f,
|
||||||
0.0f, 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;
|
unsigned int VBO;
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
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)) {
|
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);
|
||||||
|
glUseProgram(shaderProgram);
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
@ -56,28 +79,44 @@ 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) {
|
unsigned int parseShader(const char *filePath, const GLenum shaderType) {
|
||||||
FILE *fp = fopen(filePath, "rb");
|
bool success;
|
||||||
size_t lSize;
|
unsigned int ShaderId;
|
||||||
char *buffer;
|
char *ShaderSrc = acl_ReadTextFile(filePath, &success);
|
||||||
if(!fp) {
|
if(!success) {
|
||||||
perror(filePath);
|
printf("Failed to read Shader: %s", filePath);
|
||||||
|
glfwTerminate();
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
fseek(fp, 0L, SEEK_END);
|
ShaderId = glCreateShader(shaderType);
|
||||||
lSize = ftell(fp);
|
const char *tmpShaderSrc = ShaderSrc;
|
||||||
rewind(fp);
|
glShaderSource(ShaderId, 1, &tmpShaderSrc, NULL);
|
||||||
buffer = malloc(lSize + 1);
|
glCompileShader(ShaderId);
|
||||||
if(!buffer) {
|
free(ShaderSrc);
|
||||||
fclose(fp);
|
int compileSuccess;
|
||||||
printf("out of memory");
|
glGetShaderiv(ShaderId, GL_COMPILE_STATUS, &compileSuccess);
|
||||||
exit(1);
|
if(!compileSuccess) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetShaderInfoLog(ShaderId, 512, NULL, infoLog);
|
||||||
|
printf("Failed to compile Shader: %s Error: %s", filePath, infoLog);
|
||||||
}
|
}
|
||||||
size_t readReturn = fread(buffer, lSize, 1, fp);
|
return ShaderId;
|
||||||
fclose(fp);
|
|
||||||
if(readReturn != 1) {
|
|
||||||
printf("Can't read Shader");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
printf("%s", buffer);
|
unsigned int linkShader(unsigned int vertexShader, unsigned int fragmentShader) {
|
||||||
return 0;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user