Skip to content

Instantly share code, notes, and snippets.

@acidleaf
Created March 13, 2015 02:48
Show Gist options
  • Save acidleaf/8891702955eeb7705c47 to your computer and use it in GitHub Desktop.
Save acidleaf/8891702955eeb7705c47 to your computer and use it in GitHub Desktop.
Generates a checker texture
uint8_t* checkerTexture(int w, int h, int num) {
const int dataSize = w * h * 3;
uint8_t* texData = new uint8_t[dataSize];
uint8_t c1r = 0x25, c1g = 0x25, c1b = 0x25;
uint8_t c2r = 0x30, c2g = 0x30, c2b = 0x30;
for (int i = 0; i < h; ++i) {
bool odd = true;
if ((i / num) % 2) odd = false;
for (int j = 0; j < w; ++j) {
bool white = true;
if (int(j / num) % 2) white = odd;
else white = !odd;
int index = j * 3 + i * w * 3;
texData[index + 0] = white ? c1r : c2r;
texData[index + 1] = white ? c1g : c2g;
texData[index + 2] = white ? c1b : c2b;
}
}
return texData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment