コード例 #1
0
    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;
    }
コード例 #2
0
        void BlitAsSprite(SDLRenderer renderer, SDLRenderer.Texture texture, 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);

            texture.ColorMod = c;
            renderer.Blit(rect, texture);
        }
コード例 #3
0
 void ReleaseAssets()
 {
     if (textTure != null)
     {
         textTure.Dispose();
     }
     textTure = null;
 }
コード例 #4
0
        void CreateAssetsFor(SDLRenderer renderer)
        {
            // Get the size of the message
            textSize = font.TextSize(TEXT);

            // Create a Surface for the message
            var surface = font.TextBlended(TEXT, Color.White);

            // Turn the surface into a Texture
            textTure = renderer.CreateTextureFromSurface(surface);
        }
コード例 #5
0
    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()));
        }
    }
コード例 #6
0
    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;
    }