Vladar4 / sdl2_nim

Wrapper of the SDL 2 library for the Nim language.
Other
145 stars 24 forks source link

sdl_gpu version #36

Closed avahe-kellenberger closed 3 years ago

avahe-kellenberger commented 3 years ago

The README mentions the bindings are for version 0.11.0, but I can't seem to find that on the official repo. I do however see 0.10.0. Is this the actual target for the binding?

avahe-kellenberger commented 3 years ago

To follow up:

I've installed the current master branch of sdl_gpu. A minimal C example works fine, but with Nim the screen is blank.

Nim:

import sdl2_nim/sdl, sdl2_nim/sdl_gpu

when isMainModule:
  setDebugLevel(DEBUG_LEVEL_MAX);
  let screen = init(800, 600, DEFAULT_INIT_FLAGS)

  if screen == nil:
    quit(1)

  let image = loadImage("example.png")
  if image == nil:
    quit(1)

  var event: Event
  var done = false
  while not done:
    while pollEvent(event.addr) == 0:
      if event.kind == QUIT:
        done = true

    clear(screen)
    blit(image, nil, screen, image.w.float/2, image.h.float/2)
    flip(screen)

  sdl_gpu.quit()

C:

gcc example.c -lSDL2_gpu -I/usr/include/SDL2 -pthread -lSDL2

#include "SDL2/SDL_gpu.h"
#include <SDL2/SDL_events.h>

int main(int argc, char** argv) {
  GPU_SetDebugLevel(GPU_DEBUG_LEVEL_MAX);
  GPU_Target* screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);

  if (screen == NULL) {
    return 1;
  }

  GPU_Image* image = GPU_LoadImage("example.png");
  if (image == NULL) {
    return 2;
  }

  SDL_Event event;
  Uint8 done = 0;
  while (!done) {

    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT) {
        done = 1;
      }
    }

    GPU_Clear(screen);
    GPU_Blit(image, NULL, screen, image->w/2, image->h/2);
    GPU_Flip(screen);
  }

  GPU_Quit();
  return 0;
}

Unsure if this is a version issue, or something else. Would appreciate some insight so I can use sdl_gpu.

ftsf commented 3 years ago

Image data appears to be corrupted. Was able to fix this by reordering the members of Image which appear to have changed since the wrapper was created.

Image* = ptr object ##  \
    ##  Image object for containing pixel/texture data.
    ##
    ##  A image can be created with
    ##  ``createImage()``, ``loadImage()``, ``copyImage()``,
    ##  or ``copyImageFromSurface()``.
    ##
    ##  Free the memory with ``freeImage()`` when you're done.
    ##
    ##  See also:
    ##
    ##  ``createImage()``
    ##
    ##  ``loadImage()``
    ##
    ##  ``copyImage()``
    ##
    ##  ``copyImageFromSurface()``
    ##
    ##  ``Target``
    renderer*: Renderer
    contextTarget*: Target
    target*: Target
    data*: pointer

    w*, h*: uint16
    format*: Format
    numLayers*: cint
    bytesPerPixel*: int
    baseW*, baseH*: uint16        ##  Original image dimensions
    textureH*, textureW*: uint16  ##  Underlying texture dimensions

    anchorX*, anchorY*: cfloat

    color*: Color
    blendMode*: BlendMode
    filterMode*: Filter
    snapMode*: Snap
    wrapModeX*: Wrap
    wrapModeY*: Wrap

    refcount*: cint

    usingVirtualResolution*: bool
    hasMipMaps*: bool
    useBlending*: bool
    isAlias*: bool
Vladar4 commented 3 years ago

@h0lley IIRC the sdl_gpu was your addition?

h0lley commented 3 years ago

yes, though I haven't been updating the wrapper for newer versions of SDL_gpu. I last used it in 2018 when it worked without issues. It seems it was last updated by exelotl in Apr 18, 2018: ac83b6771f6df3332fc8aad78377a271395a3bfb.

the breaking change for the wrapper may have been this.

there aren't many commits being made to SDL_gpu. It's easy to track down relevant changes by checking the history of the main header file: https://github.com/grimfang4/sdl-gpu/commits/master/include/SDL_gpu.h

the oldest commit the current wrapper doesn't account for is probably this from Nov 14, 2018 and there's only a handful of commits after that.

@ftsf perhaps you can contribute an update?

avahe-kellenberger commented 3 years ago

I've updated the wrapper locally for the latest commit on master, I could put that in a PR (although it's not a release so maybe not the best idea)

Vladar4 commented 3 years ago

I will accept the patch that fixes this problem. It'll go as a minor release, while I work on 2.0.16 port.

Also, if anyone want to create an example/ex701_sdl_gpu.nim that will demonstrate the basics of sdl_gpu and help to test its functionality, I will accept it as well.

avahe-kellenberger commented 3 years ago

I'll do that tonight