Browsed by
Author: slynch@puredevsoftware.com

Sub-Pixel, Gamma Correct Font Rendering

Sub-Pixel, Gamma Correct Font Rendering

Figure 1 – Zoom in of font showing sub-pixel rendering Before I knew anything about sub-pixel font rendering, I used to think that the blue/red edges to the font shown above were a post process effect, adding cool and warm pixels to make the font jump out more. It turns out that it’s much cleverer than that. It’s called sub-pixel rendering, and it really is rendering at a sub-pixel level. Sound impossible? Read on… To understand sub-pixel rendering you need…

Read More Read More

Gamma Encoding

Gamma Encoding

I only occasionally have to think about gamma in my work, and I always have to remind myself exactly what it is and how to get it right. In this article I will explain it in the way that I think about it, mostly as a memory aid for myself, but hopefully others will also find it beneficial. I’m the sort of person who gets confused by small errors in interpretation when topics such as this are discussed. Articles on…

Read More Read More

Adding recursion to a read/write lock

Adding recursion to a read/write lock

Disclaimer: Years of working with custom locks, lock free, and memory consistency models has taught me that low level multi-threading is hard. I make no claims that the code below is safe or the right way to solve the problem. Use these techniques at your own risk. So far this code has passed all of my functional tests and is in active use in my codebase dealing with large databases. But… if I do find a flaw in this code…

Read More Read More

Memory Corruption

Memory Corruption

Today I had a memory overwrite in my code. It can happen to the best of us. I’ve known memory corruptions to take weeks to track down, they are the worst sort of bugs, which can go undetected for a long time and cause all sorts of strange knock on problems. This one took me 5 minutes to find and fix. It’s all about having the right tools. The corruption was caused by some code writing to a deleted pointer,…

Read More Read More

Visual Studio Solution-Wide Defines

Visual Studio Solution-Wide Defines

Sometimes it’s useful to have a define that is set on the solution and applied to all projects in that solution. For example, you might have a define for enabling run-time checks which you don’t normally want enabled in a project, but you do want it enabled when the project is included in a test harness solution. So, assume we have a define called ENABLE_RUNTIME_CHECKS in MyProject which we only want enabled in our project when it is included in…

Read More Read More

Texture Coordinates – D3D vs. OpenGL

Texture Coordinates – D3D vs. OpenGL

I recently had to remind myself how texture coordinates work in D3D and OpenGL. It’s actually pretty simple, but I found a lot of conflicting advice out there. Some people say UV coordinates are handled differently in OpenGL and D3D, some say they are the same. Some say you need to vertically flip your textures when they are loaded. The problem is that the advice often works even if the explanation is incorrect. There are two things to consider: Which…

Read More Read More

Text Encoding

Text Encoding

Many programmers get by without having to worry about text encodings at all. Most of the time text is just a sequence of chars, chars are just numbers that map to letters, numbers and symbols, and to save text to a file you just write out a sequence of chars, or let whatever API you are using handle the encode/decode. Unfortunately it’s not always that simple. It’s not until you start supporting multiple languages, or come across a file in…

Read More Read More

.NET Image DPI Scaling Problems

.NET Image DPI Scaling Problems

Today I noticed that the buttons in my Windows forms app were being scaled. As you can see from the image below there is a ghosting around the edges of the lines which isn’t in the original image. I eventually tracked this down to DPI scaling issues. I’m drawing the image using DrawImage: System.Windows.Forms.Graphics.DrawImage The graphics object has a correct DPI of 96, but the image DPI is 95.91039. This incorrect DPI value is what is causing the scaling. e.Graphics.DpiY =…

Read More Read More