1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
# Window Configuration Guide
Complete guide for setting up window size, fullscreen, and window management in ReiLua-Enhanced.
## Table of Contents
- [Window Size](#window-size)
- [Fullscreen Mode](#fullscreen-mode)
- [Window Flags](#window-flags)
- [Window States](#window-states)
- [Complete Examples](#complete-examples)
## Window Size
### Initial Window Size
Set window size when initializing:
```lua
-- Method 1: Default size (uses RayLib's default: 800x450)
function RL.init()
RL.SetWindowTitle("My Game")
end
-- Method 2: Set specific size after init
function RL.init()
RL.SetWindowTitle("My Game")
RL.SetWindowSize({1280, 720}) -- 1280x720 window
end
-- Method 3: Manual InitWindow (in RL.config, advanced)
function RL.config()
RL.InitWindow({1920, 1080}, "My Game")
end
```
### Change Window Size During Runtime
```lua
-- Resize window to 1920x1080
RL.SetWindowSize({1920, 1080})
-- Get current window size
local size = RL.GetScreenSize()
print("Width: " .. size[1] .. ", Height: " .. size[2])
-- Common resolutions
RL.SetWindowSize({800, 600}) -- 4:3 ratio
RL.SetWindowSize({1280, 720}) -- HD (720p)
RL.SetWindowSize({1920, 1080}) -- Full HD (1080p)
RL.SetWindowSize({2560, 1440}) -- QHD (1440p)
RL.SetWindowSize({3840, 2160}) -- 4K (2160p)
```
### Resizable Window
Allow users to resize the window:
```lua
function RL.init()
-- Enable window resizing
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
-- Optional: Set min/max size constraints
RL.SetWindowMinSize({800, 600})
RL.SetWindowMaxSize({1920, 1080})
end
function RL.update(dt)
-- Check if window was resized
if RL.IsWindowResized() then
local size = RL.GetScreenSize()
print("Window resized to: " .. size[1] .. "x" .. size[2])
-- Update your game viewport/camera if needed
end
end
```
## Fullscreen Mode
### Toggle Fullscreen
```lua
-- Simple toggle (F11 or F1 key)
function RL.update(dt)
if RL.IsKeyPressed(RL.KEY_F11) then
RL.ToggleFullscreen()
end
end
-- The template already includes this with F1 and F11
```
### Set Fullscreen at Startup
```lua
function RL.init()
RL.SetWindowTitle("My Game")
-- Start in fullscreen mode
RL.SetWindowState(RL.FLAG_FULLSCREEN_MODE)
end
```
### Borderless Fullscreen (Windowed Fullscreen)
Better alternative to true fullscreen - faster alt-tab, no resolution change:
```lua
function RL.update(dt)
if RL.IsKeyPressed(RL.KEY_F11) then
RL.ToggleBorderlessWindowed()
end
end
-- Or at startup
function RL.init()
RL.SetWindowTitle("My Game")
RL.ToggleBorderlessWindowed()
end
```
### Check Fullscreen Status
```lua
if RL.IsWindowFullscreen() then
print("Running in fullscreen")
else
print("Running in windowed mode")
end
```
### Different Fullscreen Modes
```lua
-- Method 1: True fullscreen (changes display resolution)
RL.SetWindowState(RL.FLAG_FULLSCREEN_MODE)
-- Method 2: Borderless windowed (keeps desktop resolution)
RL.ToggleBorderlessWindowed()
-- Method 3: Toggle between windowed and last fullscreen mode
RL.ToggleFullscreen()
```
## Window Flags
Window flags control various window behaviors. Set them before or after initialization.
### Common Window Flags
```lua
-- VSync (synchronize with monitor refresh rate)
RL.SetWindowState(RL.FLAG_VSYNC_HINT)
-- Fullscreen mode
RL.SetWindowState(RL.FLAG_FULLSCREEN_MODE)
-- Resizable window
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
-- Borderless window (no title bar)
RL.SetWindowState(RL.FLAG_WINDOW_UNDECORATED)
-- Always on top
RL.SetWindowState(RL.FLAG_WINDOW_TOPMOST)
-- Hidden window (start hidden)
RL.SetWindowState(RL.FLAG_WINDOW_HIDDEN)
-- Transparent window
RL.SetWindowState(RL.FLAG_WINDOW_TRANSPARENT)
-- High DPI support
RL.SetWindowState(RL.FLAG_WINDOW_HIGHDPI)
-- MSAA 4x antialiasing
RL.SetWindowState(RL.FLAG_MSAA_4X_HINT)
```
### Combining Multiple Flags
You can't OR flags in Lua, so set them individually:
```lua
function RL.init()
RL.SetWindowTitle("My Game")
-- Set multiple flags
RL.SetWindowState(RL.FLAG_VSYNC_HINT)
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
RL.SetWindowState(RL.FLAG_MSAA_4X_HINT)
end
```
### Check if Flag is Enabled
```lua
if RL.IsWindowState(RL.FLAG_WINDOW_RESIZABLE) then
print("Window is resizable")
end
if RL.IsWindowState(RL.FLAG_VSYNC_HINT) then
print("VSync is enabled")
end
```
### Clear Window Flags
```lua
-- Remove a specific flag
RL.ClearWindowState(RL.FLAG_WINDOW_TOPMOST)
-- Remove resizable flag
RL.ClearWindowState(RL.FLAG_WINDOW_RESIZABLE)
```
## Window States
### Maximize/Minimize
```lua
-- Maximize window (fill screen without fullscreen)
RL.MaximizeWindow()
-- Minimize window (to taskbar)
RL.MinimizeWindow()
-- Restore window
RL.RestoreWindow()
```
### Check Window State
```lua
-- Check if window is maximized
if RL.IsWindowMaximized() then
print("Window is maximized")
end
-- Check if window is minimized
if RL.IsWindowMinimized() then
print("Window is minimized")
end
-- Check if window is focused
if RL.IsWindowFocused() then
print("Window has focus")
end
-- Check if window is hidden
if RL.IsWindowHidden() then
print("Window is hidden")
end
```
### Window Position
```lua
-- Set window position on screen
RL.SetWindowPosition({100, 100}) -- x, y from top-left of screen
-- Get current window position
local pos = RL.GetWindowPosition()
print("Window at: " .. pos[1] .. ", " .. pos[2])
-- Center window on monitor
local monitorWidth = RL.GetMonitorWidth(0)
local monitorHeight = RL.GetMonitorHeight(0)
local windowSize = RL.GetScreenSize()
RL.SetWindowPosition({
(monitorWidth - windowSize[1]) / 2,
(monitorHeight - windowSize[2]) / 2
})
```
### Monitor Information
```lua
-- Get number of monitors
local monitorCount = RL.GetMonitorCount()
-- Get monitor dimensions
local width = RL.GetMonitorWidth(0) -- Monitor 0 (primary)
local height = RL.GetMonitorHeight(0)
-- Get monitor name
local name = RL.GetMonitorName(0)
print("Monitor: " .. name)
-- Get current monitor
local currentMonitor = RL.GetCurrentMonitor()
```
## Complete Examples
### Example 1: Game with Options Menu
```lua
-- config.lua
local Config = {
resolution = {1280, 720},
fullscreen = false,
vsync = true,
resizable = true
}
function Config.apply()
-- Apply resolution
RL.SetWindowSize(Config.resolution)
-- Apply fullscreen
if Config.fullscreen then
if not RL.IsWindowFullscreen() then
RL.ToggleBorderlessWindowed()
end
else
if RL.IsWindowFullscreen() then
RL.ToggleBorderlessWindowed()
end
end
-- Apply VSync
if Config.vsync then
RL.SetWindowState(RL.FLAG_VSYNC_HINT)
else
RL.ClearWindowState(RL.FLAG_VSYNC_HINT)
end
end
-- main.lua
function RL.init()
RL.SetWindowTitle("My Game")
-- Apply saved config
Config.apply()
-- Make window resizable
if Config.resizable then
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
RL.SetWindowMinSize({800, 600})
end
end
```
### Example 2: Adaptive Resolution
```lua
function RL.init()
RL.SetWindowTitle("My Game")
-- Get monitor size
local monitorWidth = RL.GetMonitorWidth(0)
local monitorHeight = RL.GetMonitorHeight(0)
-- Use 80% of monitor size
local width = math.floor(monitorWidth * 0.8)
local height = math.floor(monitorHeight * 0.8)
RL.SetWindowSize({width, height})
-- Center window
RL.SetWindowPosition({
(monitorWidth - width) / 2,
(monitorHeight - height) / 2
})
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
end
```
### Example 3: Dynamic Fullscreen Toggle
```lua
local isFullscreen = false
function toggleFullscreen()
isFullscreen = not isFullscreen
if isFullscreen then
-- Save windowed size before going fullscreen
windowedSize = RL.GetScreenSize()
windowedPos = RL.GetWindowPosition()
-- Go fullscreen
RL.ToggleBorderlessWindowed()
else
-- Restore windowed mode
RL.ToggleBorderlessWindowed()
-- Restore previous size and position
if windowedSize then
RL.SetWindowSize(windowedSize)
RL.SetWindowPosition(windowedPos)
end
end
end
function RL.update(dt)
if RL.IsKeyPressed(RL.KEY_F11) then
toggleFullscreen()
end
end
```
### Example 4: Resolution Presets
```lua
local resolutions = {
{name = "HD", size = {1280, 720}},
{name = "Full HD", size = {1920, 1080}},
{name = "QHD", size = {2560, 1440}},
{name = "Custom", size = {800, 600}}
}
local currentResolution = 2 -- Start with Full HD
function changeResolution(index)
currentResolution = index
local res = resolutions[index]
if RL.IsWindowFullscreen() then
-- Exit fullscreen first
RL.ToggleBorderlessWindowed()
end
RL.SetWindowSize(res.size)
-- Center window after resize
local monitorWidth = RL.GetMonitorWidth(0)
local monitorHeight = RL.GetMonitorHeight(0)
RL.SetWindowPosition({
(monitorWidth - res.size[1]) / 2,
(monitorHeight - res.size[2]) / 2
})
print("Resolution changed to: " .. res.name)
end
-- In options menu:
function drawResolutionOptions()
for i, res in ipairs(resolutions) do
local color = (i == currentResolution) and RL.YELLOW or RL.WHITE
local text = res.name .. " (" .. res.size[1] .. "x" .. res.size[2] .. ")"
-- Draw option...
end
end
```
### Example 5: Template Integration
Update your template's `main.lua`:
```lua
-- Game configuration
local GAME_TITLE = "My Game"
local WINDOW_WIDTH = 1280
local WINDOW_HEIGHT = 720
local TARGET_FPS = 60
local START_FULLSCREEN = false -- Start in fullscreen?
function RL.init()
-- Window setup
RL.SetWindowTitle(GAME_TITLE)
RL.SetWindowSize({WINDOW_WIDTH, WINDOW_HEIGHT})
RL.SetTargetFPS(TARGET_FPS)
-- Window flags
RL.SetWindowState(RL.FLAG_VSYNC_HINT)
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
-- Start fullscreen if configured
if START_FULLSCREEN then
RL.ToggleBorderlessWindowed()
end
-- Disable ESC exit key
RL.SetExitKey(0)
-- Rest of initialization...
end
function RL.update(delta)
-- Global hotkeys
if RL.IsKeyPressed(RL.KEY_F1) or RL.IsKeyPressed(RL.KEY_F11) then
RL.ToggleBorderlessWindowed()
end
-- Handle window resize
if RL.IsWindowResized() then
local newSize = RL.GetScreenSize()
print("Window resized to: " .. newSize[1] .. "x" .. newSize[2])
-- Update your camera/viewport here if needed
end
-- Rest of update...
end
```
## Quick Reference
### Most Used Functions
```lua
-- Size
RL.SetWindowSize({width, height})
RL.GetScreenSize()
-- Fullscreen
RL.ToggleBorderlessWindowed() -- Recommended
RL.ToggleFullscreen() -- Alternative
RL.IsWindowFullscreen()
-- Flags
RL.SetWindowState(RL.FLAG_VSYNC_HINT)
RL.SetWindowState(RL.FLAG_WINDOW_RESIZABLE)
-- State
RL.MaximizeWindow()
RL.MinimizeWindow()
RL.IsWindowResized()
RL.IsWindowFocused()
-- Position
RL.SetWindowPosition({x, y})
RL.GetWindowPosition()
-- Monitor
RL.GetMonitorWidth(0)
RL.GetMonitorHeight(0)
```
## Tips and Best Practices
### Performance
- Use `RL.FLAG_VSYNC_HINT` to prevent screen tearing
- Use borderless fullscreen instead of true fullscreen for faster alt-tab
- Check `IsWindowResized()` before recalculating viewport/camera
### User Experience
- Always provide a fullscreen toggle (F11 is standard)
- Save window size/position preferences
- Offer resolution presets in options menu
- Make window resizable for flexibility
### Compatibility
- Test different resolutions and aspect ratios
- Use `GetMonitorWidth/Height()` to detect screen size
- Don't hardcode UI positions - use percentages or anchors
- Support both windowed and fullscreen modes
---
**Updated**: 2025-11-05
**Template Version**: 1.0
|