void ShutdownRenderer() { // (I thought this was about SDLRenderer, not the example form!) // Example Form change state, ignore the next couple lines and the comment above CalculateWindowSize(true); buttonInit.Text = "Init"; timer.Stop(); // Tell the examples the renderer is invalid SDLExampleSet.UpdateRenderer(null); // Tell SDLRenderer to stop it's thread. We do this so we don't destroy resources // being used before destroying the renderer itself. if (sdlRenderer != null) { sdlRenderer.DestroyWindow(); } // While SDL2ThingLayer implements IDisposable in all it's classes and // explicitly disposes of their resources in their destructors, I always // like to clean up after myself (old habits). ReleaseAssets(); // Dispose of the Renderer if (sdlRenderer != null) { sdlRenderer.Dispose(); } // This is all you really need to do though, GC will handle the rest surface = null; texture = null; font = null; sdlRenderer = null; }
void BlitAsSprite(SDLRenderer renderer, SDLRenderer.Surface surface, double angle, Color c) { var pos = spinCentre.Add(RotateAround(spinDistance, angle)); var rect = new SDL.SDL_Rect(spriteRect.x + pos.x, spriteRect.y + pos.y, spriteRect.w, spriteRect.h); surface.ColorMod = c; renderer.Blit(rect, surface); }
void CreateAssetsForRenderer(SDLRenderer renderer) { // Load Surface from a file // // NOTE: Surfaces are deprecated and require conversion to Textures before blitting. surface = renderer.LoadSurface("pointsprite.png"); // Set the blend mode for surface blitting surface.BlendMode = SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND; // Create a Texture from the Surface. // // No need to set the blend mode, etc - all rendering information is copied // directly in SDLRenderer.CreateTextureFromSurface() from the Surface settings. texture = renderer.CreateTextureFromSurface(surface); // Load a font from file. font = renderer.CreateFont(12, "LibertySans.ttf"); if (font == null) { throw new Exception(string.Format("Unable to create font!\n\n{0}", SDL.SDL_GetError())); } }
void ReleaseAssets() { // Dispose of the Surface if (surface != null) { sdlRenderer.DestroySurface(ref surface); } // Dispose of the Texture if (texture != null) { sdlRenderer.DestroyTexture(ref texture); } // Dispose of the Font if (Font != null) { sdlRenderer.DestroyFont(ref font); } surface = null; texture = null; font = null; }