Initial SDL window test.
As an aside if you're on debian stable rn you will need sdl2 libs from the testing branch.
This commit is contained in:
parent
a54d13df82
commit
86d57ade14
6 changed files with 105 additions and 5 deletions
28
CMakeLists.txt
Normal file
28
CMakeLists.txt
Normal file
|
|
@ -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)
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# New Engine - Cuz starting again from scratch in a harder language is definitely the answer.
|
# New Engine - Cuz starting again from scratch in a harder language is definitely the answer.
|
||||||
|
|
||||||
TODO 0.1:
|
## TODO 0.1:
|
||||||
- [ ] Get build system working (Engine Dynamic Library and Game Executable)
|
- [ ] Get build system working (Engine Dynamic Library and Game Executable)
|
||||||
- [ ] Get Vulkan renderer working.
|
- [ ] Get Vulkan renderer working.
|
||||||
- [ ] Load models (Rework OpenGL Loader)
|
- [ ] Load models (Rework OpenGL Loader)
|
||||||
|
|
|
||||||
7
compile_shaders.sh
Executable file
7
compile_shaders.sh
Executable file
|
|
@ -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
|
||||||
47
main.c
Normal file
47
main.c
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
7
shaders/shader.frag
Normal file
7
shaders/shader.frag
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
outColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
11
shaders/shader.vert
Normal file
11
shaders/shader.vert
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue