# Desktop (Windows/macOS/Linux) with LWJGL3

> The fast-iteration loop — running, title/rotation, crossfly-lib and the macOS gotcha.

Source: https://crossfly.dev/docs/platforms/desktop-lwjgl3 — CrossFly documentation. Full docs as one file: https://crossfly.dev/llms-full.txt

# Desktop (LWJGL3) 🖥️

**Always** start with desktop: it is the **fast-iteration loop**. There is no Java hot-reload, but the
*cold start* takes seconds — you validate the UI before suffering through mobile build cycles.

## Run
```bash
gradlew :lwjgl3:run
```
The `Lwjgl3Launcher` creates the application: `new Main(true, getCommandline(args))` — `canStart=true` brings the
UI up immediately. `mainClassName` = `dev.crossfly.lwjgl3.Lwjgl3Launcher`.

## Title, size and rotation
```java
Main.setDesktopTitle("Minha App");   // only takes effect on desktop
main.rotate();                        // simulates rotation (swaps width/height) on desktop
```
Dimensions and scale come from `Screen` (`Screen.width`/`height`/`scale`/`minSize`).

## ⚠️ Two desktop prerequisites
- **`crossfly-lib` (JNI)** must be on the `java.library.path` — `Main.create()` calls
  `SharedLibraryLoader.load("crossfly-lib")` at startup (on all targets, **except WebGL**).
- **macOS** requires the JVM flag **`-XstartOnFirstThread`** (an LWJGL3/GLFW requirement on Mac). Without it,
  the app does not open a window.

## Diagnostics
- The global exception handler funnels failures (see [Errors and logging](/docs/best-practices/tratamento-de-erros-e-logging)).
- `Debug.showFPS = true` to see the frame rate.
- Generate screenshots (docs/store): `Main.getScreenShot(true).toPng("prefixo_")`.

## Best practices
- Develop and validate the UI **on desktop**; only move to mobile when the screen is ready.
- Test **rotation** (`rotate()`) and different window sizes to check responsiveness.

## Common mistakes
- Forgetting `-XstartOnFirstThread` on macOS (window does not open).
- `crossfly-lib` outside the `java.library.path` (startup failure).

## See also
- [Build and distribution](/docs/platforms/building-and-releasing) · [Responsiveness](/docs/best-practices/responsividade)
