GLFW window
This commit is contained in:
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
project(minecraft-clone C)
|
||||||
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
include_directories(src)
|
||||||
|
file(GLOB SOURCES "src/*.c")
|
||||||
|
find_program(CCACHE_PROGRAM ccache)
|
||||||
|
add_executable(test.out ${SOURCES})
|
||||||
|
if(CCACHE_PROGRAM)
|
||||||
|
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
|
||||||
|
endif()
|
||||||
|
set(OpenGL_GL_PREFERENCE GLVND)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
if(NOT OPENGL_FOUND)
|
||||||
|
message("ERROR: OpenGL not found")
|
||||||
|
endif(NOT OPENGL_FOUND)
|
||||||
|
set(GL_LIBRARY GL GLU X11)
|
||||||
|
target_link_libraries(test.out glfw GLEW )
|
||||||
|
target_link_libraries(test.out OpenGL::GL)
|
||||||
5
build_and_run.sh
Executable file
5
build_and_run.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm test.out
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
./test.out
|
||||||
31
src/main.c
Normal file
31
src/main.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <GL/glew.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);
|
||||||
|
glewExperimental = true;
|
||||||
|
}
|
||||||
|
void glfwError(int id, const char* description) {
|
||||||
|
printf("Glfw Error: %s\n", description);
|
||||||
|
}
|
||||||
4
src/main.h
Normal file
4
src/main.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef main_h
|
||||||
|
#define main_h
|
||||||
|
void glfwError(int id, const char* description);
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user