Opengl-es 1.1 change pixel data on the FBO - opengl-es

Is there a way to get the FBO pixel data and then: greyscale it fast and take back the image to that FBO again?

If you're using the fixed-function pipeline (ES 1.1), you can use glReadPixels to pull pixel data off the GPU so you can process it directly. Then you'd need to create a texture from that result, and render a quad mapped to the new texture. But this is a fairly inefficient way of accomplishing the result.
If you're using shaders (ES 2.0), you can do this on the GPU directly, which is faster. That means doing the greyscaling in a fragment shader in one of a few ways:
If your rendering is simple to begin with, you can add the greyscale math in your normal fragment shader, and perhaps toggle it with a boolean uniform variable.
If you don't want to mess with greyscale in your normal pipeline, you can render normally to an offscreen FBO (texture), and then render the contents of that texture to the screen's FBO using a special greyscale texturing shader that does the math on sampled texels.
Here's the greyscale math if you need it: https://web.archive.org/web/20141230145627/http://bobpowell.net/grayscale.aspx Essentially, plug the RGB values into that formula, and use the resulting luminance value in all your channels.

Related

Improve texture resolution in GLSL fragment shader

Is there a way to icrease, or improve resolution of a texture using GLSL fragment shader processing? Let's say, I have 512x424 px source image, and want to have 1024x848 px as a result, with smooth pixels.
Update.
Under "improvement" I mean enlarging using some sort of resampling algorithm.
Create FBO, attach large destination texture with desired dimensions
Render "full-screen" textured quad with small source texture bound

Copy luminance/alpha texture to texture in GLES

I'm trying to copy a luminance texture to a luminance texture. More specifically, I'm trying to extend a single channel texture in memory with another texture.
My current steps:
create FBO with Luminance format, new width and height.
bind FBO.
render the textures concatenated.
unbind FBO
create Luminance texture the size of FBO
bind FBO with Luminance texture
render FBO's previous texture
unbind FBO
However the GLES 2.0 docs state, that FBO's can't render to luminance textures. How do I work with single byte textures then? Is it possible for me to copy luminance textures on the gpu anyway?
I ended up using RGBA_4444, which is 2 bytes, so an increase of 100%, but still acceptable.

Subrect drawing to texture FBO within OpenGL ES Fragment Shader

I'm trying to draw to a subrect of a texture based FBO, but am having difficulty. The FBO has dimensions of say 500x500 and I am trying to have the fragment shader only redraw say a 20x20 pixel subrect. Modiyfing the full texture works without difficulty.
At first I tried setting glViewport to the needed subrect, but it doesn't look to be that simple. I'm suspecting that the Vertex attributes affecting gl_Position and the varying texture coordinates are involved, but I can't figure out how.
Turns out that I was trying to modify the texture coordinate attributes, but was more easily able to just modify the viewport using glViewport and gl_FlagCoord within the shader.

OpenGL ES: altering alpha of render without glColor?

I have a few VBOs with color data, and I wish to draw them with varying transparency.
However, I realise that to do this normally, I'd have to either change the alpha value on the color array, or to use a shader, but I'm on OpenGL ES 1.1 so that's no go..
Is there any other way to change transparency of objects as a whole, without having to go glColor?

OpenGL ES set Texture matrix for different Texturing units

with
glMatrixMode(GL_TEXTURE);
..some matrix operations...
i can change the current texture transformation matrix. However - it seems it affects not all texture units (i'm using multitexturing)
how can i change the texture matrix for different texture units?
thanks!
Try using glActiveTexture to select the appropriate texture matrix stack. This works for OpenGL, and I assume that it should also work for OpenGL ES.

Resources