Initial commit of 2D RPG Engine. @dacav come help.
This commit is contained in:
commit
8dcd42c97b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/bin
|
||||||
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(bettola VERSION 0.1)
|
||||||
|
|
||||||
|
# Let's use C++17?
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Deps.
|
||||||
|
find_package(SDL3 REQUIRED)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
add_executable(bettola src/main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(bettola PRIVATE SDL3::SDL3 GLEW::glew OpenGL::GL)
|
||||||
|
|
||||||
46
Makefile
Normal file
46
Makefile
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
SHELL:=/bin/bash
|
||||||
|
BUILD_DIR:=bin
|
||||||
|
PROJECT_NAME:=bettola
|
||||||
|
EXECUTABLE:=$(BUILD_DIR)/$(PROJECT_NAME)
|
||||||
|
|
||||||
|
CXX_COMPILER:=clang++
|
||||||
|
CMAKE_MAKEFILE:=$(BUILD_DIR)/Makefile
|
||||||
|
|
||||||
|
.PHONY: all build config run clean help
|
||||||
|
|
||||||
|
# Default.
|
||||||
|
all: build
|
||||||
|
|
||||||
|
# Build project, if not configured, then do that first.
|
||||||
|
build: $(CMAKE_MAKEFILE)
|
||||||
|
@echo "==== Building Bettola ===="
|
||||||
|
@cmake --build $(BUILD_DIR)
|
||||||
|
|
||||||
|
# run 'config' target if the build directory or CMake cache is missing.
|
||||||
|
$(CMAKE_MAKEFILE):
|
||||||
|
$(MAKE) config
|
||||||
|
|
||||||
|
config:
|
||||||
|
@echo "==== Configuring Bettola with CMake ===="
|
||||||
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
@cmake -S . -B$(BUILD_DIR) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER)
|
||||||
|
|
||||||
|
# Build and run.
|
||||||
|
run: all
|
||||||
|
@echo "==== Running Bettola ===="
|
||||||
|
$(EXECUTABLE)
|
||||||
|
|
||||||
|
# Remove build dir.
|
||||||
|
clean:
|
||||||
|
@echo "==== Cleaning Bettola ===="
|
||||||
|
@rm -rf $(BUILD_DIR)
|
||||||
|
@echo "==== Project Cleaned ===="
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "Available commands:"
|
||||||
|
@echo " make - Build the project (default)."
|
||||||
|
@echo " make build - Build the project."
|
||||||
|
@echo " make run - Build and run the project."
|
||||||
|
@echo " make config - Force CMake to re-configure the project."
|
||||||
|
@echo " make clean - Remove all build files"
|
||||||
|
|
||||||
39
README.org
Normal file
39
README.org
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#+TITLE: Bettola Game
|
||||||
|
|
||||||
|
A 2D RPG game and engine created with C++, SDL3, and OpenGL.
|
||||||
|
|
||||||
|
* Dependencies
|
||||||
|
The following dependencies are requird:
|
||||||
|
- A C++ compiler (e.g., clang, g++)
|
||||||
|
- CMake (3.16 or newer)
|
||||||
|
- SDL3 development libraries
|
||||||
|
- GLEW development libraries
|
||||||
|
|
||||||
|
** Installation (Debian)
|
||||||
|
You can install all required dependencies with the following command:
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install build-essential clang cmake libsdl3-dev libglew-dev
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
* Build Instructions
|
||||||
|
This project uses a top-level Makefile to simplify the CMake workflow. All build artifacts will be placed in the =bin/= directory.
|
||||||
|
|
||||||
|
Run the following from the root of the project directory.
|
||||||
|
|
||||||
|
- *Build the project:*
|
||||||
|
The executable will be located in =bin/bettola=.
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
make
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- *Build and run the project:*
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
make run
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- *Clean the project:*
|
||||||
|
This removes the =bin/= directory.
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
make clean
|
||||||
|
#+END_SRC
|
||||||
84
src/main.cpp
Normal file
84
src/main.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <SDL3/SDL_error.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
const int SCREEN_WIDTH = 800;
|
||||||
|
const int SCREEN_HEIGHT = 600;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
/* Initialise SDL. */
|
||||||
|
if(!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
|
fprintf(stderr, "Failed to init SDL! SDL ERROR: %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OpenGL context attributes */
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
|
||||||
|
/* Create the window. */
|
||||||
|
SDL_Window* window = SDL_CreateWindow(
|
||||||
|
"Bettola Makes No Sense!",
|
||||||
|
SCREEN_WIDTH,
|
||||||
|
SCREEN_HEIGHT,
|
||||||
|
SDL_WINDOW_OPENGL
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!window) {
|
||||||
|
fprintf(stderr, "Failed to create window! SDL_ERROR: %s\n", SDL_GetError());
|
||||||
|
SDL_Quit();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OpenGL context. */
|
||||||
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
|
if(!gl_context) {
|
||||||
|
fprintf(stderr, "Failed to create OpenGL context! SDL_ERROR: %s\n", SDL_GetError());
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GLEW init - Must be done AFTER creating the GL context. */
|
||||||
|
glewExperimental = GL_TRUE;
|
||||||
|
GLenum glew_error = glewInit();
|
||||||
|
if(glew_error != GLEW_OK) {
|
||||||
|
fprintf(stderr, "Failed to init GLEW! %s\n", glewGetErrorString(glew_error));
|
||||||
|
SDL_GL_DestroyContext(gl_context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set viewport. */
|
||||||
|
glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
/* Main game loop.. For now. */
|
||||||
|
bool is_running = true;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
while(is_running) {
|
||||||
|
/* Event handling. */
|
||||||
|
while(SDL_PollEvent(&event)) {
|
||||||
|
if(event.type == SDL_EVENT_QUIT) {
|
||||||
|
is_running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Render that b*tch. */
|
||||||
|
glClearColor(0.1f, 0.1f, 0.3f, 1.0f); /* Dark blue or something. */
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
/* Swap the buffers. */
|
||||||
|
SDL_GL_SwapWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up after ourselves. */
|
||||||
|
SDL_GL_DestroyContext(gl_context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user