-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40fd435
commit 5784be1
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Hexa.NET.SDL2.Image\Hexa.NET.SDL2.Image.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="icon.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using Hexa.NET.SDL2; | ||
using Hexa.NET.SDL2.Image; | ||
|
||
unsafe | ||
{ | ||
if (SDL.SDLInit(SDL.SDL_INIT_VIDEO) < 0) | ||
{ | ||
Console.WriteLine("SDL could not initialize! SDL_Error: " + SDL.SDLGetErrorS()); | ||
return; | ||
} | ||
|
||
SDLImage.IMGInit((int)IMGInitFlags.Png); | ||
|
||
var window = SDL.SDLCreateWindow("SDL Image Example", (int)SDL.SDL_WINDOWPOS_CENTERED_MASK, (int)SDL.SDL_WINDOWPOS_CENTERED_MASK, 600, 600, (uint)SDLWindowFlags.Shown); | ||
if (window == null) | ||
{ | ||
Console.WriteLine("Window could not be created! SDL_Error: " + SDL.SDLGetErrorS()); | ||
SDL.SDLQuit(); | ||
return; | ||
} | ||
|
||
SDLRenderer* renderer = SDL.SDLCreateRenderer(window, -1, (uint)SDLRendererFlags.Accelerated); | ||
if (renderer == null) | ||
{ | ||
Console.WriteLine("Renderer could not be created! SDL_Error: " + SDL.SDLGetErrorS()); | ||
SDL.SDLDestroyWindow(window); | ||
SDL.SDLQuit(); | ||
return; | ||
} | ||
|
||
// Load an image as an SDL surface | ||
SDLSurface* surface = SDLImage.IMGLoad("icon.png"); | ||
if (surface == null) | ||
{ | ||
Console.WriteLine("Unable to load image! SDL_image Error: "); | ||
SDL.SDLDestroyRenderer(renderer); | ||
SDL.SDLDestroyWindow(window); | ||
SDL.SDLQuit(); | ||
return; | ||
} | ||
|
||
// Create a texture from the surface | ||
SDLTexture* texture = SDL.SDLCreateTextureFromSurface(renderer, surface); | ||
SDL.SDLFreeSurface(surface); | ||
|
||
if (texture == null) | ||
{ | ||
Console.WriteLine("Unable to create texture! SDL_Error: " + SDL.SDLGetErrorS()); | ||
SDL.SDLDestroyRenderer(renderer); | ||
SDL.SDLDestroyWindow(window); | ||
SDL.SDLQuit(); | ||
return; | ||
} | ||
|
||
// Clear the screen | ||
SDL.SDLRenderClear(renderer); | ||
|
||
// Render the texture | ||
SDL.SDLRenderCopy(renderer, texture, null, null); | ||
|
||
// Update the screen | ||
SDL.SDLRenderPresent(renderer); | ||
|
||
// Wait for a few seconds | ||
SDL.SDLDelay(5000); | ||
|
||
// Clean up | ||
SDL.SDLDestroyTexture(texture); | ||
SDL.SDLDestroyRenderer(renderer); | ||
SDL.SDLDestroyWindow(window); | ||
SDL.SDLQuit(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters