SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL_SetRenderViewport not working correctly for x, y != 0,0

Open renebarto opened this issue 2 years ago • 4 comments

SDL_SetRenderViewport does not seem to do anything when x, y != 0,0. The calls do not render anything in that case. When I first set the viewport to say 0, 0, 960, 540 on a HD screen, it renders correctly. If I then set it to 960, 0, 960, 540, nothing happens. Also setting to 960, 0, 1920, 540 does not work. Resetting the viewport in between also does not resolve the issue? The workaround that is usable is e.g. when calling SDL_RenderTexture to specify the destination rectangle.

renebarto avatar Aug 29 '23 17:08 renebarto

This little app creates a viewport that tracks the mouse pointer, and seems to work. Please modify it until you can reproduce your issue (or not)?

#include <SDL.h>

int main(int argc, char *argv[]) {
    SDL_Window *window;
    SDL_Renderer *renderer;
    SDL_Rect r;
    SDL_Init(SDL_INIT_VIDEO);

    SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer);
    SDL_SetRenderVSync(renderer, 1);
    r.x = 0;
    r.y = 0;
    r.w = 320;
    r.h = 240;

    while (1) {
        int quit = 0;
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_EVENT_QUIT) {
                quit = 1;
                break;
            } else if (event.type == SDL_EVENT_MOUSE_MOTION) {
                r.x = (int)event.motion.x;
                r.y = (int)event.motion.y;
            }
        }
        if (quit) {
            break;
        }
        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MUL);
        SDL_SetRenderViewport(renderer, NULL);
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 25);
        SDL_RenderFillRect(renderer, NULL);
        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
        SDL_SetRenderViewport(renderer, &r);
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
        SDL_RenderFillRect(renderer, NULL);
        /* Draw into the viewport here. */
        SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE);
        SDL_RenderLine(renderer, 10, 10, 310, 230);
        SDL_RenderPresent(renderer);
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

madebr avatar Aug 29 '23 21:08 madebr

What platform was this happening on? It's possible it's a Direct3D or OpenGL or Metal specific issue.

icculus avatar Nov 22 '23 17:11 icculus

Hi, this was on a Win 10 PC, I'm pretty sure it uses Direct3D.

On Wed, Nov 22, 2023 at 6:34 PM Ryan C. Gordon @.***> wrote:

What platform was this happening on? It's possible it's a Direct3D or OpenGL or Metal specific issue.

— Reply to this email directly, view it on GitHub https://github.com/libsdl-org/SDL/issues/8179#issuecomment-1823204402, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQY5NMU6R5LXY7OWMA5DKTYFYZTHAVCNFSM6AAAAAA4DJW4FCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRTGIYDINBQGI . You are receiving this because you authored the thread.Message ID: @.***>

-- Regards, Groet,

Rene Barto

renebarto avatar Nov 23 '23 23:11 renebarto

@renebarto, can you please try the test program that @madebr provided, or attach a simple example that shows the problem you're seeing?

slouken avatar Jan 19 '24 13:01 slouken