Skip to content

Instantly share code, notes, and snippets.

@totegamma
Created February 20, 2018 04:35
Show Gist options
  • Save totegamma/2e46106fb73f90d7d9628fe36c08eaef to your computer and use it in GitHub Desktop.
Save totegamma/2e46106fb73f90d7d9628fe36c08eaef to your computer and use it in GitHub Desktop.
simple tile texture
uint8_t mytex[3*256*256];
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
bool flagA = (i % 32) < 16;
bool flagB = (j % 32) < 16;
if (flagA ^ flagB) {
mytex[3*(i+256*j)+0] = 32;
mytex[3*(i+256*j)+1] = 33;
mytex[3*(i+256*j)+2] = 34;
} else {
mytex[3*(i+256*j)+0] = 230;
mytex[3*(i+256*j)+1] = 169;
mytex[3*(i+256*j)+2] = 58;
}
}
}
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, mytex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment