diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5973cf2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) +project(new-engine + VERSION 0 + DESCRIPTION "Simple Engine Experiment in C" + HOMEPAGE_URL "https://git.warwick-new.co.uk/" + LANGUAGES C) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Dependancies +find_package(SDL2 REQUIRED) +find_package(SDL2_IMAGE REQUIRED) + +# Include dirs +include_directories(${SDL2_INCLUDE_DIRS}) +include_directories(${SDL2_IMAGE_INCLUDE_DIRS}) + +# Executables +add_executable(${PROJECT_NAME} main.c) + +# Link Libraries +target_link_libraries(${PROJECT_NAME} ${SDL2_IMAGE_LIBRARIES} ${SDL2_LIBRARIES}) + +# Compile Shaders +add_custom_command(TARGET ${PROJECT_NAME} + PRE_BUILD + COMMAND ./compile_shaders.sh) diff --git a/README.md b/README.md index 49fc115..01b70c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # New Engine - Cuz starting again from scratch in a harder language is definitely the answer. -TODO 0.1: -- [ ] Get build system working (Engine Dynamic Library and Game Executable) -- [ ] Get Vulkan renderer working. -- [ ] Load models (Rework OpenGL Loader) -- [ ] Run current opengl shaders +## TODO 0.1: + - [ ] Get build system working (Engine Dynamic Library and Game Executable) + - [ ] Get Vulkan renderer working. + - [ ] Load models (Rework OpenGL Loader) + - [ ] Run current opengl shaders diff --git a/compile_shaders.sh b/compile_shaders.sh new file mode 100755 index 0000000..08a2e37 --- /dev/null +++ b/compile_shaders.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd $SCRIPT_DIR + +glslc shaders/shader.vert -o shaders/shader.vert.spv +glslc shaders/shader.frag -o shaders/shader.frag.spv diff --git a/main.c b/main.c new file mode 100644 index 0000000..bd64fac --- /dev/null +++ b/main.c @@ -0,0 +1,47 @@ +#include +#include + +int main() { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("Failed to initialize the SDL2 library\n"); + return -1; + } + + SDL_Window *window = SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, 680, 480, 0); + + if (!window) { + printf("Failed to create window\n"); + return -1; + } + + SDL_Surface *window_surface = SDL_GetWindowSurface(window); + + if (!window_surface) { + printf("Failed to get the surface from the window\n"); + return -1; + } + + bool running = true; + while (running) { + // Create event handling struct + SDL_Event input; + while (SDL_PollEvent(&input) > 0) { + // Handle SDL quit event + if (input.type == SDL_QUIT) { + running = false; + } + switch (input.type) { + case SDL_QUIT: + running = false; + case SDL_KEYDOWN: { + const Uint8 *keys = SDL_GetKeyboardState(NULL); + if (keys[SDL_SCANCODE_ESCAPE]) + running = false; + } + } + } + } + + SDL_UpdateWindowSurface(window); +} diff --git a/shaders/shader.frag b/shaders/shader.frag new file mode 100644 index 0000000..43674b2 --- /dev/null +++ b/shaders/shader.frag @@ -0,0 +1,7 @@ +#version 450 + +layout (location = 0) out vec4 outColor; + +void main() { + outColor = vec4(0.0, 1.0, 0.0, 1.0); +} diff --git a/shaders/shader.vert b/shaders/shader.vert new file mode 100644 index 0000000..0fb555d --- /dev/null +++ b/shaders/shader.vert @@ -0,0 +1,11 @@ +#version 450 + +vec2 positions[3] = vec2[] ( + vec2(0.0,-0.5), + vec2(0.5,0.5), + vec2(-0.5,0.5) +); + +void main() { + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); +}