internal static Font INTERNAL_Font_Create(SDLRenderer renderer, int ptSize, string filename) { // Create Font instance var font = new Font(); // Assign the renderer font._sdlRenderer = renderer; // Create from the renderer font._ptSize = ptSize; font._sdlFont = SDL_ttf.TTF_OpenFont(filename, ptSize); if (font._sdlFont == IntPtr.Zero) { font.Dispose(); return(null); } // Fetch the Surface formatting information if (!font.FillOutInfo()) { // Someting dun goned wrung font.Dispose(); return(null); } return(font); }
public override void RenderIcon(int icon, int x, int y) { var fnt = FontEngine.IconFont; if (fnt != null) { x += transX; y += transY; SDL.SDL_Color col = new SDL.SDL_Color(); col.a = 255; col.r = 255; col.g = 255; col.b = 255; IntPtr txt = SDL_ttf.TTF_RenderGlyph_Blended(fnt.GetFont(), (ushort)icon, col); IntPtr txt2 = SDL.SDL_CreateTextureFromSurface(game.ren, txt); SDL.SDL_QueryTexture(txt2, out uint format, out int access, out int w, out int h); int tx = x; int ty = y; SDL.SDL_Rect rect = new SDL.SDL_Rect(); rect.x = tx; rect.y = ty; rect.w = w; rect.h = h; SDL.SDL_RenderCopy(game.ren, txt2, IntPtr.Zero, ref rect); SDL.SDL_DestroyTexture(txt2); SDL.SDL_FreeSurface(txt); } }
protected virtual void Cleanup() { SDL_ttf.TTF_Quit(); SDL.SDL_DestroyRenderer(rendererPtr); SDL.SDL_DestroyWindow(windowPtr); SDL.SDL_Quit(); }
static public void Main() { System.IntPtr window; System.Random rand = new System.Random(); // SDL.SDL_LogSetPriority(SDL.SDL_LOG_CATEGORY_APPLICATION, SDL.SDL_LOG_PRIORITY_INFO); // SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1"); SDL.SDL_WindowFlags flags = 0; // flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; if (SDL.SDL_CreateWindowAndRenderer(WindowWidth, WindowHeight, flags, out window, out Renderer) < 0) { Quit(2); } SDL.SDL_SetWindowTitle(window, "TestTtf"); SDL.SDL_ShowCursor(0); SDL_ttf.TTF_Init(); Font = SDL_ttf.TTF_OpenFont("misaki_gothic.ttf", FontSize); if (LoadSprite("icon.bmp", Renderer) < 0) { Quit(2); } for (int i = 0; i < NumSprites; ++i) { Positions[i].x = rand.Next(WindowWidth - Sprite_w); Positions[i].y = rand.Next(WindowHeight - Sprite_h); Positions[i].w = Sprite_w; Positions[i].h = Sprite_h; Velocities[i].x = 0; Velocities[i].y = 0; while (Velocities[i].x == 0 && Velocities[i].y == 0) { Velocities[i].x = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed; Velocities[i].y = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed; } } Done = 0; sw.Start(); while (Done == 0) { Loop(); } SDL.SDL_DestroyRenderer(Renderer); SDL.SDL_DestroyWindow(window); SDL.SDL_Quit(); SDL_ttf.TTF_CloseFont(Font); SDL_ttf.TTF_Quit(); Quit(0); }
public void RawDraw(string Text, float x = 0, float y = 0) { if (!Engine.WindowOpen) { return; } SDL.SDL_Rect rect = new(); rect.x = 0; rect.y = 0; SDL_ttf.TTF_SizeUTF8(FontPointer, Text, out rect.w, out rect.h); IntPtr sur = SDL_ttf.TTF_RenderUTF8_Blended(FontPointer, Text, Context.Colour); // SDL_Surface* //SDL.SDL_BlitSurface(sur, IntPtr.Zero, Engine.Renderer, ref rect); IntPtr tex = SDL_GPU.GPU_CopyImageFromSurface(sur); SDL_GPU.GPU_SetAnchor(tex, 0f, 0f); // MY TEXT IS ALL CENTERED GPU_Rect r = new(); r.x = 0; r.y = 0; r.w = rect.w; r.h = rect.h; SDL_GPU.GPU_Blit(tex, ref r, Engine.Screen, x, y); SDL_GPU.GPU_FlushBlitBuffer(); SDL.SDL_FreeSurface(sur); SDL_GPU.GPU_FreeImage(tex); }
public static IntPtr CreateTextureFromText(string text, IntPtr font, SDL.SDL_Color color, IntPtr renderer) { var surface = SDL_ttf.TTF_RenderUTF8_Solid(font, text, color); var texture = SDL.SDL_CreateTextureFromSurface(renderer, surface); return(texture); }
protected virtual void Dispose(bool disposing) { if (FontPtr != IntPtr.Zero) // only dispose once! { SDL_ttf.TTF_CloseFont(FontPtr); } }
public void UpdateFontString(string strOutput, SDL.SDL_Rect dstRect, SdlTextureOrientation orientation = null, int fontSize = 28, SDL.SDL_Color?color = null) { // checking initialization if (SDL_ttf.TTF_WasInit() == 0 && SDL_ttf.TTF_Init() < 0) { Debug.WriteLine($"Could not create LoadingScreen: {SDL.SDL_GetError() }"); return; } var textTexture = SDL.SDL_CreateTextureFromSurface(_renderer, SDL_ttf.TTF_RenderText_Blended( SDL_ttf.TTF_OpenFont(_fontSourceRegular, fontSize), "Initializing...", color ?? new SDL.SDL_Color { a = 0xff, r = 0xff, g = 0xff, b = 0xff } )); orientation = orientation ?? new SdlTextureOrientation(); SDL.SDL_QueryTexture(textTexture, out uint fmt, out int acs, out dstRect.w, out dstRect.h); // TODO: testwise implement horizontal centering (ignoring all other cases for now) switch (orientation.Horizontal) { case TextureOrientation.Center: dstRect.x = _rectOrigin.w / 2 - dstRect.w / 2; break; } if (textTexture == IntPtr.Zero) { Debug.WriteLine($"Could not create texture for ttf: {SDL.SDL_GetError()}"); return; } SDL.SDL_RenderCopy(_renderer, textTexture, ref _rectOrigin, ref dstRect); }
void ShowLoadingScreen(int?duration = 1000) { if (!EnableLoadingScreen || (SDL_ttf.TTF_WasInit() == 0 && SDL_ttf.TTF_Init() < 0)) { Debug.WriteLine($"Could not create LoadingScreen: {((EnableLoadingScreen) ? SDL.SDL_GetError() : "disabled")}"); return; } SDL.SDL_RenderClear(_renderer); // updating image UpdateImage( $"{AppDomain.CurrentDomain.BaseDirectory}/Images/OpenXboxLogo.png", new SDL.SDL_Rect { x = _rectOrigin.w / 2 - 200 / 2, y = 200, w = 200, h = 200 } ); // updating string(font) UpdateFontString( "Initializing...", new SDL.SDL_Rect { y = 420 }, new SdlTextureOrientation { Horizontal = TextureOrientation.Center } ); SDL.SDL_RenderPresent(_renderer); Thread.Sleep(duration ?? 0); }
private IntPtr GetGlyphSurface(ushort index) { SDL.SDL_Color color = new SDL.SDL_Color(); color.r = color.g = color.b = color.a = 255; IntPtr surfacePtr = SDL_ttf.TTF_RenderGlyph_Blended(handle, index, color); if (surfacePtr == IntPtr.Zero) { return(IntPtr.Zero); //throw new Exception("Failed to render glyph: " + SDL.SDL_GetError()); } SDL.SDL_Surface surface = Marshal.PtrToStructure <SDL.SDL_Surface>(surfacePtr); SDL.SDL_PixelFormat surfaceFormat = Marshal.PtrToStructure <SDL.SDL_PixelFormat>(surface.format); if (surfaceFormat.format == SDL.SDL_PIXELFORMAT_INDEX8) { IntPtr convertedSurface = SDL.SDL_ConvertSurfaceFormat(surfacePtr, SDL.SDL_PIXELFORMAT_ARGB8888, 0); SDL.SDL_FreeSurface(surfacePtr); surfacePtr = convertedSurface; //surface = Marshal.PtrToStructure<SDL.SDL_Surface>(surfacePtr); //surfaceFormat = Marshal.PtrToStructure<SDL.SDL_PixelFormat>(surface.format); } else if (surfaceFormat.format != SDL.SDL_PIXELFORMAT_ARGB8888) { throw new Exception("Failed to map SDL surface format to Bgfx texture format: " + SDL.SDL_GetPixelFormatName(surfaceFormat.format)); } return(surfacePtr); }
public void Init(string title, int xPos, int yPos, int width, int height) { SDL_WindowFlags flags = 0; Width = width; Height = height; endScene = false; if (SDL_Init(SDL_INIT_EVERYTHING) == 0) { SDL_ttf.TTF_Init(); Window = SDL_CreateWindow(title, xPos, yPos, width, height, flags); Renderer = SDL_CreateRenderer(Window, -1, 0); SDL_SetRenderDrawColor(Renderer, 200, 200, 50, 90); IsRunning = true; } x = 250; y = 500; w = 170; h = 100; mrect.x = x; mrect.y = y; mrect.w = w; mrect.h = h; endScreen = Texture.LoadTexture("Textures/EndScreen.png"); scrRect.x = 0; scrRect.y = 0; scrRect.w = Width; scrRect.h = Height; Scene.SetUpSceneScreen("Scenes/main menu.txt", this); }
public Font(string path, int pointSize, FontStyle style = FontStyle.Normal, bool unicode = true) { cacheFonts = SettingsManager.instance.engine.cacheFonts; this.pointSize = pointSize; this.style = style; this.unicode = unicode; if (SDL_ttf.TTF_WasInit() == 0) { if (SDL_ttf.TTF_Init() != 0) { throw new ApplicationException("Failed to initialize SDL_ttf: " + SDL.SDL_GetError()); } } handle = SDL_ttf.TTF_OpenFont(path, pointSize); if (handle == IntPtr.Zero) { throw new ApplicationException("Failed to load font: " + SDL.SDL_GetError()); } SDL_ttf.TTF_SetFontStyle(handle, (int)style); familyName = SDL_ttf.TTF_FontFaceFamilyName(handle); ushort characterCount = unicode ? ushort.MaxValue : (ushort)256; bool generateTextures = true; if (cacheFonts) { if (LoadGlyphDataCached() && LoadTextureDataCached()) { Log.Info("Font: Using cached font data"); generateTextures = false; } else { glyphs = null; foreach (Texture2D texture in textures) { texture.Dispose(); } textures.Clear(); } } if (generateTextures) { GenerateGlyphData(characterCount); GenerateTextures(characterCount); if (cacheFonts) { CacheGlyphData(); } } loadedFonts++; }
static bool loadMedia() { //Loading success flag bool success = true; //Open the font gFont = SDL_ttf.TTF_OpenFont("lazy.ttf", 28); if (gFont == IntPtr.Zero) { Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError()); success = false; } else { SDL.SDL_Color textColor = new SDL.SDL_Color { a = 0xFF }; if (!gPromptTextTexture.loadFromRenderedText("Enter Text:", textColor)) { Console.WriteLine("Failed to render prompt text!"); success = false; } } return(success); }
//initialize the Three Card Poker sprites and variables public unsafe ThreeCardPokerGame(IntPtr interfaceWindow) { window = interfaceWindow; windowSurface = SDL.SDL_GetWindowSurface(window); SDL.SDL_Surface *windowSDLSurface = (SDL.SDL_Surface *)windowSurface; clearColor = SDL.SDL_MapRGB(windowSDLSurface->format, 0, 100, 0); textColor.r = 255; textColor.b = 255; textColor.g = 255; textColor.a = 255; screenRect.x = 0; screenRect.y = 0; screenRect.w = 600; screenRect.h = 480; cardSprite = SDL.SDL_LoadBMP("cards.bmp"); cardBackSprite = SDL.SDL_LoadBMP("card back blue.bmp"); playButton = SDL.SDL_LoadBMP("play button.bmp"); foldButton = SDL.SDL_LoadBMP("fold button.bmp"); dealButton = SDL.SDL_LoadBMP("deal button.bmp"); quitButton = SDL.SDL_LoadBMP("quit button.bmp"); font = SDL_ttf.TTF_OpenFont("times.ttf", 20); betTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "Ante: $50", textColor); playerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "You won!", textColor); dealerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "The dealer won.", textColor); drawTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "Draw...", textColor); }
/// <summary> /// Draw the given string using the given font and foreground color at given location. /// </summary> /// <param name="str">the string to draw</param> /// <param name="font">the font to use to draw the string</param> /// <param name="color">the text color to set</param> /// <param name="point">the location to start string draw (top-left)</param> /// <param name="size">used to know the size of the rendered text for transparent text support</param> /// <param name="rtl">is to render the string right-to-left (true - RTL, false - LTR)</param> public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl) { var textSurface = SDL_ttf.TTF_RenderUTF8_Blended(font.ToTTF_Font(), str, color.ToSDL()); if (textSurface.ShowSDLError("Graphics.DrawString: Unable to TTF_RenderUTF8_Blended!")) { return; } var texture_text = SDL.SDL_CreateTextureFromSurface(_renderer, textSurface); if (texture_text.ShowSDLError("Graphics.DrawString: Unable to CreateTextureFromSurface!")) { SDL.SDL_FreeSurface(textSurface); return; } var dst_rect = textSurface.As <SDL.SDL_Surface>().ToSDL_Rect().UpdatedByRPoint(point); if (SDL.SDL_RenderCopy(_renderer, texture_text, IntPtr.Zero, ref dst_rect) < 0) { Helpers.ShowSDLError("Graphics.DrawString:Unable to SDL_RenderCopy!"); } SDL.SDL_DestroyTexture(texture_text); SDL.SDL_FreeSurface(textSurface); }
private static void QuitSDL2() { SDL_ttf.TTF_Quit(); SDL_image.IMG_Quit(); SDL_mixer.Mix_Quit(); SDL.SDL_Quit(); }
static bool LoadMedia() { //Loading success flag bool success = true; //Open the font Font = SDL_ttf.TTF_OpenFont("lazy.ttf", 28); if (Font == IntPtr.Zero) { Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError()); success = false; } else { //Render text var textColor = new SDL.SDL_Color(); if (!_TextTexture.LoadFromRenderedText("The quick brown fox jumps over the lazy dog", textColor)) { Console.WriteLine("Failed to render text texture!"); success = false; } } return(success); }
public void GEALOSinit() { if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0) { Console.WriteLine($"There was an issue initilizing SDL. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG | SDL_image.IMG_InitFlags.IMG_INIT_PNG | SDL_image.IMG_InitFlags.IMG_INIT_TIF | SDL_image.IMG_InitFlags.IMG_INIT_WEBP) < 0) { Console.WriteLine($"There was an issue initilizing SDL_image. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_ttf.TTF_Init() < 0) { Console.WriteLine($"There was an issue initilizing SDL_ttf. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 4096) < 0 || SDL_mixer.Mix_Init(SDL_mixer.MIX_InitFlags.MIX_INIT_FLAC | SDL_mixer.MIX_InitFlags.MIX_INIT_MID | SDL_mixer.MIX_InitFlags.MIX_INIT_MOD | SDL_mixer.MIX_InitFlags.MIX_INIT_MP3 | SDL_mixer.MIX_InitFlags.MIX_INIT_OGG | SDL_mixer.MIX_InitFlags.MIX_INIT_OPUS) < 0) { Console.WriteLine($"There was an issue initilizing SDL_mixer. {SDL.SDL_GetError()}"); Environment.Exit(-1); } running = true; GEALOSprog(); }
public bool LoadFromRenderedText(string textureText, SDL.SDL_Color textColor, IntPtr renderer, IntPtr font) { //Get rid of preexisting texture Free(); //Render text surface var textSurface = SDL_ttf.TTF_RenderText_Solid(font, textureText, textColor); if (textSurface == IntPtr.Zero) { Console.WriteLine("Unable to render text surface! SDL_ttf Error: {0}", SDL.SDL_GetError()); return(false); } //Create texture from surface pixels _Texture = SDL.SDL_CreateTextureFromSurface(renderer, textSurface); if (_Texture == IntPtr.Zero) { Console.WriteLine("Unable to create texture from rendered text! SDL Error: {0}", SDL.SDL_GetError()); return(false); } var s = Marshal.PtrToStructure <SDL.SDL_Surface>(textSurface); //Get image dimensions _Width = s.w; _Height = s.h; //Get rid of old surface SDL.SDL_FreeSurface(textSurface); //Return success return(true); }
public void DrawTextAbsolute(Colour color, int x, int y, string text, int ptSize = 12) { var rgb = color.ToRgb(); var font = GetFont(ptSize); var surfaceMessage = SDL_ttf.TTF_RenderText_Solid(font, text, new SDL.SDL_Color { r = rgb[0] , g = rgb[1] , b = rgb[2] , a = 255 }); if (surfaceMessage == IntPtr.Zero) { Console.WriteLine("unable to render text"); return; } SDL_ttf.TTF_SizeText(font, text, out var w, out var h); var message = SDL.SDL_CreateTextureFromSurface(_renderer, surfaceMessage); var rectMessage = new SDL.SDL_Rect { x = x , y = y , w = w , h = h }; SDL.SDL_RenderCopy(_renderer, message, IntPtr.Zero, ref rectMessage); SDL.SDL_DestroyTexture(message); SDL.SDL_FreeSurface(surfaceMessage); }
public Surface(Font font, string text, Color color, int wrapLength) { if (font == null) { throw new ArgumentNullException("font", Errors.E_FONT_NULL); } if (wrapLength < 0) { throw new ArgumentOutOfRangeException("wrapLength", "Wrap length must be greater than 0."); } Type = SurfaceType.Text; SDL.SDL_Color rawColor = new SDL.SDL_Color() { r = color.R, g = color.G, b = color.B }; if (wrapLength > 0) { Handle = SDL_ttf.TTF_RenderText_Blended_Wrapped(font.Handle, text, rawColor, (uint)wrapLength); } else { Handle = SDL_ttf.TTF_RenderText_Blended(font.Handle, text, rawColor); } if (Handle == IntPtr.Zero) { throw new InvalidOperationException(String.Format("Error while loading text surface: {0}", SDL.SDL_GetError())); } GetSurfaceMetaData(); }
private FontManager() { if (SDL_ttf.TTF_WasInit() == 0) { throw new Exception("You need call SDL_ttf.Init() before using FontManager"); } }
internal static void deinitialiser_2d() { foreach (var image in images) { SDL.SDL_DestroyTexture(image.Value); } images.Clear(); SDL_image.IMG_Quit(); for (int i = 0; i < 73; i++) { if (police[i] != IntPtr.Zero) { SDL_ttf.TTF_CloseFont(police[i]); police[i] = IntPtr.Zero; } } SDL_ttf.TTF_Quit(); if (rendu != IntPtr.Zero) { SDL.SDL_DestroyRenderer(rendu); rendu = IntPtr.Zero; } if (fenetre != IntPtr.Zero) { SDL.SDL_DestroyWindow(fenetre); fenetre = IntPtr.Zero; } }
public void LoadInit(IntPtr rendererPtr) { fontPtr = SDL_ttf.TTF_OpenFont("media/font/typed.ttf", 25); if (fontPtr == IntPtr.Zero) { Console.WriteLine("Error loading font. SDL: {0}", SDL.SDL_GetError()); } textColor = new SDL.SDL_Color { r = 217, g = 204, b = 0, a = 255 }; activeTextColor = new SDL.SDL_Color { r = 255, g = 125, b = 0, a = 255 }; }
private bool ReleaseAndQuit(IntPtr window, IntPtr renderer, IntPtr font, IntPtr image) { if (window != IntPtr.Zero) { SDL.SDL_DestroyWindow(window); } if (renderer != IntPtr.Zero) { SDL.SDL_DestroyRenderer(renderer); } if (font != IntPtr.Zero) { SDL_ttf.TTF_CloseFont(font); } if (image != IntPtr.Zero) { SDL.SDL_DestroyTexture(image); } SDL_image.IMG_Quit(); SDL.SDL_Quit(); return(false); }
static bool LoadMedia() { //Loading success flag bool success = true; //Open the font Font = SDL_ttf.TTF_OpenFont("lazy.ttf", 28); if (Font == IntPtr.Zero) { Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError()); success = false; } else { //Set text color as black var textColor = new SDL.SDL_Color { a = 255 }; //Load prompt texture if (!_PromptTextTexture.LoadFromRenderedText("Press Enter to Reset Start Time.", textColor)) { Console.WriteLine("Unable to render prompt texture!"); success = false; } } return(success); }
public SDLTexture RenderTextBlended(SDLRenderer renderer, string text, Color color) { // Check inputs. if (renderer == null) { throw new ArgumentNullException("renderer"); } // Convert color to SDL format. SDL.SDL_Color sdlColor = new SDL.SDL_Color(); sdlColor.r = color.RedByte; sdlColor.g = color.GreenByte; sdlColor.b = color.BlueByte; // Render the text message to an SDL_Surface and then convert the surface into an // SDL texture. SDLTexture texture; using (SDLSurface surface = new SDLSurface(SDL_ttf.TTF_RenderText_Blended( mFont, text, sdlColor))) { texture = new SDLTexture(renderer, surface); } return(texture); }
/// <summary> /// Create a new SDL font. /// </summary> /// <remarks> /// I'm normally not a huge fan of classes that load themselves, much less a constructor /// that loads itself from a file. I have to make an exception for the moment because /// SDL_image's API only supports loading from a file... once someone (maybe me) adds the /// load from memory calls I can remove this and create a proper byte[] constructor /// instead. (And leave the file loading up to the caller). /// </remarks> public SDLFont(SDLRenderer renderer, string fontName, int fontSize) { // Make sure our inputs are valid! if (renderer == null) { throw new ArgumentNullException("renderer"); } if (String.IsNullOrEmpty(fontName)) { throw new ArgumentNullException("fontName"); } if (fontSize <= 0) { throw new ArgumentOutOfRangeException("fontSize"); } // Make sure the image actually exists on disk before attempting to ask SDL to load it. // (Bonus: SDL doesn't return a null when the image does not exist on disk!) if (!File.Exists(fontName)) { throw new FileNotFoundException(fontName); } // Ask SDL to load our font for us and check if it worked. mFont = SDL_ttf.TTF_OpenFont(fontName, fontSize); if (mFont == null) { throw new SDLException("Failed to load font"); } }
private static void close() { //Open data for writing //Create file for writing using (var bw = new BinaryWriter(File.OpenWrite("nums.bin"), Encoding.Default)) { //Initialize data for (int i = 0; i < TOTAL_DATA; ++i) { bw.Write(gData[i]); } } //Free loaded images gPromptTextTexture.free(); for (int i = 0; i < TOTAL_DATA; ++i) { gDataTextures[i].free(); } //Free global font SDL_ttf.TTF_CloseFont(gFont); gFont = IntPtr.Zero; //Destroy window SDL.SDL_DestroyRenderer(gRenderer); SDL.SDL_DestroyWindow(gWindow); gWindow = IntPtr.Zero; gRenderer = IntPtr.Zero; //Quit SDL subsystems SDL_ttf.TTF_Quit(); SDL_image.IMG_Quit(); SDL.SDL_Quit(); }
private static void Start() { // ====================================================================================== // Initialize SDL // ====================================================================================== if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) != 0) { throw new Exception("Failed to initialize SDL."); } if (SDL_ttf.TTF_Init() != 0) { throw new Exception("Failed to initialize SDL_ttf."); } SDL_mixer.MIX_InitFlags mixInitFlags = SDL_mixer.MIX_InitFlags.MIX_INIT_MP3 | SDL_mixer.MIX_InitFlags.MIX_INIT_OGG | SDL_mixer.MIX_InitFlags.MIX_INIT_FLAC; if (((SDL_mixer.MIX_InitFlags)SDL_mixer.Mix_Init(mixInitFlags) & mixInitFlags) != mixInitFlags) { throw new Exception("Failed to initialize SDL_mixer."); } if (SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024) != 0) { throw new Exception("Failed to initialize SDL_mixer."); } SDL_mixer.Mix_AllocateChannels(AudioChannelCount); Window = SDL.SDL_CreateWindow( Game.Title, SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), (int)Game.Resolution.X, (int)Game.Resolution.Y, 0); if (Window == IntPtr.Zero) { throw new Exception("Failed to create window."); } Renderer = SDL.SDL_CreateRenderer(Window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RendererFlags.SDL_RENDERER_TARGETTEXTURE); if (Renderer == IntPtr.Zero) { throw new Exception("Failed to create renderer."); } IntPtr renderTargetHandle = SDL.SDL_CreateTexture(Renderer, SDL.SDL_PIXELFORMAT_RGBA8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, (int)Game.Resolution.X, (int)Game.Resolution.Y); RenderTarget = new Texture(renderTargetHandle, (int)Game.Resolution.X, (int)Game.Resolution.Y); // ====================================================================================== // Instantiate the game object // ====================================================================================== Game = new Game(); }