Reg__ @ Twitter Twitter Updates

reg__ Delicious Bookmarks

Facebook

Recommended Productions

FX Batch Compiler 1.1

This Windows application supports compilation of FX effect files and HLSL shader files using fxc command line compiler included in DirectX SDK. You can compile many files at time or one file with different settings.

Features:

  • Write compilation scripts in a simple language by specifying parameters for fxc.exe.
  • Compile multiple shaders at time.
  • Compile only shaders that need rebuild checked by file modification time.
  • Review success or failure, warning and error count and compiler output for every task.
  • Compile single HLSL source file with different parameters and preprocessor macros.

Date: 2011-02-09

Download:
FxBatchCompiler_1-1.exe
FxBatchCompiler-1.1-bin.zip
FxBatchCompiler-1.1-src.zip

Block Wizard

My first Flash game. Coded with FlashDevelop in ActionScript 3.

Date: 2010-04-06

CommonLib 9.0

Universal library for C++, created especially with game programmers in mind. Includes: math module (vectors, matrices, quaternions, planes, rich set of collision functions and more), string operations, conversions, smart pointers, configuration files handling, date and time module, exception class hierarchy for error handling, file system handling, stream class hierarchy, FreeList - free memory allocator, complex logger, profiler, library for threading and synchronization, tokenizer, wrappers for compression with zlib.

Language: C++. Platforms: Windows and Linux. License: GNU LGPL. Optional support for Unicode. Optional integration with D3DX. Documentation made with Doxygen.

Date: 2009-12-16

Download:
CommonLib_9_0.zip (4.92 MB)

Aqua Fish 2

Game for children - clone of PacMan. Player swims as a fish and collects points, as well as special items. Player also have to run away from enemies or destroy them. 60 maps in 6 different titlesets. Low hardware requirements. See also YouTube video. Game was published by Play Publishing company.

GameDev Calc

Calculator for game programmers. Basic data unit is a vector of 1-4 floating point numbers, which can be treated as (x,y,z,w) vector or (r,g,b,a) color. Next to basic calculations like addition, multiplication or sinus, vector operations are also available, e.g. vector normalization, conversion between degrees and radians, color conversion between RGB and HSB, finding linear an quadratic function coefficients and much more. Instead of entering single number, here you can see all the history of your calculations in form of stack and all operations are performed on that stack. Data can be entered and retrieved in different formats, like "D3DXVECTOR4(0.0f, 0.5f, 0.752f, 1.0f)" or "0xFF0080C0". Platform: Windows. Language: C#. License: GNU GPL.

Download:
GameDevCalc_1-0.zip (53.06 KB)
GameDevCalc_1-0_src.zip (50.73 KB)

RSS Feed: Adam Sawicki - Homepage (Blog) Blog

22:47
Mon
07
May 2012

Direct2D - Unboxing

Just as some bloggers record unboxing of products, I'd like to share my first impressions from playing around with Direct2D library. What is it? As you can guess from its name, it is a library from Microsoft for efficient, hardware-accelerated drawing of immediate-mode 2D graphics. It is successor of the old GDI, as well as GDI+. It is native library, object-oriented, based on COM. It works on Windows 7, as well as Windows Vista (after installing SP2 and Platform Update) and Windows 2008. The API seems modern, clean and very elegant, much like Direct3D 10/11. But of course it could be just a matter of taste. You can find its documentation, as well as headers and libraries in DirectX SDK. Docs say something about Windows 7 SDK, so probably it's there too.

What can it interop with? You can create a render target that will send the graphics to either a window (using HWND), a GDI canvas (HDC), DXGI surface (interop with Direct3D 10/11) or WIC Bitmap. Interop with GDI is also possible in the opposite way - you can obtain a HDC from D2D render target. Microsoft advices using WIC (Windows Imaging Component) for loading bitmap files. Another important library that cooperates with Direct2D is DirectWrite, which enables text rendering.

I didn't find any good tutorial about Direct2D, but I haven't look for it very hard either. I think the official documentation is good enough teaching all aspects of the library. After reviewing the documentation, I'm very impressed not only by the looks of the API, but also by the list of features is supports, like:

  • Uses floats everywhere, as coordinates and colors. Rectangles use (left, top, right, bottom) representation, not (left, top, width, height) like many GUI API-s.
  • Arbitrary 2D affine transforms using 3x2 matrix.
  • Antialiasing.
  • DPI-aware.
  • Alpha blending, with straight or premultiplied alpha.
  • Gamma correction and linear space.
  • Alpha-only textures (A8 format).
  • No separate brush and pen objects to be used used simultaneously like in GDI. There is only brush in D2D - a solid one, the one with linear gradient, radial gradient or created from bitmap. It is used to either fill the surface of a shape or outline it, depending on the draw call.
  • No selecting "current" brush, no tons of states to switch like in OpenGL or Direct3D 9. You fill in a structure with the description of desired parameters, create an object from it and the object is quite immutable.
  • Clipping with a shape, masking with alpha channel of any image.
  • Uses GPU if possible, falls back to software rendering if not. Even then the performance is promised to be better than GDI+.
  • Manipulating and querying arbitrary 2D shapes (made of lines and bezier curves), including: transforming with a matrix, CSG (union, intersection, difference, xor), outlining, widening, simplification, triangulation, computing area and length, interpolating point and tangent vector along the geometry, hit-testing point against interior or border (with given stroke width), testing if two geometries overlap or if one fully contains another. Wow, that's a lot! I think D2D could serve as a geometric math library :)

Things I don't like so far about the library:

  • I can't find blending modes anywhere! Is there really only alpha-blending available (and additive blending with the help of premultiplied alpha)? Libraries that use integers like GDI have bitwise operations (including the famous XOR used to draw and un-draw frames). Libraries that use floats like Direct3D have addition, subtraction, multiplication etc. Some API-s even have both, like OpenGL ES. Direct2D has none? WTF?! (Much like GDI+)
  • Lost device horror is back! ID2D1RenderTarget::EndDraw method can return D2DERR_RECREATE_TARGET. You have to free and recreate your render target then, along with all resources associated with it, like brushes, bitmaps and so on. WTF Microsoft?! I thought this idea is gone after introducing Direct3D 10 and new graphics driver model? I now hope this error is returned only when user unplugs his graphics card ;)
  • Direct2D suffers from a phenomenon similar the famous half-texel offset in Direct3D 9. Render target starts from (0, 0) at the top-left corner, not at the center of the first pixel. So you have to offset everything by (0.5, 0.5). To draw a line starting exactly from the pixel at third column and second row, you have to start it at position (3.5, 2.5). Otherwise every line is blurred across two neighbour pixels, like on the image below. Which still looks pretty good and doesn't degrade performance though.

My first test, drawn using following code:

using namespace D2D1;
const D2D1_SIZE_F rtSize = m_RenderTarget->GetSize();
m_RenderTarget->BeginDraw();

m_RenderTarget->Clear(ColorF(ColorF::White));

m_Brush->SetColor(ColorF(ColorF::Silver));
const float gridStep = 24.f;
for(float x = gridStep; x < rtSize.width; x += gridStep)
    m_RenderTarget->DrawLine(Point2F(x, 0.f), Point2F(x, rtSize.height), m_Brush, 1.f);
for(float y = gridStep; y < rtSize.height; y += gridStep)
    m_RenderTarget->DrawLine(Point2F(0.f, y), Point2F(rtSize.width, y), m_Brush, 1.f);

m_Brush->SetColor(ColorF(ColorF::Navy));
m_RenderTarget->DrawRectangle(RectF(200.f, 400.f, 400.f, 550.f), m_Brush);
m_RenderTarget->DrawRectangle(RectF(240.f, 450.f, 280.f, 500.f), m_Brush);
m_RenderTarget->DrawRectangle(RectF(320.f, 450.f, 360.f, 550.f), m_Brush));
m_RenderTarget->DrawLine(Point2F(200.f, 400.f), Point2F(300.f, 300.f), m_Brush, 1.f);
m_RenderTarget->DrawLine(Point2F(300.f, 300.f), Point2F(400.f, 400.f), m_Brush, 1.f);

m_RenderTarget->EndDraw();

Comments (0) | Tags: rendering direct2d

23:37
Wed
02
May 2012

Functional Programming is the New Trend

Some time ago I've written about data-oriented design as a popular trend among game developers, opposite to the belief that object-oriented programming is the silver bullet for all challenges and complexities of programming. Mike Acton, Engine Director at Insomniac Games and the creator of #AltDevBlogADay, is probably the biggest evangelist of this idea.

Now I can see that functional programming is a concept gaining popularity and it seems to follow similar mindset. Of course we won't start coding our games and programs in Lisp or Haskell tomorrow, but some of the ideas coming from functional languages can be applied to thinking about our everyday C++ code, instead of seeing design patterns, singletons and class inheritance everywhere. This can mean, for example, making data const (immutable) wherever possible and writing functions as pure - returning processed data that depend only on input data and not mutating or accessing any global state. This makes code simpler to read and understand, debug and unit-test, as well as to parallelize.

I've seen some voices in gamedev advocating that functional programming is the future even years ago. I can remember slides from some conference about it, I can't find it now though. But recently more and more programmers seem to be interested in learning some functional languages, writing about it, like explaining what the monad is etc. Some really recent, interesting blog posts about applying idea of functional programming in the real code:

Life Without Objects by Chris Turner
(Almost) functional programming tips for C++ by Bryan St. Amour
And finally, a post from #AltDevBlogADay by John Carmack: Functional Programming in C++.

By the way, it really impresses me how despite all his experience, fame and success, Carmack still tweets and blogs about programming, down to its dirtiest details, instead of writing about management, leadership, enterpreneurship, money, psychology, recruitment etc., like many other professionals do.

Comments (6) | Tags: c++

20:48
Mon
16
Apr 2012

Redirecting Output to File in Visual C++

If you write a console program in C++ that prints
 a lot of text to the standard output, sometimes watching these few newest line that appear in the black system console is not enough. When running the program from command line, you can redirect its output to a text file with syntax like > Output.txt.

What about launching program from Microsoft Visual Studio / Visual C++ Express? Can you redirect console output to file from there? There is no field for it in project properties, but it actually works when you just append the redirect symbol to Command Arguments field, like this:

Comments (1) | Tags: c++ visual studio

22:06
Sun
15
Apr 2012

DirectXMath - A First Look

Programmers using DirectX have access to the accompanying library full of routines that support various 3D math calculations. First it was D3DX - auxilliary library tightly coupled with DirectX itself. It's still there, but some time ago Microsoft released a new library called XNA Math. I've written about it here. This library also ships with latest versions of DirectX SDK (which was last updated in Jun 2010), but it is something completely new - a more independent, small, elegant and efficient library, portable between Windows (where it can use SSE2 or old FPU) and Xbox 360.

Now Microsoft comes up with another library called DirectXMath. See the official documentation and introductory blog post for details. As a successor of XNA Math, it looks very similar. Main differences are:

  • They dropped support for Xbox 360. The library is now portable between Windows (using SSE2 or FPU) and ARM (using NEON).
  • It is now a C++ library, makes use of namespaces and templates, so it no longer works with C.
  • It makes use of new C++11 standard (and requires compiler that supports it), including integer types from <cstdint> like uint32_t instead of types from <Windows.h> like DWORD.

Sounds great? Well, I didn't tell yet how to get it. It's not shipped with DirectX SDK. You need the SDK for Windows 8. They say that:

The library is annotated using SAL2 (rather than the older VS-style or Windows-style annotations), so requires the standalone Windows SDK for Windows 8 Consumer Preview or some additional fixups to use with Visual C++ 2010.

So probably I'm not going to switch to this new library anytime soon :P

Comments (0) | Tags: directx math

17:00
Sat
14
Apr 2012

unique_ptr in Visual C++ 2010

Sure C++ doesn't have garbage collector, but the way of freeing memory and other resources recommended for this language is RAII idiom - creating classes (like smart pointers) that free pointed object in destructor. Standard library of old C++ provided only auto_ptr class for this, which had many flaws. Some programmers have been writing their own smart pointer classes or using these from Boost library - like scoped_ptr and shared_ptr.

The new C++11 standard (called C++0x before release) defines new smart pointers, similar to these from Boost. They are called unique_ptr and shared_ptr, they exist in std namespace and require #include <memory>. Microsoft Visual Studio 2010 / Visual C++ Express 2010 already implement parts of this new standard. Language features like r-value reference and move semantics make these smart pointers more powerful than before.

shared_ptr is for shared ownership and uses reference counting, so it's not needed very often in my opinion. More often we are dealing with a situation where there is one, clearly stated owner of a dynamically allocated object, like a local variable in some scope or a class member. So let's take a look at how unique_ptr can be used for this:

std::unique_ptr<MyClass> ptr1(new MyClass());
// ptr1 will automatically call destructor and free the object when going out of scope.

std::unique_ptr<MyClass> ptr2; // ptr2 is NULL
ptr2.reset(new MyClass(1)); // Object is created and passed to smart pointer.
ptr2->m_Number = 2; // Object can be dereferenced like with normal pointer.
ptr2.reset(new MyClass(3)); // New object is given to the pointer. First one is destroyed.
ptr2.reset(); // Second object is destroyed. ptr2 is now NULL.

unique_ptr can be used for arrays:

std::unique_ptr<MyClass[]> arrPtr(new MyClass[6]); // Smart pointer to array.
arrPtr[2].m_Number = 10; // Indexing array like with normal pointer.
// arrPtr will free the array with delete[] when going out of scope.

unique_ptr cannot be copied, but thanks to r-value references and move semantics introduced in C++11 it can be moved, so it can also be passed as parameter and returned by value, like this:

typedef std::unique_ptr<MyClass> MyClassPtr;

MyClassPtr ProducePtr() {
    MyClassPtr ptr = MyClassPtr(new MyClass());
    ptr->m_Number = 123;
    return ptr;
}

void ConsumePtr(MyClassPtr ptr) {
    printf("The number was %d\n", ptr->m_Number);
}

ConsumePtr(ProducePtr());

MyClassPtr ptr = ProducePtr();
ptr->m_Number = 456;
ConsumePtr(std::move(ptr));

Unlike old scoped_ptr from Boost, unique_ptr from C++11 can be used inside STL containers, e.g. std::vector. Reallocation that happens inside vector will not corrupt it.

std::vector<MyClassPtr> vec;
vec.push_back(MyClassPtr(new MyClass(1)));
vec.emplace_back(new MyClass(2)); // A new, better way of adding elements.

for(auto it = std::begin(vec); it != std::end(vec); ++it)
    printf("%d\n", (*it)->m_Number);

And now the most interesting part - custom deleters! unique_ptr can be used to store any resources because you can provide it with your own code that will be used to free that resource. For example, you can print something to console before deleting object :) Deleter can be a functor passed as second template parameter:

struct MyDeleter {
    void operator()(int* ptr) const {
        printf("Deleting int!\n");
        delete ptr;
    }
};

std::unique_ptr<int, MyDeleter> ptr1(new int(1));

Deleter can also hold some state. This way you can associate additional information with the pointer, like a memory pool that the pointer object comes from. Now the sizeof(ptr3) will be 8 because it must hold deleter data next to the pointer.

class MyComplexDeleter {
public:
    MyComplexDeleter(int memoryPool) : m_MemoryPool(memoryPool) {
    }
    void operator()(int* ptr) const {
        printf("Deleting from memory pool %d\n", m_MemoryPool);
        delete ptr;
    }
private:
    int m_MemoryPool;
};

MyComplexDeleter deleterForPool20(20);
std::unique_ptr<int, MyComplexDeleter> ptr3(new int(3), deleterForPool20);

Deleter can also be a normal function, like fclose:

std::unique_ptr<FILE, int(*)(FILE*)> filePtr(
    fopen("Readme.txt", "rb"),
    fclose);

unique_ptr<int> will contain value of type int*. What if we want to store a resource using unique_ptr that is not a pointer but some handle or identifier, so this automatically added * is undesirable? It turns out that the type of stored value can be changed by defining "pointer" type inside deleter.

struct CloseHandleDeleter {
    typedef HANDLE pointer;
    void operator()(HANDLE handle) const { CloseHandle(handle); }
};

std::unique_ptr<HANDLE, CloseHandleDeleter> file(CreateFile(
    "Readme.txt", GENERIC_READ, FILE_SHARE_READ, NULL,
    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
// The first template parameter of unique_ptr seem to not have any menaing in this case.

Comments (1) | Tags: c++ visual studio

23:29
Fri
13
Apr 2012

Demoscene: Revision 2012 and Moleman 2

Last weekend - during Easter - there was a big demoscene party in Germany called Revision, the successor of Breakpoint. HD live videostream was available during the event and now all productions can be downloaded from Pouet.net (
also via FTP). Geeks3d.com summarizes most interesting prods and links to YouTube videos, but of course it's better to download and watch these amazing demos and intros in the highest quality, running on your machine.

Another interesting news related to demoscene is Moleman 2 - The Art of the Algorithms - a 1.5 h long documentary movie about demoscene, now available to download for free in HD and even Full HD quality. I really recommend this movie. I think it's very professional and perfectly explains what the demoscene is all about. Plus the interviews are interlaced with nice visuals and music from demos :)

Comments (0) | Tags: demoscene events

23:14
Tue
03
Apr 2012

IGK-9'2012 - Photo Gallery

Here are my photos from the IGK-9'2012 conference:

Main Gallery
Games from Compo
Slides about Sphere Tracing

Comments (0) | Tags: igk events warsztat gallery

21:23
Mon
02
Apr 2012

IGK-9'2012 - PrisonEscape Game

Our team (called Rosyjscy wieśniacy - from Russian peasants multiplication algorithm) - that is Krzysztof Kluczek "Krzysiek K.", Karol Kuczmarski "Xion" and me - scored 1st place in the gamedev compo at IGK-9'2012 conference! Thanks for all your votes, I'm glad you like our game. The theme this year was "Escape", so we decided to make an oldschool looking 2D game with pixel art, where a prisoner tries to escape, runs through constantly scrolling map, avoids policemen etc. It is coded in C++ using Direct3D 9. Here you can download binaries:

IGK2012_PrisonEscape.zip (5.83 MB)

Comments (2) | Tags: igk events warsztat competitions productions games

Older entries >

STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2012 Adam Sawicki
Copyright © 2004-2012 Adam Sawicki