Question

I am using OpenGL ES 1.1 to draw lines in my iPad app. I want to make sure that the drawn lines are always visible on the screen regardless of the background colors, and without allowing the user to choose a color. Is there a blend function that will create this effect? So the color of the line drawn will change based on the colors already drawn beneath it and therefore always be visible.

Was it helpful?

Solution

Sadly the final blending of fragments into the framebuffer is still fixed function. Furthermore glLogicOp isn't implemented in ES so you can't do something cheap like XOR drawing.

I think the net effect is that:

  • you want the output colour to be a custom function of the colour already in the frame buffer;
  • but the frame buffer can't be read in a shader (it'd break the pipeline and lead towards concurrency issues).

You're therefore going to have to implement a ping pong pipeline.

You have two off-screen buffers. One represents what you output last frame, the other represents what you output the frame before that.

To generate a new frame you render using the one that represents the frame before as an input. Because it's an input you can sample it wherever you want and make whatever calculations you like on it. You render to the other buffer that you have (ie, the even older one) because you no longer care about its contents.

Then you copy all that to the screen and swap the two over, meaning that what you just drew is still in a texture to refer to as what you drew last frame. What you just referred to becomes your next drawing target because it's something you conveniently already have lying around.

So you'll be immediately interested in rendering to a texture. You'll also need to decide what function you want to use to pick a suitable 'different' colour to the existing background. Maybe just inverting it will do?

OTHER TIPS

I think this could work:

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);

Draw your lines with a white color, and then the result will be rendered as

[1,1,1,1] * ( 1 - [DstR, DstG, DstB, DstA]) + ([DstR, DstG, DstB, DstA] * 0)

This should render a black pixel where the background is white, a white pixel where the background is black, a yellow pixel where the background is blue, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top