Example #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;
    }
Example #2
0
    // NOTE:  This callback will be run in the SDLRenderer thread.
    //
    // Access to global resources should use the appropriate safe-guards for a
    // multi-threaded envirionment.

    // void SDLRenderer.Client_Delegate_RendererReset( SDLRenderer renderer );
    void SDLRendererReset(SDLRenderer renderer)
    {
        // The underlying SDL_Window and/or SDL_Renderer changed, we need to
        // recreate our assets
        ReleaseAssets();
        CreateAssetsForRenderer(renderer);

        // Tell all the example scenes to recreate their assets
        SDLExampleSet.RendererReset(renderer);
    }
Example #3
0
    void InitInThread(SDLRenderer renderer)
    {
        // Set the render blender mode
        renderer.BlendMode = SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND;

        // Load some assets
        CreateAssetsForRenderer(renderer);

        // Tell the examples the renderer to use
        SDLExampleSet.UpdateRenderer(sdlRenderer);

        // Barf to the console
        ConsoleDump(renderer);
    }
Example #4
0
    public SDLRendererExampleForm()
    {
        // Make the WinForms window
        MaximizeBox     = false;
        MinimizeBox     = false;
        FormBorderStyle = FormBorderStyle.FixedSingle;
        FormClosing    += ExampleClosing;

        // This is what we're going to attach the SDL2 window to
        gamePanel          = new Panel();
        gamePanel.Size     = new Size(SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT);
        gamePanel.Location = new Point(WINDOW_PADDING + CONTROL_WIDTH + CONTROL_PADDING, WINDOW_PADDING);
        Controls.Add(gamePanel);

        // Anchored checkbox
        checkAnchored      = new CheckBox();
        checkAnchored.Text = "Anchor";
        checkAnchored.CalculcateControlSizeAndLocation(0);
        checkAnchored.Checked = true;
        Controls.Add(checkAnchored);

        // Add some buttons
        buttonInit = MakeButton("Init", 1, InitClicked);
        buttonSave = MakeButton("Save PNG", 2, SaveClicked);
        SDLExampleSet.Add(new exDrawPoints(this, "Points"));
        SDLExampleSet.Add(new exDrawPoints2(this, "Points 2"));
        SDLExampleSet.Add(new exDrawLines(this, "Lines"));
        SDLExampleSet.Add(new exDrawRects(this, "Rects"));
        SDLExampleSet.Add(new exDrawFilledRects(this, "Filled Rects"));
        SDLExampleSet.Add(new exDrawCircles(this, "Circles"));
        SDLExampleSet.Add(new exDrawFilledCircles(this, "Filled Circles"));
        SDLExampleSet.Add(new exBlitSurfaces(this, "Surfaces"));
        SDLExampleSet.Add(new exBlitTextures(this, "Textures"));
        SDLExampleSet.Add(new exDrawText(this, "Text"));
        SDLExampleSet.Add(new exDrawText2(this, "Text 2"));
        SDLExampleSet.Add(new exSample1(this, "Sample 1"));

        // Add a performance feedback timer
        timer           = new System.Timers.Timer();
        timer.Interval  = PROFILE_FREQUENCY_MS;
        timer.AutoReset = true;
        timer.Elapsed  += TimerElapsed;

        // Now all the controls are created, set the form size
        CalculateWindowSize(true);
    }