Create base game for future use
This commit is contained in:
@@ -16,5 +16,8 @@ set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory(lib/glfw)
|
||||
|
||||
# The basis for games
|
||||
add_subdirectory(base)
|
||||
|
||||
# The Games
|
||||
add_subdirectory(pong)
|
||||
|
||||
9
base/CMakeLists.txt
Normal file
9
base/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.00)
|
||||
|
||||
set(BASE_SOURCE src/main.c)
|
||||
|
||||
add_executable(base ${BASE_SOURCE})
|
||||
|
||||
target_link_libraries(base PRIVATE EmberLib)
|
||||
target_link_libraries(base PRIVATE glad)
|
||||
target_link_libraries(base PRIVATE glfw)
|
||||
55
base/src/main.c
Normal file
55
base/src/main.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void process_input(GLFWwindow *window)
|
||||
{
|
||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
{
|
||||
glfwSetWindowShouldClose(window, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
|
||||
GLFWwindow *window = glfwCreateWindow(800, 600, "OpenGL Base Game", NULL, NULL);
|
||||
if(window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to create GLFW Window!\n");
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLAD!\n");
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
glViewport(0, 0, 800, 600);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
while(!glfwWindowShouldClose(window))
|
||||
{
|
||||
process_input(window);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user