-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextures.bah
61 lines (50 loc) · 1.79 KB
/
textures.bah
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
/////////////////////////////////////////////////////////////
// Textures demo using OpenGL and GLUT in Bah. //
// To compile, use 'bah ./textures.bah -d'. //
// //
// © Aloïs Laurent Boë //
/////////////////////////////////////////////////////////////
#import "iostream.bah"
#import "time.bah"
#import "rand.bah"
#import "../vbah.bah"
win = new window
tex1 rgb
tex2 rgb
display() {
//draw a box with the imported bmp as texture
drawBox(vec(0.0, 0.0), 0.50, 0.50, tex1)
//tex2 has dimensions 200px per 200px
tex2Dim = vec(200.0, 200.0)
//convert its dimension to window coordinates dimensions
pixelsDimToCoords(&tex2Dim)
//draw a second box below the first with tex2 as texture
drawBox(vec(0.0, win.bb + tex2Dim.y / 2.0), tex2Dim.x, tex2Dim.y, tex2)
}
// the function that will draw to tex2
// notice that the coordinates system is now in pixels
// with [0.0;0.0] beeing the top left corner
tex2DrawFn(arg ptr) {
//sets the background of the texture white
drawBox(vec(100.0, 100.0), 200.0, 200.0, rgb(1.0, 1.0, 1.0))
//draws a red circle in the middle
drawCircle(vec(100.0, 100.0), 50.0, rgb(1.0, 0.0, 0.0))
}
init() {
//imports the bmp image and saves it inside a texture "tex1"
//Note: texture from: https://www.vecteezy.com/free-vector/lines
tex1 = rgbTexture("./assets/tex.bmp", 1920, 1229)
//makes a new texture "tex2"
tex2 = makeTexture(200, 200)
//draw to tex2 with the tex2DrawFn function
tex2.drawTo(tex2DrawFn, null)
}
main(args []str) int {
//launching the window
win = window(600, 600, "Textures")
win.display = display
win.autoLoop = false
win.init = init
win.launch()
return 0
}