Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created July 8, 2014 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phrohdoh/fd55a65d37a33a41e38e to your computer and use it in GitHub Desktop.
Save phrohdoh/fd55a65d37a33a41e38e to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using SDL2TestGame.RendererSDL2;
namespace SDL2TestGame
{
public class Game
{
static Sdl2Graphics window;
public static void Main(string[] args)
{
window = new Sdl2Graphics(new Size(450, 450));
Run(window);
}
public static void Run(Sdl2Graphics window)
{
var i = 0;
while (!window.ShouldQuit)
{
Console.WriteLine("Tick {0}", ++i);
Console.WriteLine(DateTime.Now);
}
}
}
}
using System;
using System.Drawing;
using SDL2;
using System.IO;
namespace SDL2TestGame.RendererSDL2
{
public class Sdl2Graphics
{
public bool ShouldQuit { get; private set; }
Size size;
IntPtr context, window;
public Sdl2Graphics(Size windowSize)
{
size = windowSize;
Console.WriteLine(File.Exists("SDL2-CS.dll"));
SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 0);
window = SDL.SDL_CreateWindow
(
"SDL2 TestGame",
SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED,
size.Width, size.Height,
SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN
);
SDL.SDL_ShowCursor(1);
context = SDL.SDL_GL_CreateContext(window);
SDL.SDL_GL_MakeCurrent(window, context);
}
void DrawSDLWindow()
{
SDL.SDL_Event e;
SDL.SDL_PollEvent(out e);
if (e.type == SDL.SDL_EventType.SDL_QUIT)
{
ShouldQuit = true;
// return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment