OpenGL has a glTexSubImage2D function that exactly matches your purpose.
Here are the functions that change the color of one texel:
void changeTexelColor(GLuint id, GLint x, GLint y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { uint8_t data[4]; data[0] = r; data[1] = g; data[2] = b; data[3] = a; glBindTexture(GL_TEXTURE_2D, id); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data); }
Nikolai Ruhe
source share