Skip to content

Bug with libctru where background colours appear behind text when its not been exclusively programmed to #579

@hoffmeister-3ds

Description

@hoffmeister-3ds

What's the issue you encountered?
My 3DS homebrew project, which displays text on the top screen, shows corrupted output with libctru 2.5.0-2. The issues include:
Framebuffer reported as 240x400 (rotated 90 degrees counterclockwise) instead of the expected 400x240, causing vertical rectangles and rotated/mirrored text.

Incorrect colours: red background (\x1b[41m or RGB: 255, 0, 0) appears "weird" (pinkish/washed out), grey (\x1b[47m) and black (\x1b[40m) backgrounds are inconsistent.

Console rendering corruption: text like "Hello World!" appears with incorrect backgrounds (e.g., grey instead of black for "Press start to exit").

Earlier attempts showed white backgrounds with horizontal lines.

The project worked correctly with older libctru versions (pre-2.x, e.g., 1.7.0), suggesting a regression. No changes were made to devkitPro tooling beyond updating libctru via pacman -Syu, which installed 2.5.0-2.
How can the issue be reproduced?
Install devkitARM on Windows with libctru 2.5.0-2 (via pacman).

Create a 3DS homebrew project in C:/test with this main.c:
c

#include <3ds.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
aptInit();
gfxInitDefault();
PrintConsole topConsole;
consoleInit(GFX_TOP, &topConsole);
consoleSelect(&topConsole);
printf("\x1b[2J\x1b[41m");
printf("\x1b[2;1H\x1b[37;1m\x1b[47mHello World!\n");
printf("\x1b[3;1H\x1b[37;1m\x1b[47m------------\n");
printf("\x1b[5;1H\x1b[37;1m\x1b[40mPress start to exit\x1b[0m");
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
while (aptMainLoop()) {
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown & KEY_START) break;
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
}
gfxExit();
aptExit();
return 0;
}

Use a standard Makefile with -lctru (mine also references -lsf2d, -lcitro2d, -lcitro3d, but only main.c is compiled).

Compile: cd /c/test; make.

Copy test.3dsx to a 3DS SD card and run via a homebrew launcher.

Expected Output:
Top screen: Vibrant red background, "Hello World!" and "------------" (white on grey), "Press START to exit" (white on black).

Actual Output:
Top screen: White background with horizontal lines, all text on grey (including "Press start to exit"). With framebuffer code (e.g., GSP_BGR8_OES), a weird red background, horizontal grey/black rectangles, and rotated/mirrored text (e.g., "TEST" as "E", "IZ", "I").

Bottom screen (framebuffer debug): Debug: Start, FB: 0x30000000, W: 240, H: 400, Debug: Rendered.

Environment?
Host OS: Windows, using devkitPro’s MSYS2 shell (not cmd or PowerShell).
env.txt excerpt (redacted): DEVKITPRO=/opt/devkitpro, DEVKITARM=/opt/devkitpro/devkitARM.

Official Release: libctru 2.5.0-2 from devkitPro’s pacman repository (confirmed via pacman -Q | grep libctru).

3DS Details: [Please fill in, e.g., Old 3DS XL, firmware 11.17.0-50U].

Additional context?
Environment Details:
Project path: C:/test.

Single source file: source/main.c (confirmed via ls /c/test/source/*.c).

pacman -Syu showed no newer libctru version available as of June 17, 2025.

Attempts to Fix:
Tried GSP_RGB565_OES and GSP_BGR8_OES: Improved red but didn’t fix rotation.

Direct framebuffer writes: Produced rotated 240x400 buffer, garbled text.

ANSI codes: Incorrect colours (e.g., \x1b[41m as magenta, \x1b[40m as grey).

Workaround: Planning to downgrade to libctru 1.7.0 (git clone https://github.com/devkitPro/libctru; git checkout v1.7.0; make; make install), as older code worked with pre-2.x versions.

Suspected Issues:
gfxGetFramebuffer returns incorrect 240x400 dimensions.

Console ANSI colour rendering broken.

Colour mapping issues in gfxInit variants.

I can provide screenshots if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions