blue window
This commit is contained in:
parent
bab6889337
commit
0dff56fe37
6 changed files with 144 additions and 1 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/
|
36
Makefile
Normal file
36
Makefile
Normal file
|
@ -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)
|
15
README.md
15
README.md
|
@ -1,2 +1,15 @@
|
|||
# skyridge
|
||||
# Skyridge
|
||||
|
||||
# Build
|
||||
|
||||
```sh
|
||||
apt install libsdl2-dev libglm-dev libglew-dev
|
||||
```
|
||||
|
||||
```sh
|
||||
make
|
||||
```
|
||||
|
||||
```sh
|
||||
make run
|
||||
```
|
||||
|
|
53
src/display.cpp
Normal file
53
src/display.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "display.hpp"
|
||||
#include <GL/glew.h>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
26
src/display.hpp
Normal file
26
src/display.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
|
||||
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
|
14
src/main.cpp
Normal file
14
src/main.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue