All blog entries, ordered from most recent. Entry count: 1198.
# Zjazd Twórców Gier 2010
Fri
28
May 2010
On 15-19 July 2010 an interesting event is going to happen in Gdańsk (Poland) - Zjazd Twórców Gier 2010 (would it be "Game Developers Convention" in English?). This event, organized by some young passionates, will take place in the University of Gdansk. It is 3rd edition this year, but I didn't attend it before, so I have no idea how does it look like, especially compared to the IGK conference. But this motivates me even more to go there and find out, so I'm going to attend it this year. I hope to meet some nice people there and have much fun :) The only problem is a long travel from Warsaw to Gdansk. Who else is going to go there from Warsaw?
# More Defective C++ ;)
Sun
23
May 2010
Today I'll disclose my opinions more than ever before, inspired by the C++ FQA Lite (Frequently Questioned Answers) - a great reading I recommend to any C++ programmer. If it's too long for you, just be sure to overview the introductory chapters - "Defective C++" and "Big Picture Issues". This document is written by Yossi Kreinin - a man who apparently knows and uses C++ language although doesn't like it - just like me. I like his text so much because I agree with most of his arguments. The main part of the FQA has a form of alternative answers to the questions from the C++ FAQ Lite. It's very subjective, emotional and also funny to read. I've especially laughed at point 23.2 - it's so true about all these design patterns :) Surely my opinions expressed here are not so valuable compared to opinions of all these older and more experienced programmers around, but that's what blogs are for - expressing one's opinions...
My list of objections about C++ language is long. Some specific ones are:
# Some Thoughts about Library Design
Sun
16
May 2010
Much has been said about designing good user interface, whether for desktop applications, websites or games. There are whole books available about GUI design and even this year's IGK-7'2010 conference featured two lectures about the interface in games. But what about interfaces for programmers?
I can't find much about the rules of good library API design and I believe there is much to say in this subject. I only know The Little Manual of API Design written by Jasmin Blanchette from Trolltech/Nokia, one of the creators of Qt library (thanks for the link Przemek!). There is also a blog entry about Math Library, which is quite interesting. Inspired by it, I've came up with a general thought that you cannot have all the following features when designing a library and its API, you have to choose 2 or 3 of them and make some compromise:
I think some patterns and best practices as well as some anti-patterns could be found when you look at interfaces of many libraries. Maybe I'll post some more of my thoughts on this subject in the future. In the meantime, do you know any other resources about API design?
Comments | #philosophy #software engineering #libraries Share
# Effects in DirectX 11
Sat
15
May 2010
I no longer believe Microsoft did a good job complicating new DirectX so much. Effects framework - the API that supported loading and using effect files that grouped HLSL code and render states into passes and techniques - is no longer intrinsic part of D3DX. Instead they provided source code for this library so you have to compile it by yourself!
To do this: Enter your DX SDK subdirectory "Samples\C++\Effects11", open a "Effects11_*.sln" solution file appropriate for your Visual C++ version and compile the project in both Debug and Release configuration.
Then to use effects API in your project you have to include this header: "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Inc\D3dx11effect.h" and link with this lib: "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Debug\D3DX11EffectsD.lib (Debug) or "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Release\D3DX11Effects.lib" (Release), as well as with "d3dcompiler.lib" (in both configurations).
Here is example of how to load an effect from file. You need to first compile a source code from file or memory into a blob binary effect and then create real effect object from this blob.
// Compile effect from HLSL file into binary Blob in memory ID3D10Blob *effectBlob = 0, *errorsBlob = 0; HRESULT hr = D3DX11CompileFromFile( "Effect1.fx", 0, 0, 0, "fx_5_0", 0, 0, 0, &effectBlob, &errorsBlob, 0); assert(SUCCEEDED(hr) && effectBlob); if (errorsBlob) errorsBlob->Release();
// Create D3DX11 effect from compiled binary memory block ID3DX11Effect *g_Effect; hr = D3DX11CreateEffectFromMemory( effectBlob->GetBufferPointer(), effectBlob->GetBufferSize(), 0, g_Dev, &g_Effect); assert(SUCCEEDED(hr)); effectBlob->Release();
The effect itself is not enough. You need to retrieve object that represents "pass" to use it. So you get a technique from the effect (by index or by name) and then the pass from the technique.
ID3DX11EffectTechnique *g_EffectTechnique; // No need to be Release()-d. g_EffectTechnique = g_Effect->GetTechniqueByIndex(0); assert(g_EffectTechnique && g_EffectTechnique->IsValid()); ID3DX11EffectPass *g_EffectPass; // No need to be Release()-d. g_EffectPass = g_EffectTechnique->GetPassByIndex(0); assert(g_EffectPass && g_EffectPass->IsValid());
Now when you have this object, you can apply settings from this pass to the device context during rendering:
g_EffectPass->Apply(0, g_Ctx); g_Ctx->Draw(3, 0);
But still one problem reamins. In DirectX 11 you need to pass a pointer to the bytecode with compiled shader when creating input layout - a step that you probably cannot omit. Fortunately there is a way to access this pointer stored inside loaded effect. You just need to pass through two descriptors, just like this:
D3DX11_PASS_SHADER_DESC effectVsDesc;
g_EffectPass->GetVertexShaderDesc(&effectVsDesc);
D3DX11_EFFECT_SHADER_DESC effectVsDesc2;
effectVsDesc.pShaderVariable->GetShaderDesc(effectVsDesc.ShaderIndex, &effectVsDesc2);
const void *vsCodePtr = effectVsDesc2.pBytecode;
unsigned vsCodeLen = effectVsDesc2.BytecodeLength;
ID3D11InputLayout *g_InputLayout;
D3D11_INPUT_ELEMENT_DESC inputDesc[] = { /* ... */ };
hr = g_Dev->CreateInputLayout(
inputDesc, _countof(inputDesc), vsCodePtr, vsCodeLen, &g_InputLayout);
Luckily it looks like the effect framework doesn't add much functionality over pure HLSL shader supported by D3D11 itself, so you don't have to use it. Defining these techniques and passess is not so important after all...
Comments | #directx #rendering Share
# Origami: Sonobe Module
Thu
13
May 2010
It looks like Sonobe module is a "Hello World" in modular origami. This simple module prepared from square sheet of paper is very popular, so you can find lots of instructions about how to fold it on the Internet. It's also very universal - you can use it to create a cube (6 modules required), some polyhedra, as well as arbitrary unregular shapes made of cubes, like Tetris blocks :) Here are my objects made of Sonobe modules:
# Modular Origami - Spike Ball
Sat
08
May 2010
I hope you wouldn't mind if I start blogging here a bit about modular origami. I find it related to 3D graphics programming in some way ;) To introduce the topic: As you probably know, origami is a traditional Japanese art of folding paper, without use of cuts or glue. Many objects can be done this way, including characters and animals. But I'm mostly interested in modular origami - a type of origami where some number of identical pieces (called modules) have to be prepared to be then assembled together into some interesting geometrical form.
It's not very easy. I especially couldn't imagine myself developing a new kind of module. Luckily there are some books and websites about origami. There are also lots of videos on YouTube teaching how to make particular objects. I believe YouTube is kind of a revolution in teaching origami because a video shows much more and is easier to understand than traditional static diagram.
Today I've finished assembling an cuboctahedron made of 12 modules invented by Rona Gurkewitz and Bennett Arnstein.
Here is the video I've learned it from: How to make an Origami Spiky Cuboctahedron aka Spike Ball. I can see there is whole website dedicated to these spike balls: Spike Ball Heaven.
That's it for the start. Next time I'll show some more basic stuff.
See also: my Super Spike Ball.
# LZMA SDK - How to Use
Sat
08
May 2010
What do you think about when I tell a word "compression"? If you currently study computer science, you probably think about some details of algorithms like RLE, Huffman coding or Burrows-Wheeler transform. If not, then you surely associate compression with archive file formats such as ZIP and RAR. But there is something in between - a kind of libraries that let you compress some data - implement a compression algorithm but do not provide ready file format to pack multiple files and directories into one archive. Such library is useful in gamedev for creating VFS (Virtual File System). Probably the most popular one is zlib - a free C library that implements Deflate algorithm. I've recently discovered another one - LZMA. Its SDK is also free (public domain) and the basic version is a small C library (C++, C# and Java API-s are also available, as well as some additional tools). The library uses LZMA algorithm (Lempel–Ziv–Markov chain algorithm, same as in 7z archive format), which has better compression ratio than Deflate AFAIK. So I've decided to start using it. Here is what I've learned:
If you decide to use only the C API, it's enough to add some C and H files to your project - the ones from LZMASDK\C directory (without subdirectories). Alternatively you can compile them as a static library.
There is a little bit of theory behind the LZMA SDK API. First, the term props means a 5-byte header where the library stores some settings. It must be saved with compressed data to be given to the library before decompression.
Next, the dictionary size. It is the size of a temporary memory block used during compression and decompression. Dictionary size can be set during compression and is then saved inside props. Library uses dictionary of same size during decompression. Default dictionary size is 16 MB so IMHO it's worth changing, especially as I haven't noticed any meaninful drop in compression rate when set it to 64 KB.
And finally, end mark can be saved at the end of compressed data. You can use it so decompression code can determine the end of data. Alternatively you can decide not to use the end mark, but you must remember the exact size of uncompressed data somewhere. I prefer the second method, because remembering data size takes only 4 bytes (for the 4 GB limit) and can be useful anyway, while compressed data finished with end mark are about 6 bytes longer than without it.
Compressing full block of data with single call is simple. You can find appropriate functions in LzmaLib.h header. Here is how you can compress a vector of bytes using LzmaCompress function:
Comments | #commonlib #libraries #algorithms Share
# Compiling wxWidgets 2.9.0 in Visual C++ 2010 Express
Thu
06
May 2010
NEW! (2011-02-18) I posted this entry months ago, wxWidgets keeps evolving and so it may no longer work. For building wxWidgets 2.9.1 in Visual C++ 2010, I now recommend you follow steps described here: Visual Studio C++ 2010 - Microsoft Visual C++ Guide - wiki.wxwidgets.org and here: Fixed wxWidgets 2.9.1 project files Visual Studio 2010 - forums.wxwidgets.org.
My old blog entry:
Today I wanted to compile wxWidgets library (version 2.9.0, which contains lots of interesting new features, including wxPropertyGrid control) under Visual C++ 2010 Express. A strange error appeared that stopped the build and explained nothing specific about the cause:
Microsoft.CppCommon.targets(151,5): error MSB6001: Invalid command line switch for "cmd.exe". The path is not of a legal form.
It took me some time to find a correct solution on Google, as many of them didn't work. (Copy setup.h file to some another directory? Made no difference in my case. Use the wx.dsw - project file for oldest IDE version? Didn't work either, my Visual says it cannot import such projects.)
Finally I've found this forum topic: http://forums.wxwidgets.org/viewtopic.php?t=27630. Sami Hamlaoui on 25th April 2010 posted a ZIP archive there containing converted and fixed project for Visual C++ 2010 that you can download and use to successfully build wxWidgets 2.9.0. Thanks for that!
After you build all projects in Debug and Release configuration, you just need to setup include and library paths in the IDE:
...\wxWidgets-2.9.0\include
...\wxWidgets-2.9.0\include\msvc
...\wxWidgets-2.9.0\lib\vc_lib
And finally you can use wxWidgets in your projects.
To do that, you need to #include files such as comctl32.lib, rpcrt4.lib, winmm.lib, advapi32.lib, wsock32.lib and desired wx libraries like wxbase29ud.lib and wxmsw29ud_core.lib ("d" is for debug,
use versions without "d" in Release configuration).
Also remember that the new wxWidgets has no ASCII support, so you have to use Unicode character set.