-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.monkey2
63 lines (49 loc) · 1.27 KB
/
image.monkey2
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
Namespace mijo
#Import "<std>"
#Import "<sdl2>"
Using std..
Using sdl2..
Class Image Extends Resource
Field width:Int
Field height:Int
Private
Field _texture:SDL_Texture Ptr=Null
Public
Method New(pixm:Pixmap)
Local depth := 32
Local pitch := 4*pixm.Width
Local pixel_format := SDL_PIXELFORMAT_RGBA32
Local dataVoidPtr:=Cast<Void Ptr>(pixm.Data)
Local surface:SDL_Surface Ptr = SDL_CreateRGBSurfaceWithFormatFrom(dataVoidPtr, pixm.Width, pixm.Height, depth, pitch, pixel_format)
If surface = Null
Print "could not create surface in Image.New(pixmap)"
Return
End
width=pixm.Width
height=pixm.Height
_texture=SDL_CreateTextureFromSurface(MIJO_SDL_RENDERER, surface)
If _texture=Null
Print "Failed creating SDL_Texture in mijo.Image"
Local str:=String.FromCString(SDL_GetError())
End
SDL_FreeSurface(surface)
surface = Null
End
Function Load:Image(path:String)
Local tempPixmap:=Pixmap.Load(path,PixelFormat.RGBA32)
If Not tempPixmap
Print "failed to load pixmap at "+path
Return Null
End
Return New Image(tempPixmap)
End
Method OnDiscard() Override
SDL_DestroyTexture(_texture)
End
Method OnFinalize() Override
SDL_DestroyTexture(_texture)
End
Property Texture:SDL_Texture Ptr()
Return _texture
End
End