Closed garettbass closed 3 years ago
I will try to test this on macOS in the near future. I developed this on a Mac under Windows. I can reboot in macOS, but don’t have a dev environment set up there yet.
I'll have a look at this now.
My nim is a bit rusty :) But I'm getting the following error both on Windows and macOS with nim 1.4.4 when following the build instructions in the README:
E:\projects\sokol-nim\src\examples\cube.nim(7, 13) Error: cannot open file: sokol/app
I figured out that I need to install the glm package via nimble, is there anything else I need to do so that nim finds the sokol modules?
I will investigate and update readme once I know exactly what to do
Ok, I made some adjustments based on a warning I got when running nimble install
to install sokol
as a nim package. I also added some info to the README describing installation of the sokol
and glm
packages required for the examples.
Looks like the recent changes from @garettbass have fixed issue #5 , as all these examples run on Linux now!
They only compile when using the -d:gl
switch, maybe that could be on by default when Linux is detected?
@geotre I have pushed a change that I think will address the issue. Please try it out and let me know.
Also, if you are able to test whether the samples build on Linux with both gcc
and clang
, I can add those the README.
@garettbass I confirm that the app.gl
change works, and the samples all build and run with both gcc
and clang
.
I forgot to mention that I needed to change line 33 in clear.nim
:
from
passAction.colors[0].value.g = if g > 1.f: 0.f else: g
to
passAction.colors[0].value.g = if g > 1.0: 0.0 else: g
I don't think the .f
thing is valid nim, does that compile on osx?
Ah, that is a silly mistake I made getting started with Nim. Will fix shortly. Thanks for finding it @geotre
@geotre, I fixed the compile error in clear.nim
. When I was getting started, I had a proc f(float64):float32
in there, which was being called by .f
to imitate C/C++ style float literal syntax. I later discovered you could write 1f
or 1.0f
in Nim to produce a float32
literal. I deleted the proc f
, but neglected to recompile and discover that it was still being referenced.
@geotre, can you tell me the --version
of gcc
and clang
that you tested? I will add those to the README
@garettbass ah I see. In Nim a float32 literal can be written as 1.0'f32
or 1'f32
I used gcc 7.5.0
and clang 10.0.0
. Happy to test other versions if needed
@floooh relevant issues should now be resolved.
Btw, it's now possible to split sokol_app_gfx.c
into two independent files (with yesterday's sokol update). For instance see sokol_app.c and sokol_gfx.c in the Zig bindings:
https://github.com/floooh/sokol-zig/tree/master/src/sokol/c
...not sure if it makes sense with the Nim bindings though (for instance, in the Zig bindings I simply wrote a native Zig module for the app/gfx-glue by hand instead of using sokol_glue.h:
https://github.com/floooh/sokol-zig/blob/master/src/sokol/app_gfx_glue.zig
Also, I haven't tested your latest commits here yet, will do so ASAP.
Thanks, this is great news. I will look into refactoring sokol-nim to take advantage of this separation.
Ok, using the new instructions in the readme, the demos are working (with -d:gl
, after merging I can add the Metal shader sources, we can also consider adding a nim-output option to sokol-shdc, similar to how I did for Zig.
One thing that's strange, when running the demos I see "event spam" in the terminal window, any idea where that's coming from? Looking through the sources I'm not seeing any obvious debug output from the sokol_app.h event handling code.
macOS x86-64 OpenGL 3.3 clang v.12.0.0 (clang-1200.0.32.29)
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
...
...I'm just going ahead and merge this for now :) Any additional fixes can go into new PRs I think.
The event spam is coming from line 13 in cube.nim, or similar in another example:
# the app.event callback will be invoked for each user input event
app.event = (e:app.Event) => echo(e.type)
Ah whoops ok, makes sense. I was grepping for the actual event strings :)
I'll add the missing Metal shader sources and add a small blurb to the Readme about macOS support.
The blend.nim sample looks a bit odd currently (the second vertex shader is missing the layout(location=x)
statements, I'll fix that. Currently it also doesn't seem to have the HLSL shaders, I'll just add the Metal source for now.
Yes, I don’t see where I went wrong, but the geometry is not right.
The vertex attribute definition in here:
...should look like this:
layout(location=0) in vec4 position;
layout(location=1) in vec4 color0;
...because the vertex layout in the pipeline description doesn't bind the vertex attributes by name. GLSL compilers tend to place vertex attributes at random positions, so without the location-attribute, position
most likely ended up at slot 1, and color0
at slot 0.
With the fix it looks much better:
Ok, cube.nim and blend.nim now also work with Metal:
I didn't get around today to add the missing D3D1/HLSL source code to the blend.nim example though.
FYI I'm currently seeing somewhat rare weird behaviour on macOS when mouse-clicking the window close button. Sometimes the button gets stuck and the window doesn't close. Currently I'm suspecting the new event polling code in sokol_app.h, that's why I have temporarily commented-out the event polling (and if I still see this behaviour during the next few days, at least that's not the culprit):
https://github.com/floooh/sokol/commit/d44328073d2316f73cec5a99b846593fadd51ba3
(I also just saw this with the Nim examples, that's why I'm writing here).
I hope this will make it easier for others to get started :)