added fill screen demo for testing basic initialization and drawing
This commit is contained in:
parent
0d00314f5a
commit
e11fecbc12
|
@ -0,0 +1,3 @@
|
||||||
|
ooo.shampoo.fill_screen
|
||||||
|
BPmono.ttf
|
||||||
|
fill-screen
|
|
@ -0,0 +1,106 @@
|
||||||
|
# Fill screen SPACEBOX example
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Location parameters #
|
||||||
|
#######################
|
||||||
|
|
||||||
|
# Location of project specific source files
|
||||||
|
SRC_DIR := ./
|
||||||
|
|
||||||
|
# Locations of [SPACEBOX] source and dependencies required to be compiled from source. These locations are configured to match the
|
||||||
|
# structure of the [SPACEBOX] repository but can be modified as necessary.
|
||||||
|
SB_DIR := ../../
|
||||||
|
SB_SRC_DIR := $(SB_DIR)src/
|
||||||
|
SB_LIB_DIR := $(SB_DIR)lib/
|
||||||
|
SDLGFX2_DIR := $(SB_LIB_DIR)sdl2-gfx/
|
||||||
|
GLEW_DIR := $(SB_LIB_DIR)glew/
|
||||||
|
|
||||||
|
# C and C++ compiler commands
|
||||||
|
CC := clang
|
||||||
|
CXX := clang++
|
||||||
|
|
||||||
|
# Location of SDL config program
|
||||||
|
SDLCONFIG := $(HOME)/local/sdl/bin/sdl2-config
|
||||||
|
|
||||||
|
# Edit to point to the location of BPmono.ttf
|
||||||
|
CREATE_FONT_SYMLINK := ln -nsf $(SB_DIR)"BPmono.ttf" .
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Based on above parameters #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
SDL_CFLAGS = $(shell $(SDLCONFIG) --cflags)
|
||||||
|
SDL_LFLAGS := $(shell $(SDLCONFIG) --libs)
|
||||||
|
SB_H_FILES := $(wildcard $(addprefix $(SB_SRC_DIR),*.hpp))
|
||||||
|
SB_O_FILES := $(filter-out $(addprefix $(SB_SRC_DIR),filesystem.o),$(SB_H_FILES:.hpp=.o))
|
||||||
|
SRC_H_FILES := $(wildcard $(addprefix $(SRC_DIR),*.hpp))
|
||||||
|
SRC_O_FILES := fill_screen.o $(SRC_H_FILES:.hpp=.o)
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# Targets for building [SPACE BOX], dependencies and project source #
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
$(SDLGFX2_DIR)%.o: $(SDLGFX2_DIR)%.c $(SDLGFX2_DIR)%.h
|
||||||
|
$(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
|
||||||
|
$(CC) $< $(CFLAGS) -c -o $@
|
||||||
|
|
||||||
|
$(SB_SRC_DIR)extension.o : $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Node.o : $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Sprite.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
|
||||||
|
Delegate.hpp Audio.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Animation.o : $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
|
||||||
|
$(SB_SRC_DIR)Recorder.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
|
||||||
|
$(SB_SRC_DIR)Input.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)
|
||||||
|
$(SB_SRC_DIR)Configuration.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Delegate.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Input.hpp)
|
||||||
|
$(SB_SRC_DIR)Display.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Configuration.hpp Delegate.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Box.o : $(addprefix $(SB_SRC_DIR),extension.hpp Segment.hpp)
|
||||||
|
$(SB_SRC_DIR)Segment.o : $(addprefix $(SB_SRC_DIR),extension.hpp Box.hpp)
|
||||||
|
$(SB_SRC_DIR)Pixels.o : $(addprefix $(SB_SRC_DIR),Box.hpp extension.hpp Log.hpp utility.hpp)
|
||||||
|
$(SB_SRC_DIR)Audio.o : $(addprefix $(SB_SRC_DIR),Node.hpp Display.hpp Configuration.hpp Box.hpp filesystem.hpp extension.hpp)
|
||||||
|
$(SB_SRC_DIR)GLObject.o : $(addprefix $(SB_SRC_DIR),Log.hpp)
|
||||||
|
$(SB_SRC_DIR)Texture.o : $(addprefix $(SB_SRC_DIR),GLObject.hpp filesystem.hpp Log.hpp)
|
||||||
|
$(SB_SRC_DIR)VBO.o : $(addprefix $(SB_SRC_DIR),Log.hpp GLObject.hpp Attributes.hpp extension.hpp)
|
||||||
|
$(SB_SRC_DIR)Attributes.o : $(addprefix $(SB_SRC_DIR),Log.hpp extension.hpp)
|
||||||
|
$(SRC_DIR)Model.o : $(addprefix $(SB_SRC_DIR),extension.hpp Attributes.hpp Texture.hpp utility.hpp)
|
||||||
|
$(SRC_DIR)*.o : $(SRC_H_FILES) $(SB_H_FILES)
|
||||||
|
%.o : %.cpp %.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) $< -c -o $@
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Linux build #
|
||||||
|
###############
|
||||||
|
|
||||||
|
linux : CFLAGS = -Wall -Wextra -O3 -c -I$(SB_LIB_DIR) -I$(SB_SRC_DIR) $(SDL_CFLAGS)
|
||||||
|
linux : CXXFLAGS = $(CFLAGS) --std=c++17
|
||||||
|
linux : LFLAGS = $(SDL_LFLAGS) -Wl,--enable-new-dtags -lpthread -lGL -lGLESv2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lstdc++fs
|
||||||
|
linux : $(GLEW_DIR)glew.o $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPrimitives.o) \
|
||||||
|
$(SB_O_FILES) $(SRC_O_FILES)
|
||||||
|
$(CREATE_FONT_SYMLINK)
|
||||||
|
$(CXX) $^ $(LFLAGS) -D__LINUX__ -o fill-screen
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# Clean up object files #
|
||||||
|
#########################
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-find $(SRC_DIR) -iname "*.o" -delete
|
||||||
|
rm -f BPmono.ttf
|
||||||
|
|
||||||
|
clean-all : clean
|
||||||
|
-find $(SB_SRC_DIR) -iname "*.o" -delete
|
||||||
|
-find $(SB_LIB_DIR) -iname "*.o" -delete
|
||||||
|
|
||||||
|
#############
|
||||||
|
# compiledb #
|
||||||
|
#############
|
||||||
|
|
||||||
|
# Generate a clang JSON compilation database file. This can be useful for example for code completion. It requires a
|
||||||
|
# compiledb binary (https://pypi.org/project/compiledb/). It should be generated manually every time a file is added,
|
||||||
|
# renamed, or the compilation flags change. The generated database is based on the Linux build.
|
||||||
|
|
||||||
|
PATH_TO_COMPILEDB = $(HOME)/.local/bin/compiledb
|
||||||
|
compiledb :
|
||||||
|
-$(PATH_TO_COMPILEDB) -n make linux -k
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
Fill screen with solid colors
|
||||||
|
=============================
|
||||||
|
|
||||||
|
This is an example program that fills the screen with a color every frame. It can be used for testing since it is a minimal example of a SPACEBOX program.
|
||||||
|
|
||||||
|
Setup
|
||||||
|
-----
|
||||||
|
|
||||||
|
### SPACEBOX
|
||||||
|
|
||||||
|
The [SPACEBOX][] game and interactive application framework is required for setting up SDL + OpenGL. Follow the instructions in the README for installing the required libraries.
|
||||||
|
|
||||||
|
Compiling
|
||||||
|
---------
|
||||||
|
|
||||||
|
Build at the root of the directory after setting up SPACEBOX
|
||||||
|
|
||||||
|
make linux
|
||||||
|
|
||||||
|
Running
|
||||||
|
-------
|
||||||
|
|
||||||
|
./fill-screen
|
||||||
|
|
||||||
|
[SPACEBOX]: https://git.nugget.fun/nugget/spacebox
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Fill screen example by frank at shampoo.ooo
|
||||||
|
*
|
||||||
|
* This is an example program that fills the screen with a color every frame. It is a minimal example of a SPACEBOX program
|
||||||
|
* that can be used for testing builds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Game.hpp"
|
||||||
|
|
||||||
|
class FillScreen : public Game
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* Color component values that will increment each frame to combine into a different solid color. */
|
||||||
|
float red = 1.0f, green = 0.5f, blue = 0.25f;
|
||||||
|
|
||||||
|
/* This gets called every frame by the parent class. Clear the screen with a solid color. */
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
red += 0.004f;
|
||||||
|
green += 0.002f;
|
||||||
|
blue += 0.001f;
|
||||||
|
glClearColor(std::abs(red - int(red) - 0.5f), std::abs(green - int(green) - 0.5f), std::abs(blue - int(blue) - 0.5f), 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
SDL_GL_SwapWindow(window());
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Create a game object, load its GL context, and run the game. */
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
FillScreen fill_screen = FillScreen();
|
||||||
|
fill_screen.load_gl_context();
|
||||||
|
fill_screen.run();
|
||||||
|
fill_screen.quit();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue