How to change one texel in OpenGL texture

I want to change some texels in the OpenGL texture for a given location. Can someone help me with this pls?

This is the functional function that I want

void ChangeTexelColor(int x, int y, GLuint id, int texW, int texH, GLenum format) { //What is here ? } 

This will be used to support the minimap of my game (if anyone has a better idea of ​​saving a dynamic texture map). By the way, this should be done quickly. Thanks.

+7
opengl textures
source share
2 answers

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); } 
+11
source share

In terms of performance, it might be better for you to save the map locally as your own array and draw it on the screen as a set of non-textured squares.

The rendering of primitives is highly optimized, especially compared to creating or modifying textures.

0
source share

All Articles