Search code examples
c3dsdlscalerenderer

Can't use low graphics in SDL


When I scale the window, SDL simply ignores the resolution I set and draw diagonals on my pixels. It's SDL2, Im using SDL_RenderGeometry to draw my triangles.

Here's how I create the window:

static inline void canvas_init(Canvas* canvas) {
  SDL_CreateWindowAndRenderer(canvas->width * canvas->scale_x, canvas->height * canvas->scale_y, 0, &(canvas->window), &(canvas->renderer));
  SDL_RenderSetScale(canvas->renderer, canvas->scale_x, canvas->scale_y);
  SDL_Init(SDL_INIT_VIDEO);
}

I tried something about creating a backbuffer but I probably did it wrong and it didn't work with no errors.

Here is what I'm currently getting on a windows which were supposed to have 10 pixels clearly theres a diagonal on some pixels


Solution

  • Thank you comments guy, it's working by doing this

    Creating a lowres texture, draw to it, but before displaying it, copy this to the window texture

    static inline void canvas_init(Canvas* canvas) {
      SDL_CreateWindowAndRenderer(canvas->width * canvas->scale_x, canvas->height * canvas->scale_y, SDL_WINDOW_ALWAYS_ON_TOP, &(canvas->window), &(canvas->renderer));
      canvas->texture = SDL_CreateTexture(canvas->renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, canvas->width, canvas->height);
      SDL_Init(SDL_INIT_EVERYTHING);
    }
    
    static inline void canvas_update(Canvas canvas, uint16_t delay) {
      SDL_SetRenderTarget(canvas.renderer, NULL);
      SDL_RenderCopy(canvas.renderer, canvas.texture, NULL, NULL);
      canvas_display(canvas);
    
      SDL_SetRenderTarget(canvas.renderer, canvas.texture);
      canvas_color(canvas, (Color) {0, 0, 0, 255});
      canvas_clear(canvas);
    
      canvas_delay(delay);
    }