Quick Overview
libnx is an open-source library for Nintendo Switch homebrew development. It provides a comprehensive set of APIs and tools for creating custom applications and games for the Nintendo Switch console, allowing developers to access various system features and hardware capabilities.
Pros
- Extensive documentation and community support
- Regular updates and maintenance
- Wide range of system features and hardware access
- Cross-platform development support (Linux, macOS, Windows)
Cons
- Requires a modded Nintendo Switch for testing and deployment
- Limited to homebrew applications, not official Nintendo development
- Potential legal concerns due to reverse-engineering of Nintendo's systems
- Learning curve for developers new to console programming
Code Examples
- Initializing the console and printing "Hello World":
#include <stdio.h>
#include <switch.h>
int main(int argc, char *argv[])
{
consoleInit(NULL);
printf("Hello World!");
consoleUpdate(NULL);
while (appletMainLoop())
{
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS)
break;
}
consoleExit(NULL);
return 0;
}
- Reading input from controllers:
#include <switch.h>
void readInput()
{
hidScanInput();
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_A)
printf("A button pressed\n");
if (kDown & KEY_B)
printf("B button pressed\n");
}
- Drawing a simple shape using SDL2:
#include <SDL2/SDL.h>
#include <switch.h>
void drawRectangle(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_Rect rect = {100, 100, 200, 150};
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
}
Getting Started
-
Install devkitPro and libnx:
pacman -S switch-dev
-
Create a new project directory and Makefile:
mkdir my_project && cd my_project wget https://github.com/switchbrew/switch-examples/raw/master/templates/application/Makefile
-
Write your source code (e.g., main.c) and build:
make
-
Deploy the resulting .nro file to your modded Nintendo Switch.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nintendo Switch AArch64-only userland library.
Based on libctru.
Install instructions
See Switchbrew.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot