http://asawicki.info/ Graphics programming, game programming, C++, games, Windows, Internet and more...
All blog entries, ordered from most recent. Entry count: 982.
Microsoft Visual Studio Community 2013 !!!
Microsoft just released a new edition of Visual Studio that will replace Express. It's called Visual Studio Community 2013 and it's free, while it has all the features of the commercial edition, including support for plugins and many advanced tools. You can download it from Visual Studio Downloads, web installer or DVD ISO. It works with "old" Windows 7 as well. Good move Microsoft! For me it's probably the news of the month :) So far, I installed the IDE and tested on my home project CPU profiling:
...and Graphics Analyzer, which replaces good old PIX:
Experience with Game in Scheme
Last week I talked with a colleague about optimizing performance of his game project. It's written in Scheme (functional programming language, dialect of Lisp), using SDL and OpenGL. The bottleneck was GUI rendering.
When analyzing code, we found that the function for rendering text renders TTF font to a new surface with function
TTF_RenderUTF8_*, then creates another
SDL_Surface to convert format, then creates and fills OpenGL texture with
glTexImage2D. The texture is then used just once for rendering... to another freshly allocated
SDL_Surface, to perform clipping. All this happens for every GUI control, in every frame! Finally the objects are freed by Scheme garbage collector.
He then asked me whether we should find a way not to render the GUI part of the screen every frame, but only when something changes. He also cited the famous and often misused quote of Donald Knuth: "Premature optimization is the root of all evil".
I explained to him that modern GPU-s are able to render millions of triangles every frame and redrawing whole screen every frame is a standard practice. It's resource creation (allocation and filling of surfaces and textures) what should be avoided and not done every frame. If using SDL_ttf for text rendering, a final texture/surface should be prepared once and used to do just rendering in every frame, until the text changes. Additionally, calls like
glDisable(GL_DEPTH_TEST) also don't have to be made for every object in every frame.
When thinking about it now, the general rule of game optimization could be:
About functional programming and stuff like that, I think such high level concepts are good for software development as long as they are accompanied with understanding of what's under the hood. Some principles of functional programming, like avoiding side effects and just transforming one list of items to the other, are similar to the idea of DOD (Data-Oriented Design), used in game development for efficiency and scalability. But I don't agree that thinking about efficiency should be avoided until necessary or that optimization makes code complex and unreadable. Quite contrary - I believe simple code is both readable and efficient.
As I have little experience with functional programming, for me it was also fascinating to learn basics of Scheme. It's based on simple principles yet it is so powerful. I'm now thinking about how a language like this could be applied everywhere, from program configuration and as a description language, to game scripting and procedural media generation :)
Agile Methods and Real Life
I've received an e-mail recently from a student asking me about what career path to choose. I generally don't feel good as an authority, but when trying to write some reasonable answer, I recalled this diagram - "The Project Paradox":
It basically says that when planning everything in advance, we have to make the most important decisions at the beginning, when we actually know the least about the project. In software development, we may know the final goal, but we usually don't know how exactly the implementation will look like and what problems will we encounter during the project (unless w already done something similar in the past). That's why agile software development methods were invented.
I think something similar happens in real life. What is more, we don't make the most important decisions like about job and marriage only by ourselves (it also depends on the decisions of others) and we don't do it by only rationally weighting pros and cons - we also follow our hearts. So instead of thinking all the time about the big, lifetime goals, it's better (it feels better and is more efficient) to just focus on the next step to do. That's also what GTD (Getting Things Done) method advices.
So in this case, I'd recommend not to consider theoretically what career path is better, more interesting, more profitable etc., but just try to do different things (like learn a bit and code some simple game, mobile app, web page, setup Linux server or whatever) and see how it feels for you to do these things.
PGA + ZTG 2014 - Photos
Last weekend I've been in Poznań on PGA - Poznań Game Arena (gaming expo) and ZTG - Zjazd Twórców Gier (gamedev conference, happening in same time and place). Here are my photos from these events: PGA i ZTG 2014
Writing OFX Video Processing Plugin
Computer graphics is a broad topic and GPU-accelerated real-time 3D rendering is just one of its parts. Another one is photo and video processing. Video editing is an art by itself, but from the technical point of view there are various interesting effects that can be applied. While not essentially real-time and often done on CPU, of course it could also be GPU-accelerated and also should be as efficient as possible. There are many video editing programs, from Windows Movie Maker to Adobe Premiere. The one of my choice is Sony Vegas Pro. Such programs come with a bundle of standard effects, but for a graphics programmer what can be more fun than writing own plugin?
Vegas Pro supports plugins in OpenFX (OFX) standard. They are written as native code compiled to DLL library with appropriate interface. I'm learning how to write such plugins. Below is a description of how you can start experimenting with this technology plus my "Hello World" example that performs simple color inversion. Maybe later I will write a tutorial with detailed description of this API. For now, here is C++ source code of my example with Visual Studio 2013 project and compiled binaries (Win32 and x64): OfxTest1.zip (21 KB). Inside Vegas Pro it looks like this:
A brief description of how to start coding such plugins:
c:\Program Files\Common Files\OFX\Plugins\Basic.ofx.bundle\Contents\Win64\Test1.ofx.
Note that examples provided on SourceForge next to includes package are broken. When compiled in Visual Studio, they assert in Debug configuration due to usage of uninitialized variables and stack corruption! Patch for these bugs is submitted for over 2 years (#1 Basic in Examples - uninitialised variables) and the author is not fixing it. My example has all of this fixed.
Building 64-bit Executables in Visual Studio Express
I admit that for years I was convinced only the paid version of Visual Studio can compile 64-bit EXE files. It's just because I never really needed to create one in my personal projects. Now I have to do it (what for? - I will show in one of my next posts) and as it turns out, it's perfectly possible and easy to do also in Visual Studio Express. You just have to make some configuration because the "x64" platform is not shown by default. So to compile 64-bit executable in your Visual Studio 2013 Express:
You can now choose and build any configuration (Debug or Release) for any platform (Win32 or x64). For x64 platform, intermediate and output files will be written to subdirectories:
x64\Release\. Notice that for Win32, it's just
DirectX 11 CheatSheet
I've created several cheatsheets: about DXGI Formats, XNA Math, floats, color names in .NET and Direct3D 9. You can see it in Download/Misc. Today I discovered that I didn't publish my DirectX 11 CheatSheet that I've prepared 3 years ago! So here it is:
On 15 pages, you will find:
The End of Lag Magazine
In November 2012 a new paper magazine appeared in Poland called Lag (FB page). I didn't post about it here because I didn't want my little corner of the Internet to carry a negative opinion about this innovative project. But now, after two issues, they announced the end of the project. The editor-in-chief says that it's accounting, packaging, shipping and stuff like that what made it too difficult, so I don't know whether it was a success commercially or many people would share my opinion, but anyway... I think such magazine doesn't make much sense. Here is why:
Lag was an unusual magazine. It was about games, but without any news, game reviews or screenshots. It contained only journalism (plus some illustrations) - essays not even about a particular game, but about games in general and their place in our culture. It felt like being targeted at older, mature readers. Meanwhile, popular stereotype says that games are just for children and teenagers. Some people (and statistics) show something opposite - that they are for everyone. Where is the truth?
I still like games despite being 30, but I like them because I still feel young. I like chasing news, watching trailers and screenshots, sometimes being enthusiastic or even fanatic about some IP and buying a game in the day they release it to the shops. For me it's all part of gaming. All in all, games are entertainment, so it's about emotions and being amused. If I had only such intelectual and analytical approach as the magazine presented, I would rather abandon my interest in games completely.