Giter Site home page Giter Site logo

sdl2_nim's People

Contributors

avahe-kellenberger avatar codedoes avatar exelotl avatar garymcwhorter avatar gdiv avatar gulpf avatar h0lley avatar iffy avatar krux02 avatar nortiero avatar vladar4 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

sdl2_nim's Issues

Can't find "sdl2_nim"

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

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.

static linking

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

Alpha channel not working

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.

Exported converters cause havoc.

I just spent 10-20 minutes to hunt down why I could not echo a byte, which is cause of

converter toInt*(x: uint8): int = int(x)
. This should be behind a flag or removed in my view. To see the fun error message you get due to it consider the following.

converter toInt*(x: uint8): int = int(x)
echo 10u8
``

Error when setting SDL_VIDEO_DRIVER_WAYLAND

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.

Is this library long-lasting?

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?

Cannot compile sdl2_nim under Windows 10.0.16299 with sdl_image

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 Rumpf

git 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"

WindowEventID size is of cint but should be of uint8.

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)

Bug drawing Rect

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)

rect

On macOS m1: could not load: libSDL2.dylib

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)

destinction to nim_lang/sdl2

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.

  • this wrapper has less commits (whatever that means)
  • the examples are ported and actually nice to read
  • the event union is actually implemented as a union

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.

2 requests: the game loop - iOS support ?

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

Compile warning with Nim 0.20.2

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.

incorrect dll name for SDL_gpu?

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?

sdl_gpu version

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?

>= 2.0.10.0 cannot be used from Nimble because .nimble file wasn't updated

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.

ex210_pixels doesn't compile

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.

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.