diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5bc95d4 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +TARGET := program +SRC = \ + $(wildcard src/*.cpp) \ + $(wildcard src/*.hpp) \ + +BUILD := build +OBJECTS := $(patsubst src/%.cpp,$(BUILD)/%.o,$(SRC)) + +CXX := g++ +CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror +LDFLAGS := -lstdc++ -lm -lGL -lGLEW -lSDL2 +INCLUDE := -Iinclude/ + +all: $(BUILD)/$(TARGET) + +$(BUILD)/%.o: src/%.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ + +$(BUILD)/$(TARGET): $(OBJECTS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) + +.PHONY: all run build clean debug release + +run: all + @./$(BUILD)/$(TARGET) + +debug: CXXFLAGS += -DDEBUG -g +debug: all + +release: CXXFLAGS += -O2 +release: all + +clean: + -@rm -rvf $(BUILD) diff --git a/README.md b/README.md index 1f42d65..be7c17a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# skyridge +# Skyridge +# Build + +```sh +apt install libsdl2-dev libglm-dev libglew-dev +``` + +```sh +make +``` + +```sh +make run +``` diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..d4da18d --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,53 @@ +#include "display.hpp" +#include +#include + +Display::Display(int width, int height, const std::string& title) { + SDL_Init(SDL_INIT_EVERYTHING); + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, width, height, + SDL_WINDOW_OPENGL); + m_glContext = SDL_GL_CreateContext(m_window); + + GLenum status = glewInit(); + + if (status != GLEW_OK) { + std::cerr << "Error: Glew failed to initialize" << std::endl; + } + + m_isClosed = false; +} + +Display::~Display() { + SDL_GL_DeleteContext(m_glContext); + SDL_DestroyWindow(m_window); + SDL_Quit(); +} + +void Display::Clear(float r, float g, float b, float a) { + glClearColor(r, g, b, a); + glClear(GL_COLOR_BUFFER_BIT); +} + +bool Display::IsClosed() { + return m_isClosed; +} + +void Display::Update() { + SDL_GL_SwapWindow(m_window); + SDL_Event e; + + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { + m_isClosed = true; + } + } +} diff --git a/src/display.hpp b/src/display.hpp new file mode 100644 index 0000000..46d812d --- /dev/null +++ b/src/display.hpp @@ -0,0 +1,26 @@ +#ifndef DISPLAY_H +#define DISPLAY_H + +#include +#include + +class Display { + public: + Display(int width, int height, const std::string& title); + + void Clear(float r, float g, float b, float a); + void Update(); + bool IsClosed(); + + virtual ~Display(); + protected: + private: + //Display(const Display& other) {} + //void operator=(const Display& other) {} + + SDL_Window* m_window; + SDL_GLContext m_glContext; + bool m_isClosed; +}; + +#endif // DISPLAY_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..086e8ef --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,14 @@ +#include +#include +#include "display.hpp" + +int main() { + Display display(800, 600, "Hello world!"); + + while (!display.IsClosed()) { + display.Clear(0.0f, 0.15f, 0.3f, 1.0f); + display.Update(); + } + + return 0; +}