Is there any way to get drawed pixel color (from backbuffer, not current drawing pixel)?
For example:
I'm drawing a rectangle with texture and then drawing a circle (in blue color) on this rectangle. If I use pixel shader on a circle, is there any way to get current pixel color from backbuffer (pixel from rectangle)?
I think you want to get the color of the pixel from the frame buffer for that use glReadPixels() which will return the pixel data from the frame buffer.
https://www.opengl.org/sdk/docs/man2/xhtml/glReadPixels.xml
Related
My goal is to make simple sand simulation using c++ and OpenGL. Right now my plan is to have a 2d array of pixel colors and a texture the same size. To simulate sand I will update the array accordingly to the sand coordinates and where it has to travel. I'm thinking of sending the 2d array of pixels to the fragment shader and update the texture there with colors on the array. The problem is that I can't find a way to change the pixel color on the texture.
So how do I change the color of the pixel at certain coordinates on texture?
Is doing this even practical? If, no what are the other ways?
Did u mean for texture coordinates? You can change only fragment color output. You have also the texture color but you can use only for frgament output.
gl_FragColor = tex + vec4(0.5, 0, 0, 1)*tex.a;
for blending operation
Anyway here's more info about the frag https://www.khronos.org/opengl/wiki/Fragment_Shader#Other_outputs
Is there a pre-maid unity shader so that my camera will render different alpha values depending on the color of what it sees?
For example, If i had a Gray square with a black square inside, the camera would render into the texture the current texture color with a 50% alpha on where the gray square is, + the current texture color with a 100% alpha where the black one is?
If there isn't one already made at least i'd like to confirm this is the correct approach so that i can try making the shader myself.
Thanks
So in openGL when I call glClearColor() is there a way to set the background color to a texture instead of setting it just to a static color? Or is there another method which can do that besides glClearColor()?
You cannot clear the screen to a texture. You can:
Draw a textured quad the size of the screen.
Blit a texture from an FBO onto the screen.
Either one will work.
Please have a look at this image.
I'd like to show an clipped detail of the texture while the clipping rect can be animated so I cannot crop the image upfront. The position of the image is animated too.
I'd like to show it in front of a background. The background is a color or a texture itself.
I'd like to blend both the image and the background combined with opacity
< 1.0 to the destination.
The real requirement here is to render it in one step, avoiding a temporary buffer. Obviously a (simple) shader is needed for that.
What I already tried to achieve this:
Rendering the background first and then the image each with opacity < 1. The problem here: It lets the background shine through the image. The background is not allowed to be visible where the image itself is opaque.
It works when rendering both into a temporary buffer using opacity = 1 and then rendering this buffer to destination with opacity < 1, but this needs more (too much) resources.
I can combine two textures (background, image) in a shader, transform the texture coordinates each with a different transformation matrices. The probleme here is, that I'm not able to clip the image. The rendered geometry is a simple rectangle consisting of two triangles.
Can anybody hint me in the right direction?
You're basically trying to render this.
(Image blended with background) blended with destination
The part in parentheses, you can do with a shader, the blending with destination, you have to do with glBlendFunc, since the destination isn't available in the pixel shader.
It sounds like you know how to clip the image in the shader and rotate it by animating texture coordinates.
Let's call your image with the childreb on it ImageA, and the grey square ImageB
You want your shader to produce this at each pixel:
outputColor.rgb = ImageA.rgb * ImageA.a + ImageB.rgb * (1.0 - ImageA.a);
This blends your two images exactly as you want. Now set the alpha output from your pixel shader to be your desired alpha (<1.0)
outputColor.a = <some alpha value>
Then, when you render your quad with your shader, set the blend function as follows.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
<draw quad>
so I have a problem with the alpha value in my texture. Basically the pixmap is set all black then I drew a filled circle with the alpha value set to 0 in order for the area of the circle it to be transparent (yes I set blending to none), then I created the texture out of the pixmap like this:
Texture myTexture = new Pixmap(TransparentCirclePixmap); // this constructor takes a pixmap
if I draw this texture the circle is not transparent it has a color that is not the background in my game.
so basically what i want is to draw a transparent circle in my pixmap and create a texture from that pixmap and when I draw the texture to the screen the interior of the circle displays whatever was in the background of my game.