From 59ddf683bc833ac536cd7fea4c810edec9867382 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:50:56 -0400 Subject: [PATCH] feat: Add video mode sample --- samples/set_best_video_mode/Makefile | 7 +++ samples/set_best_video_mode/main.cpp | 73 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 samples/set_best_video_mode/Makefile create mode 100644 samples/set_best_video_mode/main.cpp diff --git a/samples/set_best_video_mode/Makefile b/samples/set_best_video_mode/Makefile new file mode 100644 index 000000000..d25ee36e4 --- /dev/null +++ b/samples/set_best_video_mode/Makefile @@ -0,0 +1,7 @@ +XBE_TITLE = nxdk\ sample\ -\ set_best_video_mode +GEN_XISO = $(XBE_TITLE).iso +SRCS = $(CURDIR)/main.cpp +NXDK_DIR ?= $(CURDIR)/../.. +NXDK_CXX = y + +include $(NXDK_DIR)/Makefile diff --git a/samples/set_best_video_mode/main.cpp b/samples/set_best_video_mode/main.cpp new file mode 100644 index 000000000..1bf84217e --- /dev/null +++ b/samples/set_best_video_mode/main.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +// Screen dimension globals +static int SCREEN_WIDTH = 640; +static int SCREEN_HEIGHT = 480; + +int main(void) +{ + // set the default video mode + XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, REFRESH_DEFAULT); + + // create an empty list for the available video modes + std::vector availableVideoModes; + + // save the best video mode here + VIDEO_MODE bestVideoMode = {0, 0, 0, 0}; + + VIDEO_MODE vm; + int bpp = 32; // Bits per pixel + void *p = NULL; // Initialize to NULL for the first call + + // get the available video modes + while (XVideoListModes(&vm, bpp, REFRESH_DEFAULT, &p)) { + availableVideoModes.push_back(vm); + + // ensure height is equal to or better than the current best video mode + if (vm.height < bestVideoMode.height) { + continue; + } + + // ensure width is equal to or better than the current best video mode + if (vm.width < bestVideoMode.width) { + continue; + } + + // ensure bpp is equal to or better than the current best video mode + if (vm.bpp < bestVideoMode.bpp) { + continue; + } + + // ensure refresh is equal to or better than the current best video mode + if (vm.refresh < bestVideoMode.refresh) { + continue; + } + + // save the best video mode + bestVideoMode = vm; + } + + SCREEN_WIDTH = bestVideoMode.width; + SCREEN_HEIGHT = bestVideoMode.height; + + debugPrint("Available video modes:\n"); + for (VIDEO_MODE vm : availableVideoModes) { + debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", vm.width, vm.height, vm.bpp, vm.refresh); + } + Sleep(2000); + + // set the best video mode + XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, bestVideoMode.bpp, bestVideoMode.refresh); + + debugPrint("Best video mode:\n"); + debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", bestVideoMode.width, bestVideoMode.height, bestVideoMode.bpp, bestVideoMode.refresh); + + while (1) { + Sleep(1000); + } + + return 0; +}