Created
March 13, 2015 02:48
-
-
Save acidleaf/8891702955eeb7705c47 to your computer and use it in GitHub Desktop.
Generates a checker texture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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