bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15k stars 1.94k forks source link

How well can GLM work with BGFX? #1058

Closed auRose94 closed 7 years ago

auRose94 commented 7 years ago

GLM being the OpenGL Mathematics library by g-truc. The only extreme deal breaker is the inability to change the NDC(which is changed at compile-time). Matrices are column major format, like bx/fpumath. I just thought about forking the library and making it bgfx compatible.

shakesoda commented 7 years ago

works fine, in my experience

On Mon, Feb 27, 2017, 6:40 PM Cory Null(Noll) Crimmins - Golden < notifications@github.com> wrote:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bkaradzic/bgfx/issues/1058, or mute the thread https://github.com/notifications/unsubscribe-auth/AANZdvpaJueJAulCkSfP2k-dyQ62H5PGks5rg4kbgaJpZM4MN5b- .

bkaradzic commented 7 years ago

As long as you're consistent everywhere, it should work.

auRose94 commented 7 years ago

Thanks, yeah. I'm just experiencing some difficulty using it with bgfx and could use some tips. If other people can use it just fine I might have to closely reexamine the problem. I will try replacing some math operations from glm with ones from bx/fpumath and see if I can't build some notes on the differences. Then I might eventually build a fork and make it more compatible with bgfx. Wish me luck!

bkaradzic commented 7 years ago

I've seen glm being used with bgfx... Check this demo: https://github.com/bkaradzic/bgfx#real-time-polygonal-light-shading-with-linearly-transformed-cosines

auRose94 commented 7 years ago

I fixed my issue. The issue had to with handedness of the coordinate system. Not proud. I had put the camera behind the thing I wanted and not in front. I fixed it by specify the correct handed function I wanted. I got everything I wanted now. From what I can tell though, it would be smarter to use the perspective functions in bx/fpumath over GLM's. Just because you can specify the NDC and can't on GLM. There is nothing wrong with using GLM with BGFX in your project though. They actually go quite nice together if it wasn't for the lack of control over NDC.

And thanks @bkaradzic for the demo link, I had saw it and didn't bother digging into the code when I first saw it, now I regret not doing it sooner. Very insightful! Night.

NPatch commented 5 years ago

Seems like there was a GLM option regarding NDC.

#define GLM_DEPTH_ZERO_TO_ONE               0x00000001
#define GLM_DEPTH_NEGATIVE_ONE_TO_ONE       0x00000002

That was written 3 years ago(resides in glm/details/setup.hpp). About 3 months ago, it got a bit more elaborate and it cooperates with GLM_FORCE_LEFT_HANDED.

Just dealt with this too because GLM defaults to right handed system for OpenGL(as for NDC it defaults to gl's [-1,1]). And I was trying to replace bx::mtxProj with glm::perspective. Once I forced the left handed system, it worked fine. Going through the glm::perspective's code, you will see GLM_CLIP_CONTROL_XX_XX which is the result of NDC and Handedness definitions.

The only issue I can see is that bgfx used a runtime value for the NDC(caps->oglNDC) whereas GLM needs preprocessor definitions to work properly. At this point I've used some asserts to make sure I know if I change the renderer type, I have the correct preproc definitions enabled.