1
+ // See https://aka.ms/new-console-template for more information
2
+ using Hexa . NET . SDL2 ;
3
+ using Hexa . NET . SDL2 . Image ;
4
+
5
+ unsafe
6
+ {
7
+ if ( SDL . SDLInit ( SDL . SDL_INIT_VIDEO ) < 0 )
8
+ {
9
+ Console . WriteLine ( "SDL could not initialize! SDL_Error: " + SDL . SDLGetErrorS ( ) ) ;
10
+ return ;
11
+ }
12
+
13
+ SDLImage . IMGInit ( ( int ) IMGInitFlags . Png ) ;
14
+
15
+ var window = SDL . SDLCreateWindow ( "SDL Image Example" , ( int ) SDL . SDL_WINDOWPOS_CENTERED_MASK , ( int ) SDL . SDL_WINDOWPOS_CENTERED_MASK , 600 , 600 , ( uint ) SDLWindowFlags . Shown ) ;
16
+ if ( window == null )
17
+ {
18
+ Console . WriteLine ( "Window could not be created! SDL_Error: " + SDL . SDLGetErrorS ( ) ) ;
19
+ SDL . SDLQuit ( ) ;
20
+ return ;
21
+ }
22
+
23
+ SDLRenderer * renderer = SDL . SDLCreateRenderer ( window , - 1 , ( uint ) SDLRendererFlags . Accelerated ) ;
24
+ if ( renderer == null )
25
+ {
26
+ Console . WriteLine ( "Renderer could not be created! SDL_Error: " + SDL . SDLGetErrorS ( ) ) ;
27
+ SDL . SDLDestroyWindow ( window ) ;
28
+ SDL . SDLQuit ( ) ;
29
+ return ;
30
+ }
31
+
32
+ // Load an image as an SDL surface
33
+ SDLSurface * surface = SDLImage . IMGLoad ( "icon.png" ) ;
34
+ if ( surface == null )
35
+ {
36
+ Console . WriteLine ( "Unable to load image! SDL_image Error: " ) ;
37
+ SDL . SDLDestroyRenderer ( renderer ) ;
38
+ SDL . SDLDestroyWindow ( window ) ;
39
+ SDL . SDLQuit ( ) ;
40
+ return ;
41
+ }
42
+
43
+ // Create a texture from the surface
44
+ SDLTexture * texture = SDL . SDLCreateTextureFromSurface ( renderer , surface ) ;
45
+ SDL . SDLFreeSurface ( surface ) ;
46
+
47
+ if ( texture == null )
48
+ {
49
+ Console . WriteLine ( "Unable to create texture! SDL_Error: " + SDL . SDLGetErrorS ( ) ) ;
50
+ SDL . SDLDestroyRenderer ( renderer ) ;
51
+ SDL . SDLDestroyWindow ( window ) ;
52
+ SDL . SDLQuit ( ) ;
53
+ return ;
54
+ }
55
+
56
+ // Clear the screen
57
+ SDL . SDLRenderClear ( renderer ) ;
58
+
59
+ // Render the texture
60
+ SDL . SDLRenderCopy ( renderer , texture , null , null ) ;
61
+
62
+ // Update the screen
63
+ SDL . SDLRenderPresent ( renderer ) ;
64
+
65
+ // Wait for a few seconds
66
+ SDL . SDLDelay ( 5000 ) ;
67
+
68
+ // Clean up
69
+ SDL . SDLDestroyTexture ( texture ) ;
70
+ SDL . SDLDestroyRenderer ( renderer ) ;
71
+ SDL . SDLDestroyWindow ( window ) ;
72
+ SDL . SDLQuit ( ) ;
73
+ }
0 commit comments