84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <glad/glad.h>
|
|
#include <GLFW/glfw3.h>
|
|
#include "main.h"
|
|
|
|
int main() {
|
|
if(!glfwInit()) {
|
|
printf("Faild to initalize GLFW\n");
|
|
return -1;
|
|
}
|
|
glfwSetErrorCallback(&glfwError);
|
|
glfwWindowHint(GLFW_SAMPLES, 4);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
GLFWwindow *window;
|
|
window = glfwCreateWindow(1920, 1080, "Minecraft-Clone", NULL, NULL);
|
|
if(window == NULL) {
|
|
printf("Failed to open GLFW window.\n");
|
|
glfwTerminate();
|
|
return -1;
|
|
}
|
|
glfwMakeContextCurrent(window);
|
|
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
printf("Failed to initialize GLAD\n");
|
|
return -1;
|
|
}
|
|
glViewport(0, 0, 1920, 1080);
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
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)) {
|
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
glfwSwapBuffers(window);
|
|
glfwPollEvents();
|
|
}
|
|
glfwTerminate();
|
|
return 0;
|
|
}
|
|
void glfwError(int id, const char* description) {
|
|
printf("Glfw Error: %s\n", description);
|
|
}
|
|
|
|
void framebuffer_size_callback(GLFWwindow* window, int width, int 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;
|
|
}
|