Tuesday, June 16, 2015

bgfx

Not sure into which category falls this blog entry, maybe review? I never did any 3D programming, so tutorial is out of question. Anyway I was fiddling with bgfx library and here are my experiences.
According to author, Branimir Karadzic, bgfx is cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library. Since it works on Linux I was interested to take a look at it. Best way to get info on project is to visit https://github.com/bkaradzic/bgfx and read README.md. If you are curious to try it you will need also https://github.com/bkaradzic/bx to build it. Library uses custom tool GENie so that is reason why bx is needed, we will need it for projects as well. I have built it and attempted running examples. Some were working, some not. I was attempting to run them from directory where compiled assemblies are but they need runtime. So to run examples go to /examples/runtime and execute ../../.build/linux64_gcc/bin/example-00-helloworldDebug.
How to generate project make files or codeblocks or codelite projects. Since this is cross-platform tool Windows and Mac OS X targets are supported but I will focus on Linux only. Go to bgfx project root and run

../bx/tools/bin/linux/genie --help

To generate make files, do

../bx/tools/bin/linux/genie --gcc=linux-gcc --with-tools gmake

That will produce examples as targets plus tools, like shaderc. Now cd to .build/projects/gmake-linux and execute make help to see options. For 64 bit Linux we may build using this command:

make config=debug64 example-XY-name/nothing for all

If we are using IDE, we go to .build/projects/codeblocks or codelite, open generated project set target and build it. Now we are ready to start fiddling with provided examples.
For somebody who never did any 3D coding, like me, examples provided with bgfx are too complicated so I dumbed them down.



This is example-00-helloworld reduced to creating and showing blue window. There is huge amount of plumbing code which makes those examples work in very few lines of code. For example entry::processEvents. In original shape example will print some text and place image on the screen.
Next to be slaughtered is cubes example. It draws now single triangle:


Naturally I didn't touch shaders. If we remove completely shaders from code, instances of program, triangle will become black, new achievements of hacking. I also did square, here is the relevant code:


Everything else is the same as for triangle. I hope my experience helps somebody to get started. After I spent eternity in programming there are still areas completely unknown to me. If I didn't get friendly suggestion to use identity as view and orthogonal matrix as projection I would stay on Hello World/blue window.

No comments:

Post a Comment