GithubHelp home page GithubHelp logo

sdl2's Introduction

SDL2 for Nim

This package contains the bindings for SDL2 to Nim.

Pre-requisites

You must install the SDL2 C libraries before these Nim bindings can be used.

macOS

Homebrew

If you don't already have Homebrew installed, install it from the Homebrew site.

Install the SDL2 C libraries:

brew install sdl2{,_gfx,_image,_mixer,_net,_ttf}

MacPorts

If you don't already have Macports installed, install it from the Macports site.

sudo port install libsdl2 libsdl2_gfx libsdl2_image libsdl2_mixer libsdl2_ttf libsdl2_net

Linux

Install SDL2 development libraries using your distribution's packaging tool of choice.

Windows

Using SDL2 with mingw-w64 environment

  • Install mingw-w64-builds. Check that x86_64-w64-mingw32\bin\ from the installed mingw toolchain is in your PATH variable.
  • Download SDL2 Development Libraries for MinGW
  • Extract contents of the downloaded archive to your mingw-w64 folder (for example, SDL2-2.0.12\x86_64-w64-mingw32\ to mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\)

Static linking SDL2

Pass the following options to nim on compilation: --dynlibOverride:libSDL2 --passL:"-static -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--no-undefined -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" Options for the linker (--passL:) except -static are taken from sdl2-config.cmake which is included in SDL2 Development Libraries.

Installation

Add requires "sdl2" to your .nimble file.

You can also install manually with nimble install sdl2 if your project does not yet have a nimble package file.

For more information on using nimble, consult the nim documentation.

Documentation

For documentation about SDL2 see wiki.libsdl.org.

sdl2's People

Contributors

allnamesrtaken avatar amjadhd avatar angluca avatar apense avatar araq avatar barbeque avatar barroff avatar bixinfromthisrealm avatar clyybber avatar def- avatar dom96 avatar fowlmouth avatar g4mr avatar grundletrundle avatar krux02 avatar lantos1618 avatar markus-oberhumer avatar matkuki avatar metagn avatar quinnfreedman avatar ringabout avatar robaltenburg avatar simonkrauter avatar sspkrolik avatar timotheecour avatar woflox avatar yglukhov avatar zacharycarter avatar zetaomega avatar zoomrmc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdl2's Issues

static linking causes incompatible type

If SDL_Static is defined, several conflicting types are produced by sdl.ttf.nim module, example:

ttf_example.nim

import sdl2, sdl2.ttf

if ttfInit() == SdlError:
  raise Exception.newException(
    "SDL2 TTF initialization failed, SDL error: " & $getError())

let font = openFont("data/DejaVuSans.ttf", 28)
let surface = font.renderUtf8Blended("text".cstring, color(0, 0, 0, 64))

No errors without static linking:

nim c -d:release ttf_example.nim

Compile with --define:SDL_Static for static linking:

$ nim c -d:release --define:SDL_STATIC ttf_example.nim
Hint: used config file '/path/to/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: ttf_example [Processing]
Hint: sdl2 [Processing]
Hint: macros [Processing]
Hint: unsigned [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
SDL2 will be statically linked. Please make sure you pass the correct linker flags (library search paths, linked libraries).
Hint: ttf [Processing]
ttf_example.nim(8, 5) Hint: 'surface' is declared but not used [XDeclaredButNotUsed]
CC: ttf_example
CC: stdlib_system
CC: sdl2_sdl2
CC: sdl2_ttf
Error: execution of an external compiler program 'gcc -c  -w -O3 -fno-strict-aliasing  -I/path/to/Nim/lib -o /path/to/my_project/nimcache/ttf_example.o /path/to/my_project/nimcache/ttf_example.c' failed with exit code: 1

In file included from /path/to/my_project/nimcache/ttf_example.c:10:0:
/path/to/my_project/nimcache/ttf_example.c:277:21: error: conflicting types for ‘SDL_GetError’
 N_NIMCALL(NCSTRING, SDL_GetError)(void);
                     ^
/path/to/Nim/lib/nimbase.h:241:44: note: in definition of macro ‘N_NIMCALL’
 #  define N_NIMCALL(rettype, name) rettype name /* no modifier */
                                            ^
In file included from /usr/include/SDL2/SDL_audio.h:32:0,
                 from /usr/include/SDL2/SDL.h:36,
                 from /usr/include/SDL2/SDL_ttf.h:34,
                 from /path/to/my_project/nimcache/ttf_example.c:11:
/usr/include/SDL2/SDL_error.h:42:37: note: previous declaration of ‘SDL_GetError’ was here
 extern DECLSPEC const char *SDLCALL SDL_GetError(void);
                                     ^
/path/to/my_project/nimcache/ttf_example.c: In function ‘NimMainModule’:
/path/to/my_project/nimcache/ttf_example.c:484:96: error: incompatible type for argument 3 of ‘TTF_RenderUTF8_Blended’
  surface_tMTWNX5wwkxHTOP9ckySxSA = TTF_RenderUTF8_Blended(font_KOqh3xVpWmNWqVQjPHBR8g, "text", T9_);
                                                                                                ^
In file included from /path/to/my_project/nimcache/ttf_example.c:11:0:
/usr/include/SDL2/SDL_ttf.h:214:39: note: expected ‘SDL_Color {aka struct SDL_Color}’ but argument is of type ‘TY_Xo4YhcsfLAmbGDNu1Obfcw {aka struct TY_Xo4YhcsfLAmbGDNu1Obfcw}’
 extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font,
                                       ^

The error: conflicting types for ‘SDL_GetError’ is another issue: #87


Nim Compiler Version 0.16.1 (2017-05-07) [Linux: amd64] (latest version of devel branch)

SDL version 2.0.4+dfsg1-2ubuntu2

SDL image version 2.0.1+dfsg-2

SDL Mixer breaks on compilation

When trying to build a project using SDL mixer the build fails because of a when 0: at line 451 of sdl2/mixer.nim

Error message below:
../../../.nimble/pkgs/sdl2-1.2/sdl2/mixer.nim(451, 6) Error: type mismatch: got <int literal(0)> but expected 'bool'

Remove all ocurences of cint and cuint

Currently the sdl2 wrapper api exposes a lot of c types to the user, especially in the form of cint and cuint. Since I don't think sdl2 supports any 16bit architectures, where cint and cuint might be 16 bit, I would like to replace all cint with int32 and all cuint with uint32.

The idea is, that the use of the wrapper should not be required at all to deal with raw C types, when it is not absolutely necessary. If you do agree on this, I can create a pull request with all changes applied.

Creating Renderer Without 'RendererSoftware' Flag Causes Crash

If I use a renderer that is not created with the 'RendererSoftware' flag, I crash when trying to bind a vao with OpenGL immediately after creating a texture using said renderer. I'm not sure why the error happens at the VAO binding call, but adding the flag fixes the problem.

library filename hardcoded incorrectly to libSDL2

causes issue on operating systems where it is called by its full unambiguous name, libSDL2-2.0.so.0

reproducibility: attempt to use these bindings on Haiku. bindings cannot find libSDL2.so, since it does not exist on that operating system.

(ProveInit) Event.kind needs a unused default EventType enum value when initializing an Event variable

One thing I noticed is there's no simple way to prove that the Event variable was initialized unless we set a random gesture before the event polling happens in the game loop ex.:

var event: Event = Event(kind: DollarGesture)

Which fixes the error, but I think it would be better if we could just have a way simple EmptyEvent or something.

var event: Event = Event(kind: EmptyEvent)

The warning I'm talking about when I don't initialize the event variable. Just something to think about.

Warning: Cannot prove that 'event' is initialized. This will become a compile time error in the future. [ProveInit]

warning in event variable declaration

When writing this code:

var evt: Event = defaultEvent

I get the following warning from Nim:

Warning: Cannot prove that 'evt' is initialized. This will become a compile time error in the future. [ProveInit]

I don't know how I could avoid this warning, so I guess it should be fixed from the wrapper side. On the other side though, it wouldn't even matter when the variable would be uninitialized, because sdl initializes it when I use it to poll events.

Has trouble finding sdl_gfx library on debian

To reproduce: run examples/sdl_skeleton.nim, fails with could not load: libSDL2_gfx(|-2.0).so(|.0)

I'm not sure what this (|-2.0) syntax means or where it's documented (is it a C compiler thing?), it does not seem to allow the nim compiler to find the /usr/lib/libSDL2_gfx.so that I have on my system.

I would appreciate instructions for installing from source so that I can try changing this line to

    const LibName = "libSDL2_gfx.so"

use versioning scheme a.b.c.d: a.b.c - underlying library version; d: wrapper revision

this is in response to #112 (comment)

@yglukhov

I have just re-released the v2.0 version. It was not usable anyway, so there's nothing to lose.

git fetch
git checkout v2.0
git rev-parse HEAD

still points to the old ad9a91e before the fix

/cc @krux02

sorry I won't update the version over the version of the original sdl2 library. I see the last release as a failed release

how will that work with nimble users ? /cc @dom96

if a user already has ~/.nimble/pkgs/sdl2-2.0/ (perhaps after running nimble install foo for a package foo that had requires "sdl2 >= 2.0" as a dependency), then any subsequent change in nim-lang/sdl2 repo won't be taken into account UNLESS foo specifies a HEAD version of sdl2, eg requires "sdl2#head" which as you know has other issues (not reproducible builds, instability etc)

Instead, a better scheme is the versioning scheme done here https://github.com/Vladar4/sdl2_nim#versioning-scheme

a.b.c.d

a.b.c - underlying SDL2 version
d - sdl2_nim revision

Remove the final value in convertSurface proc

Right now the code looks like this:

proc convertSurface*(src: SurfacePtr; fmt: ptr PixelFormat;
  flags: cint): SurfacePtr {.importc: "SDL_ConvertSurface".}

However, the docs for SDL_ConvertSurface says the following about the flags cint.

the flags are unused and should be set to 0; this is a leftover from SDL 1.2's API

Therefore, why don't we just remove it to make it easier for the programmer.

Unable to flip and mirror

add enum option both
TRendererFlip* {.size: sizeof(cint).} = enum
SDL_FLIP_NONE = 0x00000000, #< Do not flip
SDL_FLIP_HORIZONTAL = 0x00000001, #
< flip horizontally
SDL_FLIP_VERTICAL = 0x00000002 #< flip vertically
SDL_FLIP_BOTH= 0x00000003 #
< flip both

I created a joystick wrapper

As a nimrod virgin and as I havent coded C in like 15 years I cannot vouch for the correctness of the code nor how idomatic it is, but in my branch there is now a joystick wrapper. I just did like it seemed the audio wrapper was done. It compiles.

Please have a look at it and tell me what is wrong. If you approve of the code I do a PR after that.

//J

Warning: undeclared conditional's

c:\users\....\.nimble\pkgs\sdl2-1.0\sdl2.nim(501, 12) Warning: undeclared conditional symbol; use --symbol to declare it: SDL_Static [User]
c:\users\....\.nimble\pkgs\sdl2-1.0\sdl2.nim(1393, 12) Warning: undeclared conditional symbol; use --symbol to declare it: iPhone [User]
c:\users\....\.nimble\pkgs\sdl2-1.0\sdl2.nim(1419, 12) Warning: undeclared conditional symbol; use --symbol to declare it: android [User]

Seems like this could be a workaround for that warning nim-lang/Nim#1704

Emscripten support?

I'd like to use Nim and this bindings to make a web game build with Emscripten, but it does not seem to work. I got the Nim program to build correctly, but when launching the generated program in the browser, I get the error:

To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking

I suspect this is due to the bindings trying to open libSDL2.so, which should not be done in Emscripten. In the linker flags, I already specify linking with SDL2 the way it should be done in Emscripten, with -s USE_SDL=2. Is there a way to force the bindings in Linux to assume SDL2 is statically linked and not try to open libSDL2.so? Or, is there another official approach for Emscripten?

SDL2 quit and init / cimport naming convention

I just installed nim today. Problem is I can compile:

import sdl2, sdl2/image as sdl2_image
...
discard sdl2_image.quit

But I can not compile:

discard sdl2.quit

This results in: "Error: internal error: expr(nkClosedSymChoice); unknown node kind".
I guess there is a conflict between:
https://github.com/nim-lang/sdl2/blob/master/src/sdl2.nim#L620
and
https://github.com/nim-lang/sdl2/blob/master/src/sdl2.nim#L823

I am not sure I like to have C names changed (prefiix removed), because with names like init quit load, etc... I need to type the module name anyways to resolve ambiguity, which is kind of pointless. And I don't think SDL names can conflict with any name in nim. Also #23 . My 2 cents

Calling the 'close' closure member of RWopsPtr throws an illegal storage access error

Error:

example.nim(33)          :anonymous
image.nim(90)            close
image.nim(93)            close
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed

Source:

import sdl2, sdl2.image as img
import helpers

import typetraits

type Image* = ref object
    rw*: RWopsPtr
    format: string
    loaded: bool
    surface: SurfacePtr
    texture: TexturePtr
    src_rect: Rect
    dst_rect: Rect

method getFormat*(self: Image): string =
    if isNil(self.format):
        "none"
    else:
        self.format

method isLoaded*(self: Image): bool = 
    self.loaded

method setDimensions*(self: Image; src, dst: Rect) =
    self.src_rect = src
    self.dst_rect = dst

method setDimensions*(self: Image; src, dst: tuple[x, y: int; w, h: int]) =
    self.setDimensions(toRect(src), toRect(dst))

method setSrc*(self: Image, src: Rect) =
    self.src_rect = src

method setSrc*(self: Image, src: tuple[x, y: int; w, h: int]) =
    self.setSrc(toRect(src))

method setDst*(self: Image, dst: Rect) =
    self.dst_rect = dst

method setDst*(self: Image, dst: tuple[x, y: int; w, h: int]) =
    self.setDst(toRect(dst))

method load*(self: Image, file: cstring, render: RendererPtr) =

    self.loaded = false
    self.rw = sdl2.rwFromFile(file, "rb")

    if not isNIl(self.rw):
        if img.isGIF(self.rw) == 1:
            self.format = "gif"
        elif img.isPNG(self.rw) == 1:
            self.format = "png"
        elif img.isJPG(self.rw) == 1:
            self.format = "jpg"
        elif img.isBMP(self.rw) == 1:
            self.format = "bmp"
        elif img.isWEBP(self.rw) == 1:
            self.format = "webp"
        else:
            self.format = nil

    if isNil(self.rw):
        echo "yes..."

    if not isNil(self.format):

        # try loading surface
        self.surface = img.load_RW(self.rw, 1)
        if isNil(self.surface):
            #throw exception
            return

        #try loading texture
        self.texture = sdl2.createTextureFromSurface(render, self.surface)
        if isNil(self.texture):
            #throw exception
            return

        self.loaded = true

method draw*(self: Image, render: RendererPtr) =

    if isNil(self.texture):
        return

    # draw font to screen
    sdl2.copy(render, self.texture, addr(self.src_rect), addr(self.dst_rect))

# Release any resources used by the stream and free RWopsPtr memory
method close*(self: Image) =

    if not isNil(self.rw):
        let close_rw = self.rw.close(self.rw)
        #echo "closed successfully"

    if not isNil(self.surface):
        destroy self.surface

    if not isNil(self.texture):
        destroy self.texture

Usage:

var img = Image()
img.load("example.jpg", sdl_renderer)

.. loop ..

img.close()

Unsatisfied dependency: nim (> 0.11.2)

Trying to install through Nimble, I get the following output:

Downloading git://github.com/nim-lang/sdl2 into /tmp/nimble_9325/githubcom_nimlangsdl2 using git...
Cloning into '/tmp/nimble_9325/githubcom_nimlangsdl2'...
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 23 (delta 0), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (23/23), 68.79 KiB | 0 bytes/s, done.
Checking connectivity... done.
Unsatisfied dependency: nim (> 0.11.2)

And my output for nim -V is:

Nim Compiler Version 0.11.2 (2015-08-09) [Linux: amd64]
Copyright (c) 2006-2015 by Andreas Rumpf

active boot switches: -d:release

Obviously my version is not greater than 0.11.2, but as far as I'm aware that's the most recent release.

static linking causes conflicting types

If SDL_Static is defined, several conflicting types are produced by sdl.image.nim module, example:

index.nim

import sdl2, sdl2.image

const imgFlags: cint = IMG_INIT_PNG
if image.init(imgFlags) != imgFlags:
  raise Exception.newException(
    "SDL2 Image initialization failed, SDL error: " & $getError())

No errors without static linking:

nim c -d:release index.nim

Compile with --define:SDL_Static for static linking:

$ nim c -d:release --define:SDL_Static index.nim
Hint: used config file '/path/to/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: index [Processing]
Hint: sdl2 [Processing]
Hint: macros [Processing]
Hint: unsigned [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
SDL2 will be statically linked. Please make sure you pass the correct linker flags (library search paths, linked libraries).
Hint: image [Processing]
CC: index
Error: execution of an external compiler program 'gcc -c  -w -O3 -fno-strict-aliasing  -I/path/to/Nim/lib -o /path/to/my_project/nimcache/index.o /path/to/my_project/nimcache/index.c' failed with exit code: 1

In file included from /path/to/my_project/nimcache/index.c:10:0:
/path/to/my_project/nimcache/index.c:209:21: error: conflicting types for ‘SDL_GetError’
 N_NIMCALL(NCSTRING, SDL_GetError)(void);
                     ^
/path/to/Nim/lib/nimbase.h:241:44: note: in definition of macro ‘N_NIMCALL’
 #  define N_NIMCALL(rettype, name) rettype name /* no modifier */
                                            ^
In file included from /usr/include/SDL2/SDL_audio.h:32:0,
                 from /usr/include/SDL2/SDL.h:36,
                 from /usr/include/SDL2/SDL_image.h:27,
                 from /path/to/my_project/nimcache/index.c:11:
/usr/include/SDL2/SDL_error.h:42:37: note: previous declaration of ‘SDL_GetError’ was here
 extern DECLSPEC const char *SDLCALL SDL_GetError(void);
                                     ^

Nim Compiler Version 0.16.1 (2017-05-07) [Linux: amd64] (latest version of devel branch)

SDL version 2.0.4+dfsg1-2ubuntu2

SDL image version 2.0.1+dfsg-2

Release new version

There have been some important fixes, especially regarding the event objects. It would be nice if those were included in a new release.

Can't compile with nim devel

I'm getting the following error with nim devel:
.nimble/pkgs2/sdl2-2.0.4-ff413d7f590f1114d4ee7096257abcdf06d6e87e/sdl2/ttf.nim(23, 25) Error: invalid indentation
Today is my first touch with nim so I have no idea what this is about!

nim -v:

Nim Compiler Version 1.9.3 [Linux: amd64]
Compiled at 2023-05-06
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Bizzare sizeUnicode behaviour

import sdl2/ttf
from sdl2 import SdlSuccess

var 
  font: FontPtr
  w, h: cint

assert ttfInit() == SdlSuccess

proc loadFont =
  const path = "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf"
  font = openFont(path, 48)
  assert fontFaceIsFixedWidth(font) > 0
  block:
    var tmp = uint16 1
    discard sizeUnicode(font, addr tmp, addr w, addr h)
    assert w == 48 and h == 49
  block:
    var tmp = uint16 1
    discard sizeUnicode(font, addr tmp, addr w, addr h)
    assert w == 48 and h == 49

loadFont()

var tmp = uint16 1
discard sizeUnicode(font, addr tmp, addr w, addr h)
assert w == 24 and h == 49

What is going on? Can anyone confirm it happening on their machine?

Why are we missing InitSubSystem, WasInit etc?

Is there a brilliant explaination behind sdl.nim not covering:
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);

Should I add them and PR or should I know what I am thinking wrong?
//J

Question: how to use draw render.drawLines()

I have a question.

I'm new to sdl2 and nim.

How do I use render.drawLines()?
I have modified the skeleton example according to the documentation.
I don't know how to provide points: ptr Point and what means the count.
Experimenting with pointers I cannot figure out to provide this c vector.

Could not import: SDL_GL_GetDrawableSize

Issue Statement:

This code compiles, but outputs could not import: SDL_GL_GetDrawableSize when trying to run it.

import SDL2

discard SDL_Init(INIT_EVERYTHING)

let w = CreateWindow("foo", 0,0,400,400, SDL_WINDOW_SHOWN)

Compiler version:

$ nimrod -v
Nimrod Compiler Version 0.9.5 (2014-06-22) [Linux: amd64]
Copyright (c) 2006-2014 by Andreas Rumpf

active boot switches: -d:release --gc:markAndSweep --gc:generational

SDL version:

sdl2-config --version
2.0.0

Could not specify SDL_WINDOW_FULLSCREEN_DESKTOP on sdl2.setFullscreen

I just want to change window's fullscreen state to "fake" fullscreen by the
following code:

discard window.setFullscreen(SDL_WINDOW_FULLSCREEN_DESKTOP)

However sdl2.setFullscreen's flags type is Bool32, so I couldn't specify
SDL_WINDOW_FULLSCREEN_DESKTOP.

I think is the better that proc can be specified in Uint32.

iPhone functions are missing

The following functions are missing:

// SDL_system.h
extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);

extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);

sdl2.gfx roundedBoxRGBA?

Hi guys,
I'm using the gfx.roundedBoxRGBA procedure to draw a filled rounded box,
but I get these weird lines inside the box (the white box):
1

Any ideas of why the lines are there?

setDrawColor procedure call error

proc setDrawColor*(renderer: RendererPtr; r, g, b: uint8, a = 255'u8): SDL_Return {.
  importc: "SDL_SetRenderDrawColor", discardable.}

proc setDrawColor*(r: RendererPtr; c: Color) =
  setDrawColor(r, c.r, c.g, c.b, c.a)

When calling the first procedure with explicitly named arguments, like for example:

myRendered.setDrawColor(r=0, g=0, b=0, a=255)

it throws an error:

Error: cannot bind parameter 'r' twice

This didn't happen in a bit older version of the wrapper, as the second setDrawColor procedure was not defined yet.
Should this be reported here or in the Nim repository?

Matic

Depracated import

It seems that import unsigned is deprecated.

.nimble/pkgs/sdl2-1.1/sdl2.nim(3, 8) Warning: unsigned is deprecated [Deprecated]

Missing data fields in WindowEventObj

According to the SDL2 documentation, the SDL_WindowEvent (WindowEventObj) struct should contain two data fields called data1 and data2. These fields are supposed to contain window event dependent data such as the new window size or position. The latest version of the sdl2 library does not provide access to the fields in question. It looks like they were removed in d4d6e6b. Am I missing something here or were they simply removed by accident?

Can you add a text-rendering example to the examples?

I'm unfamiliar with SDL and also learning Nim. I'm struggling to write out some text:

let font = openFont("Inconsolata-Regular.ttf", 12)
let black = color(0, 0, 0, 100)
let message = font.renderTextSolid("some text", black)
let texture = createTextureFromSurface(render, message)
let message_rect = rect(0, 0, 100, 100)
let another_rect = rect(0, 0, 100, 100)
...
  render.setDrawBlendMode(BlendMode_Blend)
  render.drawLine(0, 100, 200, 300)
  render.fillRect(another_rect.unsafeAddr)
  render.copy(texture, message_rect.unsafeAddr, another_rect.unsafeAddr)

I have no idea what I'm doing :)

No SDL_PIXELFORMAT_* enum?

Hey!

Great work with the SDL 2.0 bindings :)

I was wondering why there was no SDL_PIXELFORMAT_ARGB8888 specifically, but it seems that whole enum is missing. Is there a design decision here that I'm missing?

Cheers,
Joey

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.