# Changes on My Website
I've dedicated my free time last week to improving this website. I made it myself from scratch more than 10 years ago, using some old version of PHP, MySQL, and HTML 4.01, so it definitely needed some refresh. I introduced many changes to the code, most notably:
<table>and applying rules of "responsive design". By the way, I also limited maximum width of the page to make it more convenient to read on big screens.
There are still things to do. The website, as well as database, still uses ISO-8859-2 codepage instead of UTF-8 (it was a standard for encoding Polish characters before Unicode became popular). The scripts still generate the page using lots of
print()-s instead of some template system. But maybe I will fix that next time :)
# How to Restrict Access to Apache Server to Local Machine?
I wanted to do some web development locally, so I installed Apache 2.2, PHP, and MySQL on my Windows 10 machine. When configuring it, I wanted to restrict access to the Apache server to two machines only - local one and another one in my local network.
The way to do it is to enable and use mod_authz_host module. In file C:\Apache2\conf\httpd.conf I needed to make sure that following line is not commented:
LoadModule authz_host_module modules/mod_authz_host.so
Then I could add appropriate directives to
<Directory ...> section of this file, or alternatively use them in .htaccess file located next to files of my website.
To deny access from all addresses except my two computers, I started from this:
Deny from all
Allow from 192.168.0.21
Allow from 192.168.0.23
After restarting Apache (needed to apply any changes in configuration), I found out that I could access my website from the other computer, but not from the local one. I quickly recalled that connections to the same machine go through special loopback interface and use special address: localhost, which has IP 127.0.0.1. So I changed my configuration to this:
Deny from all
Allow from 192.168.0.21
Allow from 192.168.0.23
Allow from 127.0.0.1
It didn't work either. That's when I started to search for address where the local connection comes from, using Process Hacker - Network tab, as well as Apache log in file C:\Apache2\logs\access.log. What I found out is that the loopback connection uses IPv6, where address of localhost is: "::1" - however strange it may seem. Explanation of this format can be found here: IPv6 at Wikipedia.
Apache accepts this form of address, so following configuration finally allowed me to connect from my local computer, as well as the other computer from my network:
Deny from all
Allow from 192.168.0.21
Allow from 192.168.0.23
Allow from 127.0.0.1
Allow from ::1
# How to Use Vulkan SDK with AppVeyor and Travis CI?
AppVeyor and Travis CI are popular, free web services that provide continuous integration style build and testing environments for open source projects - for Windows and Linux, respectively. They are relatively easy to setup if your project is self-contained, but can be a little bit tricky if you need to install some additional dependencies. Today I successfully finished installing Vulkan SDK in these environments, to test Vulkan Memory Allocator project. Here is how to do it:
In AppVeyor I have everything configured on their website, so you can’t really see configuration file. To download Vulkan SDK, I used
curl --silent --show-error --output VulkanSDK.exe https://vulkan.lunarg.com/sdk/download/18.104.22.168/windows/VulkanSDK-22.214.171.124-Installer.exe
First command downloads and second one installs Vulkan SDK in silent mode. The SDK is installed to C:\VulkanSDK\126.96.36.199 directory.
Next I added an environmental variable in Environment > Environmental variables section:
In my Visual Studio project settings, I added include directory "$(VULKAN_SDK)/Include" and library directory "$(VULKAN_SDK)/Lib". Then I could successfully
#include <vulkan/vulkan.h> and link with vulkan-1.lib.
For Travis CI you can see my current configuration file as: .travis.yml. What I did here is I added few commands to
install section. First there are some
apt-get commands that install some additional libraries, which I took from Getting Started with the Vulkan SDK page:
sudo apt-get -qq update
sudo apt-get install -y libassimp-dev libglm-dev graphviz libxcb-dri3-0 libxcb-present0 libpciaccess0 cmake libpng-dev libxcb-dri3-dev libx11-dev libx11-xcb-dev libmirclient-dev libwayland-dev libxrandr-dev
Then I download and install Vulkan SDK. URL to real file is in the same format as for Windows. I used
wget command for downloading. The file is a self-extracting archive that unpacks SDK content to following subdirectory of current directory: VulkanSDK/188.8.131.52/x86_64.
wget -O vulkansdk-linux-x86_64-184.108.40.206.run https://vulkan.lunarg.com/sdk/download/220.127.116.11/linux/vulkansdk-linux-x86_64-18.104.22.168.run
chmod ugo+x vulkansdk-linux-x86_64-22.214.171.124.run
Finally I issue a command that sets environmental variable pointing to the SDK, to have it available in the code just like on Windows:
Then I needed to configure my project to search for include files in "$(VULKAN_SDK)/include" and library files in "$(VULKAN_SDK)/lib" (directory names are lowercase this time!). Finally I could
#include <vulkan/vulkan.h> and link with libvulkan.so.
# Stencil Test Explained Using Code
I must admit I never used stencil buffer in my personal code. I know it's there available in GPUs and all graphics APIs for years and it's useful for many things, but somehow I never had a need to use it. Recently I became aware that I don't fully understand it. There are many descriptions of stencil test on the Internet, but none of them definitely answered my questions in the way I would like them to be answered. I thought that a piece of pseudocode would explain it better than words, so here is my explanation of the stencil test.
Let's choose Direct3D 11 as our graphics API. Other APIs have similar sets of parameters. D3D11 offers following configuration parameters for stencil test:
Parameter passed to
How do they work? If you render pixel (x, y) and you have current value of stencil buffer available as:
UINT8 Stencil[x, y]
Then pseudocode for stencil test and write could look like below. First, one of two sets of parameters is selected depending on whether current primitive is front-facing or back-facing:
if(primitive has no front and back face, e.g. points, lines)
StencilOpDesc = FrontFace
if(primitive is front facing)
StencilOpDesc = FrontFace
StencilOpDesc = BackFace
Then, a test is performed:
(StencilRef & StencilReadMask) StencilOpDesc.StencilFunc
(Stencil[x, y] & StencilReadMask)
StencilOpDesc.StencilFunc is a comparison operator that can be one of possible enum values:
ALWAYS. I think this is quite self-explanatory.
StencilRef is on the left side of comparison operator and current stencil buffer value is on the right.
StencilRef and current stencil buffer value are ANDed with
StencilReadMask before comparison.
Next, based on the result of this test, as well as result of depth-test aka Z-test (which is out of scope of this article), an operation is selected:
Op = StencilOpDesc.SencilPassOp
Op = StencilOpDesc.StencilDepthFailOp
Op = StencilOpDesc.StencilFailOp
Op is another enum that controls a new value to be written to stencil buffer. It can be one of:
case D3D11_STENCIL_OP_KEEP: NewValue = Stencil[x, y]
case D3D11_STENCIL_OP_ZERO: NewValue = 0
case D3D11_STENCIL_OP_REPLACE: NewValue = StencilRef
case D3D11_STENCIL_OP_INCR_SAT: NewValue = min(Stencil[x, y] + 1, 0xFF)
case D3D11_STENCIL_OP_DECR_SAT: NewValue = max(Stencil[x, y] - 1, 0)
case D3D11_STENCIL_OP_INVERT: NewValue = ~Stencil[x, y]
case D3D11_STENCIL_OP_INCR: NewValue = Stencil[x, y] + 1 // with 8-bit wrap-around
case D3D11_STENCIL_OP_DECR: NewValue = Stencil[x, y] - 1 // with 8-bit wrap-around
Finally, the new value is written to the stencil buffer. Notice how only those bits are changed that are included in
StencilWriteMask. Others remain unchanged.
Stencil[x, y] =
(Stencil[x, y] & ~StencilWriteMask) |
(NewValue & StencilWriteMask)
Now as we have all this explained in a very strict way using code, let me answer doubts I had before understanding this, in form of a FAQ.
Q: Are there no separate flags to enable stencil test and stencil write?
A: No. There is only one flag
StencilEnable to enable all this functionality.
Q: So how to use only one and not the other?
A: You can find specific set of settings to do that.
To perform only stencil test and not write, set
StencilEnable to true,
StencilFunc to the comparison function you need and set all
KEEP or alternatively set
StencilWriteMask to 0 to disable any modifications to stencil buffer.
To perform only stencil write and not stencil test, set
StencilEnable to true, all
StencilWriteMask to values you need and set
ALWAYS to make the stencil test always passing.
Q: Is the StencilRef value also masked by StencilReadMask?
A: Yes. As you can see in the code, it is also ANDed with
StencilReadMask, just as the previous value from stencil buffer. You don't need to provide it "pre-masked". (Comparison to "premultipled alpha" comes to my mind...)
In other words, we could say that only bits indicated by
StencilReadMask from both sides participate in comparison.
Q: What are stencil value bits replaced to in REPLACE Op mode?
A: They are replaced with
StencilRef value - the same that was used in comparison.
Q: Why is it the same StencilRef value as used for comparison, not separate one?
A: I don't know. There is separate
StencilWriteMask. They could have provided separate "StencilReadRef" and "StencilWriteRef" - but for some reason the didn't :P
Q: What value is incremented/decremented when Op in INCR*, DECR*?
A: It's the original value read from stencil buffer, not masked or shifted in relation to
StencilWriteMask. Which means it doesn't make much sense to use these ops if your
StencilWriteMask looks like e.g. 0xF0 - masks out least significant bits.
Q: Is depth buffer updated when stencil test fails?
A: No. Failing stencil test means that the pixel is discarded, so Z-buffer is not updated and color is not written or blended to render targets.
On the other hand, failing Z-test can cause stencil buffer to be updated when you use
StencilDepthFailOp other than
If I misunderstood something and some of the information in this article is wrong, please let me know by e-mail or comment below.
# Visual C++: IntelliSense Versus Macros
When you code in C++ using Visual Studio, you may meet following problem: Your code uses preprocessor directives that depend on some macro that is defined elsewhere, e.g. in one of CPP files including the header file you write, and so IntelliSense gets lost and stops working, or even completely grays out that part of your code as inactive. For example:
// Some code...
// Some code where IntelliSense stops working...
I just found a solution to that. It turns out there is a special macro predefined when code is processed by Visual Studio IntelliSense. It's called just
__INTELLISENSE__. By using it, you can change parts of your code as seen by IntelliSense parser, e.g. define some macros, without influencing logic seen by the compiler. For example:
// Some code...
// Some more code where IntelliSense is working again...
# Understanding Vulkan objects
An important part of learning the Vulkan® API – just like any other API – is to understand what types of objects are defined in it, what they represent and how they relate to each other. To help with this, we’ve created a diagram that shows all of the Vulkan objects and some of their relationships, especially the order in which you create one from another.
Read more: Understanding Vulkan objects @ GPUOpen
# Few organizational advice for game jams
I have participated in Slavic Game Jam 2017. I would like to share few thoughts that came to my mind during the event and especially during presentations.
Participation in a game jam is like any gamedev project, just on a small scale. All the rules of a successful gamedev project apply. All the rules of doing a software project apply. You need a good idea for a game, so any method of coming up with ideas (like brainstorming) may help. You need the code, so good programming practices apply as well, so you can implement features fast and not drown in spaghetti code or hard to fix bugs in the middle of the project. Experience in game design and level design is useful. Skill in making good game graphics and sound is essential as well. Some project management is needed too. Even the wisdom about work-life balance apply, because having too little sleep makes you less productive the other day (coffee or energy drinks can help a little bit though :)
There are many books about these topics. What I would like to focus on here is something different - some basic organizational things that can have decisive influence on your performance during the jam. Even if you are a great game developer, you won't deliver a good game (or win, if there is a competition) if you fail on some of these basic topics. They are related to both development process, as well as presentation on a big screen.
1. Come prepared. I don't mean making a game in advance and only adjusting it to the theme during the jam. I mean setting up some basic software environment. If you already have your team, or at least some friends who you plan to team up with, meet together before the jam, decide what technologies and tools you are going to use and set them up. This will save you a lot of time during the event.
2. Take as much hardware and cables with you as you can. You never know what you or other team members may need.
3. Finish early. It doesn't mean you need to stop polishing your game long before the deadline. It means you should strive to have a playable game many hours before the deadline, test it as early and as often as possible, and make first build that you could potentially submit at least one hour before the time is up. Maybe you will crunch and apply critical fixes and improvements to your game in the last moment, but your shouldn't count on that. Maybe the organizers will extend deadline by additional hour, but you shouldn't rely on that either. Even something as silly as compressing your game build to a ZIP file on an old laptop can take unexpectedly long time and make you miss the deadline. If you need to upload the game somewhere on the Internet, keep in mind that everyone is going to do this at the same time, so the transfer may be very slow.
4. Focus on making your game looking good during the few-minutes presentation of you playing it. That's how the game will be seen and judged. Making it fun to play for others or fun to play for many hours is a secondary goal. Of course I don't mean cheating like preparing a prerecorded video. I just mean that you don't need to have 20 levels. It's OK to have enough gameplay for just few minutes, like only a single level. It's even better when the game is fast paced and can be finished during the presentation. You may also cheat just a little, like make a keyboard shortcut for invincibility, advancing to next level or showing final credits screen.
5. Make your game easy to remember and recognize. Sophisticated or generic name and content will make people forget about it. Even if there is a list and an order of presenting games, there is often some chaos happening during presentations. Some games have technical difficulties, some teams just give up, and so viewers may be confused about which game is which. If you design your whole game around a single, simple theme (like "a butterfly") and include it everywhere: in game title, logo/menu screen, and in the graphics visible during gameplay, then everyone will be able to easily identify it and so to vote for it. You want them to later say "I liked that game about the butterfly."
6. Give your game build folder/archive some meaningful name. It should contain the title of your game, possibly the name of your team and preferably some ordinal version number. I've seen game builds called "Build.zip". That's a very bad idea. I know that for you this is a build of THE game, but for others it's just one of the games and so they need to be able to easily identify which one is it. (BTW Same rule applies to the file with your resume that you send to potential employers - don't call it "CV.pdf" :) On the other hand, version number is for you. Believe me, there will be more than one version. Calling any of these "final" is not a good idea, because you will end up with "final final", "really final" etc. :) So it's better to call your game build something like "TeamName - GameTitle v01.zip".
7. Prepare your game for difficult technical conditions during presentation. I've written separate blog post about shapes and colors that you should use: 3 Rules to Make You Image Looking Good on a Projector. Here I would like to add that you should test your game on various resolutions. Projectors tend to have small resolutions. You can also meet problems with sound (too quiet or not working at all), so make sure your game is attractive even without it.
8. Use some margin when displaying things on the screen. It is also known as "safe area". In other words, don't put critical information (like GUI elements) near the edges of the screen. It may happen that the projector is not setup correctly and your image will be cropped, making these things invisible. Same applies to time domain as well as to spatial domain: Don't show important content during first three seconds of your game. Leave some "time margin". Projector may need some time to switch to new source and resolution, so viewers may not be able to see the beginning of your game.
9. Control sound volume of your game. If you learned a little bit about giving speeches, you probably know already that you should speak loudly, slowly and clearly. When you present a game, there is another level of difficulty, because the music and sound effects from your game are played at the same time as you speak. Be aware of how loud they are so that viewers can hear them, but also can hear you speaking.
10. Remove all the distractions that your operating system may experience during the presentation. Receiving notification about incoming Skype call in the middle of your presentation would look funny, but it definitely won't increase your chances to win. Same applies to Windows deciding to install new updates in the worst possible moment on antivirus slowing down your system because it just started to scan your entire hard drive. So for the presentation:
11. Finally, prepare for your talk. Decide who is going to talk and who is going to play the game. Consider how long the presentation should be. Determine what do you want to show, what to tell and in what order. Don't do it spontaneuisly, but rather think about the presentation in advance and discuss it with your team.