-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RenderWinDemo.exw
83 lines (58 loc) · 1.51 KB
/
RenderWinDemo.exw
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
include std/get.e
include std/io.e
include std/machine.e
include EuSDL2.ew
include flags.e
if SDL_Init(SDL_INIT_EVERYTHING) = -1 then
puts(1,"Failed to init SDL2!\n")
abort(0)
end if
atom win = SDL_CreateWindow("Render Demo",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN)
atom ren = SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED)
atom gfx,tex
gfx = SDL_LoadBMP("SDL.bmp")
tex = SDL_CreateTextureFromSurface(ren,gfx)
if win = -1 then
puts(1,"Failed to create window!\n")
abort(0)
end if
if ren = -1 then
puts(1,"Failed to create renderer!\n")
abort(0)
end if
procedure calc_rect(atom rect,integer sx,integer sy,integer tx,integer ty)
poke4(rect,sx)
poke4(rect+4,sy)
poke4(rect+8,tx)
poke4(rect+12,ty)
end procedure
--atom srect = allocate(10)
atom drect = allocate(10)
--calc_rect(srect,10,10,100,100)
calc_rect(drect,10,10,100,100)
atom key = 0
integer running = 1
while running = 1 do
SDL_PumpEvents()
key = SDL_GetKeyboardState(key)
if (peek(key+SDL_SCANCODE_ESCAPE) > 0) then
running = 0
end if
SDL_SetRenderDrawColor(ren,0,0,0,0)
if SDL_RenderClear(ren) < 0 then
puts(1,"Failed to clear window!\n")
abort(0)
end if
if SDL_RenderCopy(ren,tex,0,drect) < 0 then
puts(1,"Failed to render image!\n")
abort(0)
end if
SDL_RenderPresent(ren)
end while
free(drect)
SDL_FreeSurface(gfx)
SDL_DestroyTexture(tex)
SDL_DestroyRenderer(ren)
SDL_DestroyWindow(win)
SDL_Quit()
28.9