-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
WinImage.exw
77 lines (54 loc) · 1.39 KB
/
WinImage.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
include std/machine.e
include EuSDL2.ew
include flags.e
atom width = 800, height = 600
atom buffer,format
atom x
x = SDL_Init(SDL_INIT_EVERYTHING)
if x = -1 then
puts(1,"Failed to load initialize SDL!\n")
abort(0)
end if
atom win = SDL_CreateWindow("Window Image",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_SHOWN)
if win = -1 then
puts(1,"Failed to create window!\n")
abort(0)
end if
atom surf = SDL_GetWindowSurface(win)
atom img = SDL_LoadBMP("SDL.bmp")
if img = -1 then
puts(1,"Failed to load image!\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,width / 2,height / 2,100,100)
--Use SDL_UpperBlit to draw to screen
--As this replaces SDL_BlitSurface
x = SDL_UpperBlit(img,0,surf,drect)
if x = -1 then
puts(1,"Failed to blit image!\n")
abort(0)
end if
integer running = 1
atom key = 0
while running = 1 do
SDL_PumpEvents()
key = SDL_GetKeyboardState(key)
if peek(key+SDL_SCANCODE_ESCAPE) > 0 then
running = 0
end if
SDL_UpdateWindowSurface(win)
end while
SDL_FreeSurface(img)
SDL_FreeSurface(surf)
SDL_DestroyWindow(win)
SDL_Quit()
43.32