Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL texture to erase
    primarykey
    data
    text
    <p>I am using OpenGl ES 1.1 on the iOS to create a draw/paint program. I am new to openGL but with all the information about I have managed to use a semi-trasnparent png texture to use as brush and draw anti-alise lines. </p> <pre><code>glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glColor4f( 0.5, 0, 0, 0.5 ); </code></pre> <p>Also using the glColor I have managed to control the colour of the brush and it opacity. </p> <p>Now I am trying to use the texture to erase part of the drawing, and also to be able to use opacity when erasing so that I get a translucent erase and not everything is cleared. </p> <p>I have tried a few blend functions with very little success. For example I used the blend settings:</p> <pre><code> glBlendFunc( GL_ONE, GL_ZERO ); </code></pre> <p>and what I got was the area of the texture that did have content was erased and the the area of the texture where it was totally transparent it turned out black, and the opacity of the texture was ignored. </p> <p>Could anybody give me anyhints as how I can partly erase with opacity and soft edges.</p> <h3>Update:</h3> <p>To be able to explore this problem further, I created an ipad app where we have a texture/image background and on top of that I have placed a grid of brush texture which is a white circle with faded edges. Clicking on the textures will open a popup that allows you to set the colour to the texture as well as the OpenGL Source and Destination blends. I can change the settings to be able draw over the background with different colours with the expected effect. However I can not seem to be able to set a setting that will allow me for the texture to erase the background. Most of the drawing code is done is class GLElement in "renderWithTexture". Here is the code:</p> <pre><code>-( void ) renderWithTexture { glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(blendSource_m, blendDest_m); [ self setPremultipliedColour ]; static const GLfloat texCoords[] = { 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0 }; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, sizeof(Vertex), vertices_m ); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } </code></pre> <p>in this code blendSource_m and blendDest_m are two variables stored in the class and can be set through the popup. Please download the project and please let me know how to get it working so that I can erase with a texture. Hopefully this little project would help others in the future as it can be very useful to see how blending in OpenGL can effect the drawing environment.</p> <h3>Resolved:</h3> <p>I managed to solve the problem by first setting the isOpaque property of the GLView to NO, and setting the glClearColor for GL settings to a clear colour. I added a background colour to the main view to be able to see when an areas are erased. As you can see from the example the 2 items at the end of the first row, one is totally erase and the other is partially erased. </p> <p><a href="http://www.ud-ltd.com/dev/BlendTest.zip" rel="nofollow">ipad test project</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload