vladar4 / sdl2_nim Goto Github PK
View Code? Open in Web Editor NEWWrapper of the SDL 2 library for the Nim language.
License: Other
Wrapper of the SDL 2 library for the Nim language.
License: Other
I don't know what the hell I am doing wrong, but after installing this package 3 times, it still says when importing the module like this:
from sdl2_nim import setClipboardText, hasClipboardText
Or like this:
import sdl2_nim
The following:
Error: cannot open file: sdl2_nim
Info:
$ nim --version
Nim Compiler Version 0.20.2 [Linux: amd64]
Compiled at 2019-07-17
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: 88a0edba4b1a3d535b54336fd589746add54e937
active boot switches: -d:release
$ nimble list | grep sdl2
sdl2_nim:
url: https://github.com/Vladar4/sdl2_nim (git)
tags: library, wrapper, sdl2, game, video, image, audio, network, ttf
website: https://github.com/Vladar4/sdl2_nim
What am I missing?
Is it going to use sdl2_nim or sdl2, updateYUVTexture only exists in sdl2_nim,
but
import sdl2,sdl2/audio
of fplay.nim
means import from nim-lang/sdl2, though it compiles and can play video, but sound processing has some obvious issue, makes sound sharp and lags. I suspect that it has some business with this issue.Using sdl2_nim uses
import sdl2/sdl
is enough, it includes all the modules.
Is there a way to link statically to SDL2 with your wrapper?
I know with nim-lang/sdl2 it was required to define SDL_STATIC.
Thanks
Maybe it's just something I'm doing wrong, but I'm trying to draw two overlapping rectangles with alpha < 255. I expect to see the first rectangle showing through the second one where they overlap, but instead it is as if alpha is always 255.
Example:
discard renderer.setRenderDrawColor(Color(r: 0xff, g: 0x00, b: 0x00, a: 0x88))
discard renderer.renderFillRect(rect1)
discard renderer.setRenderDrawColor(Color(r: 0x00, g: 0xff, b: 0x00, a: 0x88))
discard renderer.renderFillRect(rect2)
where rect1
and rect2
overlap. I can give a fully complete working example if you need. This is just a general idea.
In sdl_syswm.nim
there is an import x, xlib
which raises an exception: https://github.com/Vladar4/sdl2_nim/blob/master/sdl2/sdl_syswm.nim#L46
I suppose it should be import x11/x, x11/xlib
?
I just spent 10-20 minutes to hunt down why I could not echo a byte
, which is cause of
sdl2_nim/sdl2_nim/private/stdinc.nim
Line 87 in 43bbdb9
converter toInt*(x: uint8): int = int(x)
echo 10u8
``
If I try to compile with nim c -d:SDL_VIDEO_DRIVER_WAYLAND main.nim
, the compiler throws this error:
~/.nimble/pkgs/sdl2_nim-2.0.10.0/sdl2/sdl_syswm.nim(54, 5) Error: expression 'nil' is of type 'typeof(nil)' and has to be discarded
Line 54 in that file just says nil
. If I replace it with discard
it no longer errors there, but it then fails with
~/.nimble/pkgs/sdl2_nim-2.0.10.0/sdl2/sdl_syswm.nim(250, 23) Error: undeclared identifier: 'WlDisplay'
I'm assuming the first error is from some kind of syntax change with Nim, bu where are the WlDisplay
, WlSurface
, etc. symbols supposed to come from? Is there a missing import or something?
Sorry if I'm misunderstanding something here. Fairly new to Nim and SDL2.
Hello world. This may not be the right place to ask my question. If it's not, I'm sorry.
I prefer this version of sdl2 than the official repo's. But I ask myself : How can I be sure that it will still be maintained in several years.
Please do you plan to keep maintaining this library?
I've been compiling successfully with Arch Linux for some time now but when I rebooted and tried to compile under Windows 10 I recieved the following error message. I don't know enough about Nim macros to fix this so the problem might be PEBKAC. The problem seems to happen with sdl_image
.
... Hint: sdl_image [Processing] ... C:\Users\sam\.nimble\pkgs\sdl2_nim-2.0.7.0\sdl2\sdl_image.nim(99, 20) template/generic instantiation from here ... C:\Users\sam\.nimble\pkgs\sdl2_nim-2.0.7.0\sdl2\sdl_image.nim(43, 22) template/generic instantiation from here ... C:\Users\sam\.nimble\pkgs\sdl2_nim-2.0.7.0\sdl2\private\version.nim(79, 27) Error: expression '2002' is of type 'int literal(2002)' and has to be discarded
Nim Version:
C:\Windows\System32>nim --version
Nim Compiler Version 0.17.3 [Windows: i386]
Copyright (c) 2006-2017 by Andreas Rumpfgit hash: d1e10f9aa3e033414fb924e4f90736e46fde8256
active boot switches: -d:release
My .nimble file:
version = "1.0"
author = "Samuel Vargas"
description = "Game"
license = "MIT"srcDir = "src"
bin = @["game"]requires "sdl2_nim >= 2.0.7.0"
requires "easygl >= 0.1.0"
This exhibits behaviour of getting incorrect values w,h values from resize events.
To test:
elif evt.kind == WindowEvent and evt.window.event == WindowEvent_Resized:
echo evt.window.data1, " ", evt.window.data2
data1 will be the height and data2 will be incorrect.
# from private/video.nim
type
WindowEventID* {.size: sizeof(cint).} = enum ## \
# from /usr/include/SDL2/SDL_events.h
typedef struct SDL_WindowEvent
{
Uint32 type; /**< ::SDL_WINDOWEVENT */
Uint32 timestamp;
Uint32 windowID; /**< The associated window */
Uint8 event; /**< ::SDL_WindowEventID */
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
Sint32 data1; /**< event dependent data */
Sint32 data2; /**< event dependent data */
} SDL_WindowEvent;
private/video.nim should be modified to have WindowEventID's size be changed to sizeof(uint8)
I noticed in some of the examples and then tested it myself that sometime drawing a Rectangle shows 1 pixel offset in the bottom line of the rectangle,. Only the first or second half of that line seems to be affected though. renderDrawRect produces this bug but FilledRect or other shapes does not
setRenderDrawColor(app.renderer, 0, 99, 99, 0)
var rect = Rect(x: 10, y: 30, w: 160, h: 60)
renderDrawRect(app.renderer, addr rect)
Run through by NICO:
SDL2 is installed by homebrew.
[Running] nim compile --verbosity:0 --hints:off --run "/Users/takwolf/Develop/Nim/nico/nico/gui2.nim"
/Users/takwolf/.nimble/pkgs/nico-0.4.9/nico/backends/sdl2.nim(1037, 5) Warning: The bare except clause is deprecated; use `except CatchableError:` instead [BareExcept]
/Users/takwolf/.nimble/pkgs/nico-0.4.9/nico/backends/sdl2.nim(1794, 9) Warning: The bare except clause is deprecated; use `except CatchableError:` instead [BareExcept]
/Users/takwolf/.nimble/pkgs/nico-0.4.9/nico.nim(2785, 3) Warning: The bare except clause is deprecated; use `except CatchableError:` instead [BareExcept]
could not load: libSDL2.dylib
(compile with -d:nimDebugDlOpen for more information)
Error: execution of an external program failed: '/Users/takwolf/Develop/Nim/nico/nico/gui2 '
[Done] exited with code=1 in 2.02 seconds
MacBook Pro Apple M1 Pro: Ventura 13.2
Everything is ok on my old macOS x86. (SDL2 is Installed by homebrew too)
Nimble reports wrong version of package, bc nimble file contains outdated version info.
Discussed here: https://forum.nim-lang.org/t/4725
Btw, thanks for this package!
Not having a different versioning scheme for this library and the C library this library wraps just makes things simpler.
Can you state in the readme, why this wrapper exists, in contrast to the "official" nim-lang/sdl2 wrapper? I just found out about this repository and the differences I saw so far are the following.
I did not yet have time to test it out on my own, but I will. This is not really an issue, because I can see the differences, but it would be nice to have some distinction in the readme.
H!
I'm using nim-lang for the first time, and made a simple test using your SDL 'wrapper'.
At this point everything works oke :) Now it is time to ask some important questions ;)
I don't know if I can ask questions here, but you seem the person that understand those things.
Multiple Platforms
Most people want to build to multiple platforms, at the moment I don't even know if it is possible with nim and your SDL 'wrapper'. And how to do that.
It would be nice if you have an example directory iOS/linux/windows with a nim file with "hello world" and a readme.md how to get it working.
That would be super cool, and a go for most people to try/start using nim with your repo.
If your answer is: "This will never run on iOS", than I have to search for another language :(
The game loop
Is it possible that you make another frame rate example but this time using the knowledge below.
Many users using the first two links to create a modern game loop, that will run on many devices/systems. This will be the almost perfect starting point for new users and example how to make things work better.
Basically I have something like this
fps.nim
import sdl2
const ticksPerSecond = 25
const skipTicks*: float32 = 1000 / ticksPerSecond
const maxFrameSkip* = 5
type Fps* = ref object of RootObj
nextGameTick*: uint32
loops*: uint32
interpolation*: float64
proc init*(this: Fps) =
this.nextGameTick = sdl2.getTicks()
proc beforeGameUpdateAndEvents*(this: Fps) =
this.loops = 0
proc afterGameUpdate*(this: Fps) =
this.interpolation = float64(sdl2.getTicks() + uint32(skipTicks) -
this.nextGameTick) / float64(skipTicks)
main.nim
var fps: Fps = Fps()
fps.init()
while app.running:
fps.beforeGameUpdateAndEvents()
app.handleEvents()
while sdl2.getTicks() > fps.nextGameTick and fps.loops < Fps.maxFrameSkip:
app.update()
fps.nextGameTick = fps.nextGameTick + uint32(Fps.skipTicks)
inc(fps.loops)
fps.afterGameUpdate()
app.render(fps.interpolation)
In the render function I do something like this
warning this is old GO language code
//var drawX int32 = int32((gameobj.x - gameobj.PrevX) * interpolation + gameobj.PrevX);
// drawX := int32(gameobj.PrevX + interpolation * (gameobj.x - gameobj.PrevX))
// m_Pos_render = m_Pos_previous + ((m_Pos_current - m_Pos_previous) * fInterpolationFraction);
// drawX := int32(gameobj.PrevX + ((gameobj.x - gameobj.PrevX) * interpolation))
// state = current_state * alpha + prev_state * (1.0 - alpha);
// drawX := int32(gameobj.x * interpolation + gameobj.PrevX * (1.0 - interpolation))
//fmt.Printf("interpolation %v\n", (1 * interpolation))
drawX := int32(gameobj.x + (1 * interpolation))
//fmt.Printf("X: %v %v\n",
// gameobj.PrevX + ((gameobj.x - gameobj.PrevX) * interpolation),
// int32(gameobj.PrevX + ((gameobj.x - gameobj.PrevX) * interpolation)),
//)
DrawFrame(gameobj.textureId, drawX, int32(gameobj.PrevY), gameobj.width, gameobj.height, gameobj.currentRow, gameobj.currentFrame, pRenderer, sdl.FLIP_NONE)
As you can see you don't have to use delta time anymore and use the interpolation.
I'm still testing things, but need a pro that understand those things ;)
Greetings,
GCMartijn
I get this compile warning (context: I'm busy running 'nimble install nimgame2@#devel'):
Downloading https://github.com/Vladar4/sdl2_nim using git
Warning: Package 'sdl2_nim' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'sdl2_nim', but file 'sdl_gfx_primitives_font.nim' is in a directory named 'sdl2' instead. This will be an error in the future.
Hint: If 'sdl2' contains source files for building 'sdl2_nim', rename it to 'sdl2_nim'. Otherwise, prevent its installation by adding `skipDirs = @["sdl2"]` to the .nimble file.
This is causing clashes with the nim-lang/sdl2 wrapper and doesn't reflect the name that's in the packages.json file.
You will also need to rename the sdl2
directory to sdl2_nim
.
Hey, first of all thanks for these awesome clean and well documented bindings :)
When I build SDL_gpu from source (using MSYS2 MinGW 64-bit) I get libSDL2_gpu.dll
, while my test program using these bindings is looking for SDL2_gpu.dll
Ofc this is no big problem because I can just rename my DLL, but I'm wondering if this is an issue for all Windows users, or if it's just something wrong with my setup?
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?
E:\prog\aaeet_nim
λ nimble build
Verifying dependencies for [email protected]
Installing sdl2_nim@>= 2.0.10.0 & < 2.1.0.0
Downloading https://github.com/Vladar4/sdl2_nim using git
Warning: Package 'sdl2_nim' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'sdl2_nim', but file 'atomics.nim' is in a directory named 'sdl2\private' instead. This will be an error in the future.
Hint: If 'sdl2\private' contains source files for building 'sdl2_nim', rename it to 'sdl2_nim'. Otherwise, prevent its installation by adding `skipDirs = @["sdl2\private"]` to the .nimble file.
Tip: 5 messages have been suppressed, use --verbose to show them.
Error: Downloaded package's version does not satisfy requested version range: wanted >= 2.0.10.0 & < 2.1.0.0 got 2.0.9.2.
Error I get is
Hint: sdl_image [Processing]
/Users/hcorion/.nimble/pkgs/sdl2_nim-2.0.7.0/sdl2/sdl_image.nim(99, 20) template/generic instantiation from here
/Users/hcorion/.nimble/pkgs/sdl2_nim-2.0.7.0/sdl2/sdl_image.nim(43, 22) template/generic instantiation from here
/Users/hcorion/.nimble/pkgs/sdl2_nim-2.0.7.0/sdl2/private/version.nim(79, 27) Error: expression '2002' is of type 'int literal(2002)' and has to be discarded
((x) * 1000 + (y) * 100 + (z))
^
This is on MacOS High Sierra 10.13.1
$ clang --version
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ nim --version
Nim Compiler Version 0.17.2 (2017-11-22) [MacOSX: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf
git hash: 811fbdafd958443ddac98ad58c77245860b38620
active boot switches: -d:release -d:avoidTimeMachine -d:nativeStackTrace
I also tried with nim built from the latest git, same issue.
I talked a bit with dom86 about this and he's fine with this one becoming the first-stop for people looking for a sdl2 package.
See: https://irclogs.nim-lang.org/29-03-2018.html#11:00:51
Didn't know how to contact you so here's a quick notification! If you really don't want this, this'll probably the moment too.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.