如何在OpenGL纹理中更改单个纹理 [英] How to change single texel in OpenGL texture
本文介绍了如何在OpenGL纹理中更改单个纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改给定位置的OpenGL纹理中的某些纹理像素.有人可以帮我这个忙吗?
I want to change the some texels in a OpenGL texture for a given location. Can anyone help me with this pls ?
这是我想要的功能,
void ChangeTexelColor(int x, int y, GLuint id, int texW, int texH, GLenum format)
{
//What is here ?
}
这将用于维护我的游戏的小地图(如果有人对维护动态map-texture-有更好的主意).顺便说一句,这必须做得很快.谢谢.
This will use to maintain the minimap of my game (if anyone have a better idea of maintaining a dynamic map-texture-). Btw, this must done fast. Thanks.
推荐答案
OpenGL具有glTexSubImage2D
功能,正是您想要的功能.
OpenGL has the glTexSubImage2D
function, which is exactly for your purpose.
这是一个可更改一个纹理像素颜色的函数:
Here's a functions that changes 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);
}
这篇关于如何在OpenGL纹理中更改单个纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文