Using bgfx and opengl. [solved]

Started by Misterpin, March 07, 2018, 19:42:08

Previous topic - Next topic

Misterpin

Good afternoon! Let's say I have a game that uses OpenGL. But can I use bgfx and opengl at the same time for rendering or not?
For example: I draw a cube on opengl, and another 3D figure using bgfx?

Misterpin

I using GLFW for window and input.

spasi

It should be possible. There's the bgfx_get_internal_data() function that returns this structure:

struct bgfx_internal_data_t {
    bgfx_caps_t * caps;
    void * context;
}


If you initialized bgfx with the OpenGL renderer (BGFX_RENDERER_TYPE_OPENGL), then the context pointer is the OpenGL context handle. You can grab it and, for example, create another OpenGL context that shares objects with the bgfx context (you'll need the platform-specific WGL/GLX/GLX bindings for that).

Note: I just noticed that there's a bug in the bindings and the context pointer is not exposed in the BGFXInternalData class. A workaround for now:

BGFXInternalData id = bgfx_get_internal_data();
long ctx = memGetAddress(id.address() + POINTER_SIZE);

Misterpin

That is, you can initialize bgfx and render?

spasi

Yes, you first initialize GLFW with glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API), then initialize bfgx which creates the context. You get the context handle with bgfx_get_internal_data(), then you can do the custom rendering. Fair warning: it's more than likely that you'll have to study bgfx internals if you want to render to the same context as bgfx, without messing its state. Creating a new context with object sharing should be simpler. Depends on what exactly you're trying to do of course.

Misterpin

Thank you! I would like to ask a small question. Soon there was a release of LWJGL 3.2? I hope this should be a great update!

spasi

There's currently no reason to push for a 3.2 release. The release schedule is going well lately and there are fresh updates almost every weekly if you follow the nightly snapshots.

Also, a few notes on versioning:

- This library is called LWJGL 3, but it's a rewrite of LWJGL 2 that came before it. I.e. it's not really the 3rd major release of the LWJGL library, but completely new.
- So, we're currently at LWJGL v3.1.6, but you can think of it as LWJGL3 v1.6.
- I'm saving 3.2/3.3/etc. for major API-incompatible changes. It's like semantic versioning, but shifted to the right by a version number.
- I'm saving 4.0 for whenever Project Panama becomes available. LWJGL 3.x and 4.0 will be maintained in parallel, at least for a while.