OpenGL ES: altering alpha of render without glColor? - opengl-es

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?

Related

Compositing Transparent Polygons with OpenGL ES 2.0

I have a 2D object that needs to be rendered to the screen as semi-transparent using OpenGL ES 2.0. However, the object is is composed of several overlapping polygons. When I use the blend function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
the result is that the sections of the object where the polygons overlap is distinctly less transparent (which makes sense) For example, if I was rendering an object made of two slightly overlapping circles with alpha = .5, the region of the object where the circles overlap would only be 25% transparent while the non overlapping regions would be 50% transparent. However, my goal is to render the object with uniform color and transparency.
I am aware I can render the object as opaque into an intermediate texture, and then render the texture with the correct transparency to the screen. However, this particular draw call happens frequently with different objects (so I can't cache the result) and the intermediate step would be a significant performance hit. Can this be done without the intermediate step using OpenGL ES 2.0?

OpenGL ES 1.1 - texture and alpha and color key

Using OpenGL ES 1.1.
The picture I am generating is being color-keyed later on down the line. It replaces one color (magenta) with something else.
So I clean the background with that color, draw on top of it, and everything is good.
However, textures with an alpha channel cause some complications. I effectively want to use only maximum or minimum alpha, and show the background OR show the image blended with, say, black.
My mostly-working hack has the texture data manually adjusted force the alpha channel to either min or max, and do pre-multiplication for the actual color value, and this mostly works.
However, when the texture size changes, I get a little bit of filtering and some magenta goes through.
So:
1) Is there some combination of glBlendFunc and glTexEnv combiner functions that will let me stop manually editing the textures?
or, failing that....
2) What parameters should I use when drawing the texture to keep alpha at either 0 or 1 when it's scaling?
Use alpha testing instead of blending. Use glAlphaFunc to select a comparision function and reference value. Enable with glEnable(GL_ALPHA_TEST) (and disable once you no longer need it during rendering).

Opengl-es 1.1 change pixel data on the FBO

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.

Returning values from a OpenGL ES 2.0 shader

Is it possible to get any values out of a OpenGL ES 2.0 shader? I'd like to use the gpu to do some processing (not 3D). The only thing I could think of is to render to the canvas and then to use readPixels to get the colors (preferably in a large 2d array).
Yes, that's called GPGPU. The only way is to draw to a framebuffer or a texture, here is a tutorial that explains it, just stick to the GLSL version.

Repeating only a portion of a texture in OpenGL ES?

I know it's possible to repeat an entire texture by setting the wrap mode to GL_REPEAT, but is it somehow possible to repeat only a subregion of the texture? For example, when the texture is part of an atlas.
I'm targetting OpenGL ES 1.x, so shaders are out.
Unfortunatelly, it is not possible. The only thing you can do it to repeat side pixels (if the image is at the edge of a texture altals).
If you need tiling – probably the only solution here is generate is with geometry. Otherwise, just go with a separate texture.

Resources