init
This commit is contained in:
commit
12205696b6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build
|
48
Makefile
Normal file
48
Makefile
Normal file
@ -0,0 +1,48 @@
|
||||
# Compiler and flags
|
||||
CPPC = g++
|
||||
CPPC_FLAGS = -std=c++23 -s -O3 -lSDL3 -Wall -Wextra -Wno-write-strings
|
||||
DEBUG_FLAGS = -ggdb -std=c++23 -lSDL3 -Wall -Wextra -Wno-write-strings
|
||||
DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lSDL3 -Wall -Wextra -Wno-write-strings
|
||||
|
||||
|
||||
SRC_PATH := src
|
||||
OBJ_PATH := build/obj
|
||||
BIN_PATH := build/bin
|
||||
|
||||
BIN_NAME = pupes-screensaver
|
||||
|
||||
|
||||
SRC_FILES := $(shell find $(SRC_PATH) -name '*.cpp')
|
||||
OBJ_FILES := $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(SRC_FILES))
|
||||
|
||||
|
||||
all: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
|
||||
debug: CPPC_FLAGS = $(DEBUG_FLAGS)
|
||||
debug: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
asan: CPPC_FLAGS = $(DEBUG_ASANITIZE)
|
||||
asan: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
|
||||
make-build-dir:
|
||||
mkdir -p $(OBJ_PATH)
|
||||
mkdir -p $(BIN_PATH)
|
||||
|
||||
|
||||
$(BIN_PATH)/$(BIN_NAME): $(OBJ_FILES)
|
||||
$(CPPC) $(CPPC_FLAGS) $^ -o $@
|
||||
|
||||
|
||||
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cpp
|
||||
$(CPPC) $(CPPC_FLAGS) -c $< -o $@
|
||||
|
||||
|
||||
install:
|
||||
@install -vpm 755 -o root -g root $(BIN_PATH)/$(BIN_NAME) /usr/bin/
|
||||
|
||||
clean:
|
||||
rm -fr build
|
||||
|
||||
.PHONY: all clean install debug asan
|
11
src/const.h
Normal file
11
src/const.h
Normal file
@ -0,0 +1,11 @@
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
|
||||
#ifndef CONST_NS
|
||||
#define CONST_NS
|
||||
|
||||
constexpr int SCREEN_WIDTH = 1920;
|
||||
constexpr int SCREEN_HEIGHT = 1080;
|
||||
constexpr int TARGET_FPS = 60;
|
||||
constexpr Uint64 TARGET_FRAME_TIME_NS = 1'000'000'000 / TARGET_FPS;
|
||||
|
||||
#endif
|
10
src/func.cpp
Normal file
10
src/func.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <random>
|
||||
|
||||
int get_random_num(int min, int max) {
|
||||
std::random_device dev;
|
||||
std::mt19937 rng(dev());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist(
|
||||
min, max); // set range
|
||||
|
||||
return dist(rng);
|
||||
}
|
1
src/func.h
Normal file
1
src/func.h
Normal file
@ -0,0 +1 @@
|
||||
int get_random_num(int min, int max);
|
35
src/main.cpp
Normal file
35
src/main.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include "types.h"
|
||||
#include "const.h"
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <iostream>
|
||||
#include "func.h"
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
sdl_session main_sdl_session;
|
||||
|
||||
main_sdl_session.window = SDL_CreateWindow("pupes screensave", SCREEN_WIDTH, SCREEN_HEIGHT, 0);
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(main_sdl_session.window, "gpu,vulcan");
|
||||
|
||||
signal(SIGTERM, exit);
|
||||
SDL_FPoint last_pos = {static_cast<float>(get_random_num(0,1920)),static_cast<float>(get_random_num(0,1080))};
|
||||
SDL_FPoint new_pos;
|
||||
while (true) {
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, get_random_num(0,255), get_random_num(0,255),get_random_num(0,255), SDL_ALPHA_OPAQUE);
|
||||
new_pos = {static_cast<float>(get_random_num(0,1920)),static_cast<float>(get_random_num(0,1080))};
|
||||
SDL_RenderLine(renderer, last_pos.x ,last_pos.y, new_pos.x,new_pos.y);
|
||||
last_pos = new_pos;
|
||||
SDL_RenderPresent(renderer);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
std::cin.get();
|
||||
}
|
5
src/types.h
Normal file
5
src/types.h
Normal file
@ -0,0 +1,5 @@
|
||||
#include <SDL3/SDL.h>
|
||||
struct sdl_session {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user