Skip to content

Commit

Permalink
C#
Browse files Browse the repository at this point in the history
  • Loading branch information
expert4pro committed Jan 12, 2018
1 parent defe292 commit 8dc44c3
Show file tree
Hide file tree
Showing 49 changed files with 8,225 additions and 1,649 deletions.
2 changes: 1 addition & 1 deletion 01/01.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{AFCDC194-86C6-411C-9B09-55D83C0E7629}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_01</RootNamespace>
<RootNamespace>SdlExample</RootNamespace>
<AssemblyName>01</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand Down
11 changes: 5 additions & 6 deletions 01/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using SDL2;

namespace _01
namespace SdlExample
{
class Program
{
Expand All @@ -14,10 +14,7 @@ class Program
static int Main(string[] args)
{
//The window we'll be rendering to
IntPtr window = IntPtr.Zero;

//The surface contained by the window
SDL.SDL_Surface screenSurface;
var window = IntPtr.Zero;

//Initialize SDL
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0)
Expand All @@ -36,7 +33,9 @@ static int Main(string[] args)
{
//Get window surface
var myscreenSurface = SDL.SDL_GetWindowSurface(window);
screenSurface = Marshal.PtrToStructure<SDL.SDL_Surface>(myscreenSurface);

//The surface contained by the window
var screenSurface = Marshal.PtrToStructure<SDL.SDL_Surface>(myscreenSurface);

//Fill the surface white
SDL.SDL_FillRect(myscreenSurface, IntPtr.Zero, SDL.SDL_MapRGB(screenSurface.format, 0xFF, 0xFF, 0xFF));
Expand Down
4 changes: 2 additions & 2 deletions 02/02.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{12CB5DE0-90CE-42FD-BA36-3A02E880B1C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_01</RootNamespace>
<AssemblyName>01</AssemblyName>
<RootNamespace>SdlExample</RootNamespace>
<AssemblyName>02</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
47 changes: 24 additions & 23 deletions 02/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Runtime.InteropServices;
using SDL2;

namespace _01
namespace SdlExample
{
class Program
{
Expand All @@ -12,67 +11,69 @@ class Program
private const int SCREEN_HEIGHT = 480;

//The window we'll be rendering to
private static IntPtr gWindow = IntPtr.Zero;
private static IntPtr _Window = IntPtr.Zero;

//The surface contained by the window
private static IntPtr gScreenSurface = IntPtr.Zero;
private static IntPtr _ScreenSurface = IntPtr.Zero;

//The image we will load and show on the screen
private static IntPtr gHelloWorld = IntPtr.Zero;
private static IntPtr _HelloWorld = IntPtr.Zero;

static int Main(string[] args)
{
//Start up SDL and create window
if (!init())
if (Init() == false)
{
Console.WriteLine("Failed to initialize!");
}
else
{
//Load media
if (!loadMedia())
if (LoadMedia() == false)
{
Console.WriteLine("Failed to load media!");
}
else
{
//Apply the image
SDL.SDL_BlitSurface(gHelloWorld, IntPtr.Zero, gScreenSurface, IntPtr.Zero);
SDL.SDL_BlitSurface(_HelloWorld, IntPtr.Zero, _ScreenSurface, IntPtr.Zero);

//Update the surface
SDL.SDL_UpdateWindowSurface(gWindow);
SDL.SDL_UpdateWindowSurface(_Window);

//Wait two seconds
SDL.SDL_Delay(3000);
SDL.SDL_Delay(2000);
}
}

//Free resources and close SDL
close();
Close();

return 0;
}

private static void close()
private static void Close()
{
//Deallocate surface
SDL.SDL_FreeSurface(gHelloWorld);
gHelloWorld = IntPtr.Zero;
SDL.SDL_FreeSurface(_HelloWorld);
_HelloWorld = IntPtr.Zero;

//Destroy window
SDL.SDL_DestroyWindow(gWindow);
gWindow = IntPtr.Zero;
SDL.SDL_DestroyWindow(_Window);
_Window = IntPtr.Zero;

//Quit SDL subsystems
SDL.SDL_Quit();
}

static bool loadMedia()
private static bool LoadMedia()
{
//Loading success flag
bool success = true;

//Load splash image
gHelloWorld = SDL.SDL_LoadBMP("hello_world.bmp");
if (gHelloWorld == IntPtr.Zero)
_HelloWorld = SDL.SDL_LoadBMP("hello_world.bmp");
if (_HelloWorld == IntPtr.Zero)
{
Console.WriteLine("Unable to load image {0}! SDL Error: {1}", "hello_world.bmp", SDL.SDL_GetError());
success = false;
Expand All @@ -81,7 +82,7 @@ static bool loadMedia()
return success;
}

private static bool init()
private static bool Init()
{
//Initialization flag
bool success = true;
Expand All @@ -95,17 +96,17 @@ private static bool init()
else
{
//Create window
gWindow = SDL.SDL_CreateWindow("SDL Tutorial", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
_Window = SDL.SDL_CreateWindow("SDL Tutorial", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
if (gWindow == IntPtr.Zero)
if (_Window == IntPtr.Zero)
{
Console.WriteLine("Window could not be created! SDL_Error: {0}", SDL.SDL_GetError());
success = false;
}
else
{
//Get window surface
gScreenSurface = SDL.SDL_GetWindowSurface(gWindow);
_ScreenSurface = SDL.SDL_GetWindowSurface(_Window);
}
}

Expand Down
4 changes: 2 additions & 2 deletions 03/03.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{2EBDA40E-0519-441C-B321-A8D8B7D23DA5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_01</RootNamespace>
<AssemblyName>01</AssemblyName>
<RootNamespace>SdlExample</RootNamespace>
<AssemblyName>03</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
54 changes: 26 additions & 28 deletions 03/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Runtime.InteropServices;
using SDL2;

namespace _01
namespace SdlExample
{
class Program
{
Expand All @@ -12,25 +11,25 @@ class Program
private const int SCREEN_HEIGHT = 480;

//The window we'll be rendering to
private static IntPtr gWindow = IntPtr.Zero;
private static IntPtr _Window = IntPtr.Zero;

//The surface contained by the window
private static IntPtr gScreenSurface = IntPtr.Zero;
private static IntPtr _ScreenSurface = IntPtr.Zero;

//The image we will load and show on the screen
private static IntPtr gXOut = IntPtr.Zero;
private static IntPtr _XOut = IntPtr.Zero;

static int Main(string[] args)
{
//Start up SDL and create window
if (!init())
if (Init() == false)
{
Console.WriteLine("Failed to initialize!");
}
else
{
//Load media
if (!loadMedia())
if (LoadMedia() == false)
{
Console.WriteLine("Failed to load media!");
}
Expand All @@ -39,59 +38,58 @@ static int Main(string[] args)
//Main loop flag
bool quit = false;

//Event handler
SDL.SDL_Event e;

//While application is running
while (!quit)
{
//Event handler
SDL.SDL_Event e;

//Handle events on queue
while (SDL.SDL_PollEvent(out e) != 0)
{
//User requests quit
if (e.type == SDL.SDL_EventType.SDL_QUIT)
{
quit = true;
}
}

//Apply the image
SDL.SDL_BlitSurface(gXOut, IntPtr.Zero, gScreenSurface, IntPtr.Zero);
SDL.SDL_BlitSurface(_XOut, IntPtr.Zero, _ScreenSurface, IntPtr.Zero);

//Update the surface
SDL.SDL_UpdateWindowSurface(gWindow);
SDL.SDL_UpdateWindowSurface(_Window);
}
}
}

//Free resources and close SDL
close();
Close();

//Console.ReadLine();
return 0;
}

private static void close()
private static void Close()
{
//Deallocate surface
SDL.SDL_FreeSurface(gXOut);
gXOut = IntPtr.Zero;
SDL.SDL_FreeSurface(_XOut);
_XOut = IntPtr.Zero;

//Destroy window
SDL.SDL_DestroyWindow(gWindow);
gWindow = IntPtr.Zero;
SDL.SDL_DestroyWindow(_Window);
_Window = IntPtr.Zero;

//Quit SDL subsystems
SDL.SDL_Quit();
}

static bool loadMedia()
private static bool LoadMedia()
{
//Loading success flag
bool success = true;

//Load splash image
gXOut = SDL.SDL_LoadBMP("x.bmp");
if (gXOut == IntPtr.Zero)
_XOut = SDL.SDL_LoadBMP("x.bmp");
if (_XOut == IntPtr.Zero)
{
Console.WriteLine("Unable to load image {0}! SDL Error: {1}", "x.bmp", SDL.SDL_GetError());
success = false;
Expand All @@ -100,7 +98,7 @@ static bool loadMedia()
return success;
}

private static bool init()
private static bool Init()
{
//Initialization flag
bool success = true;
Expand All @@ -114,21 +112,21 @@ private static bool init()
else
{
//Create window
gWindow = SDL.SDL_CreateWindow("SDL Tutorial", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
_Window = SDL.SDL_CreateWindow("SDL Tutorial", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
if (gWindow == IntPtr.Zero)
if (_Window == IntPtr.Zero)
{
Console.WriteLine("Window could not be created! SDL_Error: {0}", SDL.SDL_GetError());
success = false;
}
else
{
//Get window surface
gScreenSurface = SDL.SDL_GetWindowSurface(gWindow);
_ScreenSurface = SDL.SDL_GetWindowSurface(_Window);
}
}

return success;
}
}
}
}
4 changes: 2 additions & 2 deletions 04/04.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{726AACAE-F425-4BD3-9F35-78E2D2CE3E18}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_01</RootNamespace>
<AssemblyName>01</AssemblyName>
<RootNamespace>SdlExample</RootNamespace>
<AssemblyName>04</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Loading

0 comments on commit 8dc44c3

Please sign in to comment.