DEV Community

Hello, bgfx!

Phil Peron on March 06, 2019

Bgfx is a rendering library that supports Direct3D, Metal and OpenGL variants across 11 platforms and counting. It's easy to build and there are ma...
Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

bgfx::VertexDecl has been renamed to bgfx::VertexLayout.

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

In order to use the bgfx::setPlatformData function, you also need to include bgfx/platform.h header file.

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

This line:

FILE *file = fopen(FILENAME, "rb");
Enter fullscreen mode Exit fullscreen mode

Should be

FILE *file = fopen(filePath, "rb");
Enter fullscreen mode Exit fullscreen mode
Collapse
 
allanjake profile image
Jake Allan •

this returns null for me.
filePath ends up being "shaders/dx11/vs_cubes.binýýýý"
hard coding this to "shaders/dx11/vs_cubes.bin" results in no change despite the file being present...

Any idea why?

Collapse
 
versine profile image
versine •

Because he uses memcpy, a null terminator never gets written to the end of the string. You need to allocate with "char* filePath = (char*)calloc(1, shaderLen + fileLen + 1);", then there will be a zero at the end of the string

Collapse
 
laurens_schunk_fef8060912 profile image
Laurens Schunk •

I should have read this. I took me a good 10 minutes to figure out why I was segfaulting

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

For platform compatibility, you also need to add bgfx/include/compat/*** to your include paths.

For example, for Visual Studio 2012 and higher, add bgfx/include/compat/msvc to your include paths.

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten • • Edited

In order to get bgfx to clear the screen, you also need to call bgfx::touch(0) before bgfx::frame().

Collapse
 
boldhonor profile image
Prakhar_Srivastava •
 std::cout<<"nULLER7"<<std::endl;
 const bgfx::Memory *mem = bgfx::alloc(fileSize + 1);
if(mem ==NULL) std::cout<<"nULLER"<<std::endl;
std::cout<<"nULLER4"<<std::endl;
Enter fullscreen mode Exit fullscreen mode

My program stops at "nULLER7" - dont mind the language its my native lang word
using Tdmgcc 9.2;

Collapse
 
boldhonor profile image
Prakhar_Srivastava •

Sorry figured it out it was silly

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

For bx::Vec3 you also need to include bx/math.h.

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

For FILE, and fopen function to compile, you also need to include cstdio.

Collapse
 
jpvanoosten profile image
Jeremiah van Oosten •

Thanks for the great tutorial! I learned a lot about using bgfx!

Collapse
 
freemorger profile image
freemorger •
#include "bgfx/bgfx.h"

int main(void)
{
    bgfx::init();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

its causes a LNK2019 error