summaryrefslogtreecommitdiff
path: root/examples/image_draw/main.lua
blob: ac8e7e6c35ca9af168e755d87c10bae8b8960872 (plain)
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
local monitor = 0
local texture = -1
local image = -1
local catImage = -1
local catCopy = -1
local textImage = -1

function RL.init()
	local mPos = RL.GetMonitorPosition( monitor )
	local mSize = RL.GetMonitorSize( monitor )
	local winSize = RL.GetScreenSize()

	RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
	RL.SetWindowState( RL.FLAG_VSYNC_HINT )
	RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
	image = RL.GenImageColor( winSize, RL.WHITE )
	-- Test changing working directory.
	RL.ChangeDirectory( RL.GetBasePath().."../resources" )
	catImage = RL.LoadImage( RL.GetWorkingDirectory().."/images/cat.png" )
	RL.ImageClearBackground( image, { 150, 60, 100 } )
	RL.ImageDrawPixel( image, { 32, 32 }, RL.WHITE )
	RL.ImageDrawLine( image, { 32, 45 }, { 100, 60 }, RL.GREEN )
	RL.ImageDrawCircle( image, { 64, 32 }, 16, RL.BLUE )
	RL.ImageDrawRectangle( image, { 120, 64, 32, 64 }, RL.BLUE )
	RL.ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, RL.BLUE )
	RL.ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, RL.WHITE )
	RL.ImageDrawTextEx( image, RL.defaultFont, "Hello", { 300, 32 }, 48.0, 1.0, RL.WHITE )

	local src = { 80, 70, 96, 96 }
	catCopy = RL.ImageFromImage( catImage, src )

	RL.ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, RL.WHITE )

	textImage = RL.ImageText( RL.defaultFont, "Cat", 10, 4, RL.WHITE )
	local imageSize = RL.GetImageSize( textImage )
	RL.ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, RL.WHITE )

	texture = RL.LoadTextureFromImage( image )
end

function RL.draw()
	RL.ClearBackground( { 100, 150, 100 } )
	RL.DrawTexture( texture, { 0, 0 }, RL.WHITE )
end