Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add video mode sample #678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions samples/set_best_video_mode/Makefile
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions samples/set_best_video_mode/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <hal/debug.h>
#include <hal/video.h>
#include <windows.h>
#include <vector>

// 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<VIDEO_MODE> 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;
}
Loading