简体   繁体   English

如何在OpenGL ES中的纹理上添加一些像素

[英]How to add some pixels on the texture in OpenGL ES

I'm making an Android application to add a line like a header which is like this for example: 我正在制作一个Android应用程序以添加像标题这样的行,例如:

头

(it's a line of some colored pixels, it was kinda zoomed in) (这是一些彩色像素的线,已经放大了)

on top left of this: 在此的左上方:

主要质地

I don't know if it's possible to add some pixels on top of a texture with OpenGL or not. 我不知道是否可以使用OpenGL在纹理上添加一些像素。 Or we must put it in an Bitmap, load it to texture and then combine it with the main texture. 或者我们必须将其放入位图,将其加载到纹理中,然后将其与主纹理组合。

To draw a row of pixels, the best way is to create a texture from them, and then draw them just like any other texture. 要绘制一行像素,最好的方法是从它们创建纹理,然后像其他任何纹理一样绘制它们。 Depending on your exact use case, there are at least two approaches: 根据您的实际用例,至少有两种方法:

  1. If you always want to render that row of pixels over the existing texture, and in the same place relative to the original texture content, you can modify that texture with glTexSubImage2D() . 如果始终要在现有纹理上并且相对于原始纹理内容在同一位置渲染该行像素,则可以使用glTexSubImage2D()修改该纹理。 Say you have an array of bytes rowBytes , that contains the RGB values for the row of nPixels pixels you want to add. 假设您有一个字节数组rowBytes ,其中包含要添加的nPixels像素行的RGB值。 Bind the existing texture, and then call: 绑定现有纹理,然后调用:

     GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, nPixels, 1, GLES20.G_RBB, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(rowBytes)); 
  2. Create a new texture for the row, using the standard calls you use for any other texture ( glGenTextures , glBindTexture , glTexImage2D ). 使用用于任何其他纹理( glGenTexturesglBindTextureglTexImage2D )的标准调用为该行创建一个新纹理。 For just a single row of pixels, specify the height as 1. Then render the texture the same way you already render your existing textures, which is typically by rendering a textured quad for the area you want covered. 对于仅一行像素,将高度指定为1。然后以已经渲染现有纹理的方式渲染纹理,通常是通过为要覆盖的区域渲染一个纹理四边形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM