17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
914 stars 63 forks source link

Black screen/shader issues on MacOS #54

Closed WEREMSOFT closed 5 years ago

WEREMSOFT commented 5 years ago

Running on osX mojave. Macbook pro retina. Download from GIT and run

cargo run --example hello_world

Compiling tetra v0.2.1 (/Users/pabloweremczuk/Documents/Proyectos/rust/tetra) Finished dev [unoptimized + debuginfo] target(s) in 6.41s Running target/debug/examples/texture OpenGL Device: AMD Radeon R9 M370X OpenGL Engine OpenGL Driver: 2.1 ATI-2.4.9 OpenGL Vendor: ATI Technologies Inc. Swap Interval: VSync Error: OpenGl("ERROR: 0:1: \'\' : version \'130\' is not supported\n")

17cupsofcoffee commented 5 years ago

Someone on Discord ran into this same issue yesterday - after doing a bit of further research, it sounds if you don't force OpenGL to use the core profile on MacOS, it defaults to OpenGL 2.1 🤔

An easy way to test whether this is the cause - do the examples start working if you set the TETRA_OPENGL_FORCE_CORE_PROFILE environment variable to 1?

17cupsofcoffee commented 5 years ago

@VictorKoenders: Could you also try setting the TETRA_OPENGL_FORCE_CORE_PROFILE env variable to 1 when you get chance? It sounds like I may need to force 3.2 core profile by default to be able to support MacOS (at least without adding a load of GL extensions), but given that your drivers were reporting 3.0 by default, I want to double check that I'm not going to break things on your end!

VictorKoenders commented 5 years ago

I'll try that tomorrow evening (20-24 hours from now) once I get my linux laptop back. It's currently in the hackerspace and I am not.

17cupsofcoffee commented 5 years ago

Thanks :)

ghost commented 5 years ago

I still got the same error message even when setting the environment variable.

17cupsofcoffee commented 5 years ago

@xithiox Could you try running an example on the core-profile branch that I just pushed? I've made Tetra unconditionally force core profile there, so that should rule out any issues with the environment variable being read.

ghost commented 5 years ago

@17cupsofcoffee Just tried it out. The examples do run now on the core-profile branch but they aren't displaying anything—just a black screen.

WEREMSOFT commented 5 years ago

Same result: Black screen on core-profile branch.

I'm in gmt+1. Just in case you need more tests.

VictorKoenders commented 5 years ago

Wouldn't it be easier just to target 2.1.0 instead of 1.3.0?

That seems to be what apple likes: link

The steam summary suggests that most people support DX10 or higher (about 99%). According to this stackexchange post, that's comparable to OpenGL 3.0.

Alternatively, we can make different shaders per OS, as long as we use the functionality that all of them support, this should work.

17cupsofcoffee commented 5 years ago

Don't get mixed up between the shader language versions and the OpenGL versions - it's 3.2 we target, not 1.3 :p

Long term I might try to support 2.1, but it'll require enabling some GL extensions (e.g. framebuffers weren't added to core until 3.0, and Tetra uses them for screen scaling). Will have to do some research on that.

I'll look into the black screen issue today - the shaders don't do anything particularly complex, so hopefully getting them working on Mac won't be too hard.

17cupsofcoffee commented 5 years ago

@xithiox @WEREMSOFT - Try pulling the latest changes to core-profile and see if it works now. I've bumped the shader versions to #version 150 core, which is the version that corresponds to OpenGL 3.2. That's also the shader version that GGEZ uses, and they seem to have working Mac support, so something is probably broken in my code if this doesn't work 😅

17cupsofcoffee commented 5 years ago

@xithiox @WEREMSOFT - Aah, actually - I just realized the core-profile doesn't have the fix from #52 in it, and that was also causing black screens. I've merged those changes in - hopefully one or both of those fixes will get stuff working.

WEREMSOFT commented 5 years ago

Sadly not. I checked out I have this after execute git log:

commit 0c84cf007d81f9f7ce4d51e41eedb4ede25ced80 (HEAD -> core-profile, origin/core-profile) Merge: e2dff24 ac1b340 Author: Joe Clay 27cupsofcoffee@gmail.com Date: Sun Dec 23 12:19:36 2018 +0000

Merge branch 'master' into core-profile

commit e2dff245a6625897a5ed1aaa8fec86c68b6edfd3 Author: Joe Clay 27cupsofcoffee@gmail.com Date: Sun Dec 23 12:03:52 2018 +0000

Bump shader versions to 150

I still have a black window. I moved the window around and resize because other game engines like SFML have this bug, but still no luck.

Tested with cargo "hello_world" and "animations"

17cupsofcoffee commented 5 years ago

Agh :( Well I'll merge the core profile changes into master, since it seems like they're a requirement to get anything to run on Mac, even if it's just a black screen. Will keep trying to figure out what's causing the issues, although I don't know how much time I'll have this week cause of the holidays.

WEREMSOFT commented 5 years ago

You have me on twitter and here. Drop me a line if you want me to test something.

Cheers

VictorKoenders commented 5 years ago

0.2.2 still works on my machine with mesa drivers

totsteps commented 5 years ago

Is it fixed? I get the same error:

Finished dev [unoptimized + debuginfo] target(s) in 0.14s                                       
     Running `target/debug/examples/hello_world`
OpenGL Device: AMD Radeon Pro 560X OpenGL Engine
OpenGL Driver: 4.1 ATI-2.4.9
OpenGL Vendor: ATI Technologies Inc.
Swap Interval: VSync
Error: OpenGl("ERROR: 0:1: \'\' :  version \'130\' is not supported\nERROR: 0:2: \'\' :  #version required and missing.\n")

Thanks ☺️

17cupsofcoffee commented 5 years ago

@gagan0723 Which OS version/Tetra version are you using? There's still issues on Mac, but I was under the impression we could at least get the shaders to compile now...

totsteps commented 5 years ago

OS: macOS Tetra: 0.2.2

17cupsofcoffee commented 5 years ago

Thank you for the info - the tricky bit for me is that I don't have access to a Mac, so it's very hard to diagnose these kinds of issues (especially when it seems like other Mac users are getting an entirely different problem with black screens rather than shader compilation) 😞 If I have any ideas for a fix, I'll be sure to let you know.

17cupsofcoffee commented 5 years ago

The new release (0.2.3) has a couple of compatibility fixes included - fingers crossed it resolves some of these issues...

totsteps commented 5 years ago

Same issue.

▶ fork/tetra (master ⁚ ) (🦀 v1.31.0) cargo run --example hello_world
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s                                       
     Running `target/debug/examples/hello_world`
OpenGL Device: AMD Radeon Pro 560X OpenGL Engine
OpenGL Driver: 4.1 ATI-2.4.9
OpenGL Vendor: ATI Technologies Inc.
Swap Interval: VSync
Error: OpenGl("ERROR: 0:1: \'\' :  version \'130\' is not supported\nERROR: 0:2: \'\' :  #version required and missing.\n")

▶ fork/tetra (master ⁚ ) (🦀 v1.31.0) 

Git log:

commit bec85347d1af994f11c6383c62d732ae5166caf6 (HEAD -> master, tag: 0.2.3, origin/master, origin/HEAD)
Author: Joe Clay <27cupsofcoffee@gmail.com>
Date:   Thu Jan 3 01:24:42 2019 +0000

    Release 0.2.3

commit d62f30d424f50003f353757e096ca8ba3f32b81b
Author: Joe Clay <27cupsofcoffee@gmail.com>
Date:   Thu Jan 3 00:28:24 2019 +0000

    Update CHANGELOG.md [skip-ci]
17cupsofcoffee commented 5 years ago

Agh, how annoying :(

JD557 commented 5 years ago

Changing the shader version to #version 140, #version 150 or #version 150 core all seem to fix the issues for me. Tested on both "Hello World" and "Animation".

I'm running an older version of Mac OS X, though (Sierra, 10.12.6).

17cupsofcoffee commented 5 years ago

Thanks for the tip @JD557 - after looking into it a bit more, it seems like the Mac OpenGL implementation just doesn't bother to implement anything other than GLSL 1.40 and 1.50. Both GGEZ and Quicksilver (the two big Rust 2D game frameworks) also use #version 150, so I think we should just go with that.

In the long run, I'd like to see if I can do what FNA/Raylib/LibGDX do and get the whole thing running on OpenGL 2.1 (which would also open the door to porting to WebGL, I think?), but I need a bit of a break from graphics code I think :p

17cupsofcoffee commented 5 years ago

@WEREMSOFT / @xithiox / @gagan0723 - I've just checked in the fix suggested above to the master branch. If any of you have some free time, I'd appreciate it if you let me know if this fixes your issue :)

EDIT: It's also in the 0.2.10 release. Fingers crossed this finally sorts it!

totsteps commented 5 years ago

Thanks, @17cupsofcoffee & @JD557 after latest changes everything works fine.

ghost commented 5 years ago

Oh nice, it looks like that fixed it. 😄

17cupsofcoffee commented 5 years ago

Fantastic :) I think its probably safe for us to close this, then!