commit 160d61945736d91f9cc7d1f69227b1fec641c1ad
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sat Nov 14 09:07:31 2020 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sat Nov 14 09:07:31 2020 -0700
WIP getting sdl2 build working (rendering at 1x)
---
.gitignore | 4 +
Makefile | 12 +-
platform/SDL2/Makefile | 179 +++++++++++-------
platform/SDL2/Makefile.bu | 69 +++++++
.../SDL2/source/{SDL2Host.ignore => SDL2Host.cpp} | 210 +++++++++------------
platform/SDL2/source/main.cpp | 76 --------
platform/SDL2/source/testmain.dontcompile | 41 ++++
7 files changed, 327 insertions(+), 264 deletions(-)
diff --git a/.gitignore b/.gitignore
index 22f85e9..8b2079b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,7 @@ libs/lua-5.3.2/src/liblua.a
libs/z8lua/*.o
libs/z8lua/liblua.a
platform/SDL2/obj/*.o
+platform/SDL2/*.d
+platform/SDL2/fake08
+platform/SDL2/FAKE08
+pico.log
diff --git a/Makefile b/Makefile
index 11b63bf..bcbe7c8 100644
--- a/Makefile
+++ b/Makefile
@@ -6,11 +6,11 @@ ROOT_INCLUDES ?= include
export SOURCES = ../../source ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng
export INCLUDES = ../../include ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng
-.PHONY: all 3ds switch clean clean-3ds clean-switch
+.PHONY: all 3ds switch sdl2 clean clean-3ds clean-switch clean-sdl2
-all: 3ds switch
+all: 3ds switch sdl2
-clean: clean-tests clean-3ds clean-switch
+clean: clean-tests clean-3ds clean-switch clean-sdl2
clean-3ds:
@$(MAKE) -C platform/3ds clean
@@ -18,6 +18,9 @@ clean-3ds:
clean-switch:
@$(MAKE) -C platform/switch clean
+clean-sdl2:
+ @$(MAKE) -C platform/SDL2 clean
+
3ds:
@$(MAKE) -C platform/3ds
@@ -27,6 +30,9 @@ cia:
switch:
@$(MAKE) -C platform/switch
+sdl2:
+ @$(MAKE) -C platform/SDL2
+
clean-tests:
@$(MAKE) -C test clean
diff --git a/platform/SDL2/Makefile b/platform/SDL2/Makefile
index f9686e9..ebad1dd 100644
--- a/platform/SDL2/Makefile
+++ b/platform/SDL2/Makefile
@@ -1,69 +1,120 @@
-########################################################################
-####################### Makefile Template ##############################
-########################################################################
-
-# Compiler settings - Can be customized.
-CC = g++
-CXXFLAGS = -std=c++17 -Wall -g
-LDFLAGS = -lSDL2 -lGL -lGLEW
-
-# Makefile settings - Can be customized.
-APPNAME = fake08
-EXT = .cpp
-SRCDIR = source
-OBJDIR = obj
-
-############## Do not change anything from here downwards! #############
-SRC = $(wildcard $(SRCDIR)/*$(EXT))
-OBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)/%.o)
-DEP = $(OBJ:$(OBJDIR)/%.o=%.d)
-# UNIX-based OS variables & settings
-RM = rm
-DELOBJ = $(OBJ)
-# Windows OS variables & settings
-DEL = del
-EXE = .exe
-WDELOBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)\\%.o)
-
-########################################################################
-####################### Targets beginning here #########################
-########################################################################
-
-all: $(APPNAME)
-
-# Builds the app
-$(APPNAME): $(OBJ)
- $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
-# Creates the dependecy rules
-%.d: $(SRCDIR)/%$(EXT)
- @$(CPP) $(CFLAGS) $< -MM -MT $(@:%.d=$(OBJDIR)/%.o) >$@
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing header files
+#
+#---------------------------------------------------------------------------------
+TARGET := FAKE08
+BUILD := build
+SOURCES := ${SOURCES} source
+INCLUDES := ${INCLUDES}
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+CC = $(CXX)
+
+CFLAGS := -g -Wall -O2 -ffunction-sections \
+ $(DEFINES)
+
+CFLAGS += $(INCLUDE)
+
+CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17
+
+ASFLAGS := -g $(ARCH)
+
+LIBS := -lSDL2 -lstdc++fs
+
+LDFLAGS := $(LIBS)
+
+
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#---------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+export TOPDIR := $(CURDIR)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
-# Includes all .h files
--include $(DEP)
+export OFILES_BIN := $(addsuffix .o,$(BINFILES))
+export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+export OFILES := $(OFILES_BIN) $(OFILES_SRC)
+export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
-# Building rule for .o files and its .c/.cpp in combination with all .h
-$(OBJDIR)/%.o: $(SRCDIR)/%$(EXT)
- $(CC) $(CXXFLAGS) -o $@ -c $<
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
-################### Cleaning rules for Unix-based OS ###################
-# Cleans complete project
-.PHONY: clean
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+
+.PHONY: $(BUILD) clean all
+
+#---------------------------------------------------------------------------------
+all: $(BUILD)
+
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
clean:
- $(RM) $(DELOBJ) $(DEP) $(APPNAME)
-
-# Cleans only all files with the extension .d
-.PHONY: cleandep
-cleandep:
- $(RM) $(DEP)
-
-#################### Cleaning rules for Windows OS #####################
-# Cleans complete project
-.PHONY: cleanw
-cleanw:
- $(DEL) $(WDELOBJ) $(DEP) $(APPNAME)$(EXE)
-
-# Cleans only all files with the extension .d
-.PHONY: cleandepw
-cleandepw:
- $(DEL) $(DEP)
\ No newline at end of file
+ @echo clean ...
+ @rm -fr $(BUILD) $(TARGET)
+
+
+#---------------------------------------------------------------------------------
+else
+.PHONY: all
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+all : $(OUTPUT)
+
+$(OUTPUT) : $(OFILES)
+ $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
+
+$(OFILES_SRC) : $(HFILES_BIN)
+
+#---------------------------------------------------------------------------------
+# you need a rule like this for each extension you use as binary data
+#---------------------------------------------------------------------------------
+%.bin.o %_bin.h : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/platform/SDL2/Makefile.bu b/platform/SDL2/Makefile.bu
new file mode 100644
index 0000000..25b03f9
--- /dev/null
+++ b/platform/SDL2/Makefile.bu
@@ -0,0 +1,69 @@
+########################################################################
+####################### Makefile Template ##############################
+########################################################################
+
+# Compiler settings - Can be customized.
+CC = g++
+CXXFLAGS = -std=c++17 -Wall -g
+LDFLAGS = -lSDL2
+
+# Makefile settings - Can be customized.
+APPNAME = fake08
+EXT = .cpp
+SRCDIR = source
+OBJDIR = obj
+
+############## Do not change anything from here downwards! #############
+SRC = $(wildcard $(SRCDIR)/*$(EXT))
+OBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)/%.o)
+DEP = $(OBJ:$(OBJDIR)/%.o=%.d)
+# UNIX-based OS variables & settings
+RM = rm
+DELOBJ = $(OBJ)
+# Windows OS variables & settings
+DEL = del
+EXE = .exe
+WDELOBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)\\%.o)
+
+########################################################################
+####################### Targets beginning here #########################
+########################################################################
+
+all: $(APPNAME)
+
+# Builds the app
+$(APPNAME): $(OBJ)
+ $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
+
+# Creates the dependecy rules
+%.d: $(SRCDIR)/%$(EXT)
+ @$(CPP) $(CFLAGS) $< -MM -MT $(@:%.d=$(OBJDIR)/%.o) >$@
+
+# Includes all .h files
+-include $(DEP)
+
+# Building rule for .o files and its .c/.cpp in combination with all .h
+$(OBJDIR)/%.o: $(SRCDIR)/%$(EXT)
+ $(CC) $(CXXFLAGS) -o $@ -c $<
+
+################### Cleaning rules for Unix-based OS ###################
+# Cleans complete project
+.PHONY: clean
+clean:
+ $(RM) $(DELOBJ) $(DEP) $(APPNAME)
+
+# Cleans only all files with the extension .d
+.PHONY: cleandep
+cleandep:
+ $(RM) $(DEP)
+
+#################### Cleaning rules for Windows OS #####################
+# Cleans complete project
+.PHONY: cleanw
+cleanw:
+ $(DEL) $(WDELOBJ) $(DEP) $(APPNAME)$(EXE)
+
+# Cleans only all files with the extension .d
+.PHONY: cleandepw
+cleandepw:
+ $(DEL) $(DEP)
\ No newline at end of file
diff --git a/platform/SDL2/source/SDL2Host.ignore b/platform/SDL2/source/SDL2Host.cpp
similarity index 60%
rename from platform/SDL2/source/SDL2Host.ignore
rename to platform/SDL2/source/SDL2Host.cpp
index 71ce4de..fa5d731 100644
--- a/platform/SDL2/source/SDL2Host.ignore
+++ b/platform/SDL2/source/SDL2Host.cpp
@@ -6,88 +6,56 @@
#include <fstream>
#include <iostream>
-#include <filesystem>
using namespace std;
-namespace fs = std::filesystem;
#include "../../../source/host.h"
#include "../../../source/hostVmShared.h"
#include "../../../source/nibblehelpers.h"
-#define FB_WIDTH 1280
-#define FB_HEIGHT 720
+// sdl
+#include <SDL2/SDL.h>
+
+#define SCREEN_SIZE_X 512
+#define SCREEN_SIZE_Y 512
+
#define SAMPLERATE 22050
#define SAMPLESPERBUF (SAMPLERATE / 30)
#define NUM_BUFFERS 2
-const int __screenWidth = FB_WIDTH;
-const int __screenHeight = FB_HEIGHT;
+const int __screenWidth = SCREEN_SIZE_X;
+const int __screenHeight = SCREEN_SIZE_Y;
const int PicoScreenWidth = 128;
const int PicoScreenHeight = 128;
StretchOption stretch;
-u64 last_time;
-u64 now_time;
-u64 frame_time;
+uint16_t last_time;
+uint16_t now_time;
+uint16_t frame_time;
double targetFrameTimeMs;
-u32 currKDown;
-u32 currKHeld;
-
-Framebuffer fb;
+uint32_t currKDown;
+uint32_t currKHeld;
Color* _paletteColors;
-uint8_t ConvertInputToP8(u32 input){
- uint8_t result = 0;
- if (input & KEY_LEFT){
- result |= P8_KEY_LEFT;
- }
+SDL_Window* window;
+SDL_Event event;
+SDL_Renderer *renderer;
- if (input & KEY_RIGHT){
- result |= P8_KEY_RIGHT;
- }
-
- if (input & KEY_UP){
- result |= P8_KEY_UP;
- }
-
- if (input & KEY_DOWN){
- result |= P8_KEY_DOWN;
- }
-
- if (input & KEY_B){
- result |= P8_KEY_O;
- }
-
- if (input & KEY_A){
- result |= P8_KEY_X;
- }
-
- if (input & KEY_PLUS){
- result |= P8_KEY_PAUSE;
- }
-
- if (input & KEY_MINUS){
- result |= P8_KEY_7;
- }
-
- return result;
-}
void postFlipFunction(){
//flush switch frame buffers
// We're done rendering, so we end the frame here.
- framebufferEnd(&fb);
+ SDL_RenderPresent(renderer);
}
void init_fill_buffer(void *audioBuffer,size_t offset, size_t size) {
- u32 *dest = (u32*)audioBuffer;
+ uint32_t *dest = (uint32_t*)audioBuffer;
for (size_t i=0; i<size; i++) {
dest[i] = 0;
@@ -98,11 +66,11 @@ void init_fill_buffer(void *audioBuffer,size_t offset, size_t size) {
}
bool audioInitialized = false;
-u32 *audioBuffer;
-u32 audioBufferSize;
+uint32_t *audioBuffer;
+uint32_t audioBufferSize;
//ndspWaveBuf waveBuf[2];
bool fillBlock = false;
-u32 currPos;
+uint32_t currPos;
void audioCleanup(){
@@ -117,51 +85,7 @@ void audioCleanup(){
}
void audioSetup(){
- /*
- if(R_FAILED(ndspInit())) {
- return;
- }
-
- //audio setup
- audioBufferSize = SAMPLESPERBUF * NUM_BUFFERS * sizeof(u32);
- audioBuffer = (u32*)linearAlloc(audioBufferSize);
- if(audioBuffer == nullptr) {
- audioCleanup();
- return;
- }
-
-
- ndspSetOutputMode(NDSP_OUTPUT_STEREO);
-
- ndspChnSetInterp(0, NDSP_INTERP_LINEAR);
- ndspChnSetRate(0, SAMPLERATE);
- ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16);
-
- float mix[12];
- memset(mix, 0, sizeof(mix));
- mix[0] = 1.0;
- mix[1] = 1.0;
- ndspChnSetMix(0, mix);
-
- memset(waveBuf,0,sizeof(waveBuf));
- waveBuf[0].data_vaddr = &audioBuffer[0];
- waveBuf[0].nsamples = SAMPLESPERBUF;
- waveBuf[1].data_vaddr = &audioBuffer[SAMPLESPERBUF];
- waveBuf[1].nsamples = SAMPLESPERBUF;
-
-
- size_t stream_offset = 0;
-
- //not sure if this is necessary? if it is, memset might be better?
- init_fill_buffer(audioBuffer,stream_offset, SAMPLESPERBUF * 2);
-
- stream_offset += SAMPLESPERBUF;
- ndspChnWaveBufAdd(0, &waveBuf[0]);
- ndspChnWaveBufAdd(0, &waveBuf[1]);
-
- audioInitialized = true;
- */
}
@@ -173,10 +97,21 @@ void Host::oneTimeSetup(Color* paletteColors){
audioSetup();
- NWindow* win = nwindowGetDefault();
+ // ----- Initialize SDL
+ if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
+ {
+ fprintf(stderr, "SDL could not initialize\n");
+ return;
+ }
+
+ // ----- Create window
+ SDL_CreateWindowAndRenderer(SCREEN_SIZE_X, SCREEN_SIZE_Y, 0, &window, &renderer);
+ if (!window)
+ {
+ fprintf(stderr, "Error creating window.\n");
+ return;
+ }
- framebufferCreate(&fb, win, FB_WIDTH, FB_HEIGHT, PIXEL_FORMAT_RGBA_8888, 2);
- framebufferMakeLinear(&fb);
last_time = 0;
now_time = 0;
@@ -189,7 +124,9 @@ void Host::oneTimeSetup(Color* paletteColors){
void Host::oneTimeCleanup(){
audioCleanup();
- framebufferClose(&fb);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
}
void Host::setTargetFps(int targetFps){
@@ -197,6 +134,7 @@ void Host::setTargetFps(int targetFps){
}
void Host::changeStretch(){
+ /*
if (currKDown & KEY_R) {
if (stretch == PixelPerfect) {
stretch = PixelPerfectStretch;
@@ -205,39 +143,44 @@ void Host::changeStretch(){
stretch = PixelPerfect;
}
}
+ */
}
void Host::scanInput(){
- hidScanInput();
+ //hidScanInput();
- currKDown = hidKeysDown(CONTROLLER_P1_AUTO);
- currKHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
+ //currKDown = hidKeysDown(CONTROLLER_P1_AUTO);
+ //currKHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
}
uint8_t Host::getKeysDown(){
- return ConvertInputToP8(currKDown);
+ //return ConvertInputToP8(currKDown);
+ return 0;
}
uint8_t Host::getKeysHeld(){
- return ConvertInputToP8(currKHeld);
+ //return ConvertInputToP8(currKHeld);
+ return 0;
}
bool Host::shouldQuit() {
- bool lpressed = currKHeld & KEY_L;
- bool rpressed = currKDown & KEY_R;
+ //bool lpressed = currKHeld & KEY_L;
+ //bool rpressed = currKDown & KEY_R;
- return lpressed && rpressed;
+ //return lpressed && rpressed;
+ return false;
}
const double NANOSECONDS_TO_MILLISECONDS = 1.0 / 1000000.0;
void Host::waitForTargetFps(){
+ /*
now_time = armGetSystemTick();
frame_time = now_time - last_time;
last_time = now_time;
- u64 frameTimeNs = armTicksToNs(frame_time);
+ uint64_t frameTimeNs = armTicksToNs(frame_time);
double frameTimeMs = frameTimeNs * NANOSECONDS_TO_MILLISECONDS;
//sleep for remainder of time
@@ -249,10 +192,30 @@ void Host::waitForTargetFps(){
last_time += armNsToTicks(nsToSleep);
}
+ */
}
void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap){
+ //clear screen to all black
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
+ SDL_RenderClear(renderer);
+
+
+ for (int y = 0; y < PicoScreenHeight; y ++)
+ {
+ for (int x = 0; x < PicoScreenWidth; x ++)
+ {
+ uint8_t c = getPixelNibble(x, y, picoFb);
+ //uint8_t c = picoFb[x*128 + y];
+ Color col = _paletteColors[screenPaletteMap[c]];
+
+ SDL_SetRenderDrawColor(renderer, col.Red, col.Green, col.Blue, 255);
+
+ SDL_RenderDrawPoint(renderer, x, y);
+ }
+ }
+ /*
u32 stride;
u32* framebuf = (u32*) framebufferBegin(&fb, &stride);
@@ -288,6 +251,7 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap){
}
}
+ */
postFlipFunction();
}
@@ -316,23 +280,27 @@ void Host::playFilledAudioBuffer(){
}
bool Host::mainLoop(){
- return appletMainLoop();
+ if (SDL_PollEvent(&event) && event.type == SDL_QUIT){
+ return false;
+ }
+
+ return true;
}
vector<string> Host::listcarts(){
vector<string> carts;
- DIR* dir = opendir("/p8carts");
-
- if (dir) {
- for(auto& p: fs::directory_iterator("/p8carts")){
- auto ext = p.path().extension().string();
- if (ext == ".p8" || ext == ".png"){
- carts.push_back(p.path().string());
- }
+ DIR *dir;
+ struct dirent *ent;
+ if ((dir = opendir ("~/p8carts")) != NULL) {
+ /* print all the files and directories within directory */
+ while ((ent = readdir (dir)) != NULL) {
+ carts.push_back(ent->d_name);
}
-
- closedir(dir);
+ closedir (dir);
+ } else {
+ /* could not open directory */
+ perror ("");
}
diff --git a/platform/SDL2/source/main.cpp b/platform/SDL2/source/main.cpp
deleted file mode 100644
index e518554..0000000
--- a/platform/SDL2/source/main.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-// std
-#include <stdio.h>
-
-// opengl
-#include <GL/glew.h>
-
-// sdl
-#include <SDL2/SDL.h>
-
-#define SCREEN_SIZE_X 800
-#define SCREEN_SIZE_Y 600
-
-int main (int argc, char* argv[])
-{
- // ----- Initialize SDL
- if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
- {
- fprintf(stderr, "SDL could not initialize\n");
- return 1;
- }
-
- // ----- Create window
- SDL_Window* window = SDL_CreateWindow("My Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_X, SCREEN_SIZE_Y, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
- if (!window)
- {
- fprintf(stderr, "Error creating window.\n");
- return 2;
- }
-
- // ----- SDL OpenGL settings
- 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);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
-
- // ----- SDL OpenGL context
- SDL_GLContext glContext = SDL_GL_CreateContext(window);
-
- // ----- SDL v-sync
- SDL_GL_SetSwapInterval(1);
-
- // ----- GLEW
- glewInit();
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- // ----- Game loop
- bool quit = false;
- while (quit == false)
- {
- SDL_Event windowEvent;
- while (SDL_PollEvent(&windowEvent))
- {
- if (windowEvent.type == SDL_QUIT)
- {
- quit = true;
- break;
- }
- }
-
- /*
- do drawing here
- */
-
- SDL_GL_SwapWindow(window);
- }
-
- // ----- Clean up
- SDL_GL_DeleteContext(glContext);
-
- return 0;
-}
\ No newline at end of file
diff --git a/platform/SDL2/source/testmain.dontcompile b/platform/SDL2/source/testmain.dontcompile
new file mode 100644
index 0000000..83c31ce
--- /dev/null
+++ b/platform/SDL2/source/testmain.dontcompile
@@ -0,0 +1,41 @@
+// std
+#include <stdio.h>
+
+// sdl
+#include <SDL2/SDL.h>
+
+#define SCREEN_SIZE_X 512
+#define SCREEN_SIZE_Y 512
+#define WINDOW_WIDTH 512
+
+SDL_Event event;
+SDL_Renderer *renderer;
+SDL_Window *window;
+
+
+//example of rendering to texture then copying to screen:
+//https://github.com/cirosantilli/cpp-cheat/blob/0607da1236030d2e1ec56256a0d12cadb6924a41/sdl/plot2d.c
+int test_main (int argc, char* argv[])
+{
+
+ int i;
+
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_CreateWindowAndRenderer(SCREEN_SIZE_X, SCREEN_SIZE_Y, 0, &window, &renderer);
+
+ while (1) {
+ if (SDL_PollEvent(&event) && event.type == SDL_QUIT)
+ break;
+
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
+ SDL_RenderClear(renderer);
+ SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
+ for (i = 0; i < WINDOW_WIDTH; ++i)
+ SDL_RenderDrawPoint(renderer, i, i);
+ SDL_RenderPresent(renderer);
+ }
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+ return EXIT_SUCCESS;
+}
\ No newline at end of file