-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrlimgui_basic.nelua
More file actions
129 lines (104 loc) · 4.46 KB
/
rlimgui_basic.nelua
File metadata and controls
129 lines (104 loc) · 4.46 KB
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
require'raylib'
require 'rlimgui'
--
require'cimgui'
require'simple'
require'IconsFontAwesome6'
local SCREEN_WIDTH: uint16 <comptime> = 1080
local SCREEN_HEIGHT: uint16 <comptime> = 600
--- External functions
local function setupFonts(): *ImFont <cimport> end -- from utils/setupFonts.c
local testDrawRectangle = function()
local rec = rl.rectangle{50, 50, 400, 150}
rl.drawRectangleRec(rec, rl.color{64,166,217,55})
end
local testDrawText = function()
rl.drawText(string.format("%s", _VERSION), 70, 70, 20, rl.DARKBLUE)
rl.drawText(string.format("Raylib v%s", rl.VERSION), 70, 100, 20, rl.DARKBLUE)
rl.drawText("2025/11", 70, 130, 20, rl.DARKBLUE)
local font = rl.getFontDefault()
local position = rl.vector2{150, 160}
rl.drawTextEx(font, "Hello with custom font", position, 24, 2, rl.GRAY)
end
---------
--- main
---------
local main = function()
rl.setConfigFlags(rl.configFlags.VSYNC_HINT | rl.configFlags.WINDOW_RESIZABLE) -- Enable VSYNC
rl.initWindow(SCREEN_WIDTH,SCREEN_HEIGHT, "Raylib.nelua + Dear ImGui + rlImGui")
-- Define our custom camera to look into our 3d world
local camera = rl.camera3D{
rl.vector3{18, 18, 18}, -- Camera position
rl.vector3{0, 0, 0}, -- Camera looking at point
rl.vector3{0, 1, 0}, -- Camera up vector (rotation towards target)
45, -- Camera field-of-view Y
PERSPECTIVE -- Camera projection type
}
local image = rl.loadImage("istockphoto_com-1209065219-128.png") -- https://www.istockphoto.com search "grayscale height map"
local texture = rl.loadTextureFromImage(image) -- Convert image to texture (VRAM)
local mesh = rl.genMeshHeightmap(image, rl.vector3{16, 8, 16}) -- Generate heightmap mesh (RAM and VRAM)
local model = rl.loadModelFromMesh(mesh) -- Load model from generated mesh
local MATERIAL_MAP_DIFFUSE <const> = rl.materialMapIndex.ALBEDO
model.materials.maps.texture = texture -- Set map diffuse texture
local mapPosition = rl.vector3{-8, 0, -8} -- Define model position
rl.unloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
rl.setTargetFPS(60) -- Set our game to run at 60 frames-per-second
rlImGuiSetup(true)
local font = setupFonts()
local mapColor: [3]cfloat = {(255 - 73)/255, (255 - 113)/255, (255 - 166)/255}
local pio = igGetIO()
--------------------
--- Main while loop
--------------------
while not rl.windowShouldClose() do
-- Update
----------------------------------------------------------------------------------
-- TODO: Update your variables here
rl.updateCamera(camera, ORBITAL) -- Set an orbital camera mode
----------------------------------------------------------------------------------
-- Draw
----------------------------------------------------------------------------------
rl.beginDrawing()
rlImGuiBegin()
---------------
-- ImGui block
---------------
pio.FontDefault = font
do
igPushFont(nilptr, 19.0)
defer igPopFont() end
igShowDemoWindow(nilptr)
igBegin("Test Window " .. ICON_FA_DOG , nilptr, 0)
igText("%s", ICON_FA_SUN .. " Sun")
igText("%s", ICON_FA_CLOUD_RAIN .. " Rain" )
igText("Change Color")
igColorEdit3("##Change color", &mapColor, 0)
igEnd()
end
--------------------
-- Raylib draw texts
--------------------
testDrawRectangle()
testDrawText()
------------------------
-- Raylib draw height map
------------------------
rl.clearBackground(rl.BLACK)
rl.beginMode3D(camera)
local color = rl.color{mapColor[0] * 255, mapColor[1] * 255, mapColor[2] * 255, 255}
rl.drawModel(model, mapPosition, 1, color)
rl.drawGrid(20, 1)
rl.endMode3D()
rl.drawTexture(texture, SCREEN_WIDTH - texture.width - 20, 20, rl.WHITE)
rl.drawRectangleLines(SCREEN_WIDTH - texture.width - 20, 20, texture.width, texture.height, rl.WHITE)
rl.drawText(string.format("%i FPS", rl.getFPS()), 10, 10, 20, rl.GRAY)
rl.drawText("Dear ImGui + Raylib.nelua + rlImGui", 50, 250, 20, rl.RAYWHITE)
------------
-- end proc
------------
rlImGuiEnd()
rl.endDrawing()
end -- main while loop end
rl.closeWindow() -- Close window and OpenGL context
end -- main() end
main()