0
\$\begingroup\$

how do I resize SDL2 Window correctly?

using static SDL2.SDL;
using System;

namespace tutorial_003
{
    class Example
    {
        private static int SCREEN_WIDTH = 640;
        private static int SCREEN_HEIGHT = 480;

        static void Main(string[] args)
        {
            IntPtr window = IntPtr.Zero;
            IntPtr screenSurface = IntPtr.Zero;
            IntPtr helloworld = IntPtr.Zero;
            bool IsQuit = false;

            if (SDL_Init(SDL_INIT_VIDEO) < 0)
                Console.WriteLine("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
            else
            {
                window = SDL_CreateWindow("SDL Tutorial - Event Quit", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
                if (window == IntPtr.Zero)
                    Console.WriteLine("Window could not be created! SDL_Error: %s\n", SDL_GetError());
                else
                {
                    screenSurface = SDL_GetWindowSurface(window);

                    helloworld = SDL_LoadBMP("test.bmp");

                    SDL_BlitSurface(helloworld, IntPtr.Zero, screenSurface, IntPtr.Zero);
                }
            }

            IntPtr renderer = SDL_CreateRenderer(window, -1,
                SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);

            SDL_SetWindowResizable(window, SDL_bool.SDL_TRUE);

            SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

            SDL_UpdateWindowSurface(window);

            SDL_RenderClear(renderer);

            while (!IsQuit)
            {
                SDL_Event evt;

                if (SDL_PollEvent(out evt) != 0)
                {
                    if (evt.type == SDL_EventType.SDL_QUIT)
                    {
                        IsQuit = true;
                    }

                    if (evt.type == SDL_EventType.SDL_KEYDOWN)
                    {
                        if (evt.key.keysym.sym == SDL_Keycode.SDLK_ESCAPE)
                        {
                            IsQuit = true;
                        }
                    }

                    if (evt.window.windowEvent == SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED)
                    {
                        SCREEN_WIDTH = evt.window.data1;
                        SCREEN_HEIGHT = evt.window.data2;
                        SDL_RenderPresent(renderer);
                    }
                }
            }

            SDL_GetWindowSurface(window);
            SDL_FreeSurface(helloworld);
            SDL_DestroyRenderer(renderer);
            SDL_DestroyWindow(window);
            SDL_Quit();
        }
    }
}

enter image description here

How do I fix it?

It is from SDL2-CS Github

Can you help me, how do I resize renderer?

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.