I'm making an Android application to add a line like a header which is like this for example:
(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. 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:
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()
. Say you have an array of bytes rowBytes
, that contains the RGB values for the row of nPixels
pixels you want to add. 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));
Create a new texture for the row, using the standard calls you use for any other texture (glGenTextures
, glBindTexture
, glTexImage2D
). 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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments