Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgfx with nuklear ui #1047

Closed
VladSerhiienko opened this issue Feb 16, 2017 · 2 comments
Closed

bgfx with nuklear ui #1047

VladSerhiienko opened this issue Feb 16, 2017 · 2 comments

Comments

@VladSerhiienko
Copy link

Currently, I'm learning bgfx and trying to integrate nuklear gui library into my project.
In nk_sdl_device_create function I initialize nuklear and create bgfx resources (vertex declation, buffers and font atlas texture).
The file where I'm rendering mesh generated by nuklear is here
https://github.com/VladSerhiienko/FbxPipeline/blob/master/FbxPipeline/FbxViewer/NuklearSdlBgfx.cpp in nk_sdl_render function.
I made the shader very trivial gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); and I expect to see some red rects. I see none. I printed debug stats and checked via renderdoc, the problem is there were no draw calls made.

I need help on this issue, I'm sure there is smth very trivial I'm missing in the code, here is what i do in nk_sdl_render :

bgfx::setViewRect( 0, 0, 0, display_width, display_height );
bgfx::setState( BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE | BGFX_STATE_BLEND_EQUATION_ADD |
                    BGFX_STATE_BLEND_FUNC( BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA ) );

....

// I checked if the vertices and indices are ok, they are ok
bgfx::updateDynamicVertexBuffer(dev->vertexBufferHandle, 0, fbxv::bgfxUtils::makeReleasableRef( sdl.ogl.vertexBuffer.memory.ptr, sdl.ogl.vertexBuffer.allocated ) );
bgfx::updateDynamicIndexBuffer(dev->elementBufferHandle, 0, fbxv::bgfxUtils::makeReleasableRef( sdl.ogl.elementBuffer.memory.ptr, sdl.ogl.elementBuffer.allocated ) );

...

// Then in the loop for each command I do:
        bgfx::setScissor( ( GLint )( cmd->clip_rect.x * scale.x ),
                          ( GLint )( ( height - ( GLint )( cmd->clip_rect.y + cmd->clip_rect.h ) ) * scale.y ),
                          ( GLint )( cmd->clip_rect.w * scale.x ),
                          ( GLint )( cmd->clip_rect.h * scale.y ) );

        auto &textureHandle = *(bgfx::TextureHandle *) cmd->texture.ptr;
        bgfx::setTexture( 0, dev->textureUniformHandle, textureHandle );

        bgfx::setViewTransform( 0, view, ortho );
        bgfx::setVertexBuffer( dev->vertexBufferHandle );
        bgfx::setIndexBuffer( dev->elementBufferHandle, offset, cmd->elem_count );
        drawcallCount += bgfx::submit( 0, dev->textureProgramHandle );

        offset += cmd->elem_count;

I took the code from the nuklear sdl3 demo here https://github.com/vurtun/nuklear/blob/master/demo/sdl_opengl3/nuklear_sdl_gl3.h

@VladSerhiienko
Copy link
Author

Solved, my bad :\

@htmlboss
Copy link

Any chance you would share your fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants