PDA

View Full Version : Layers



ramana
10-14-2003, 10:43 PM
In Adobe PhotoShop the images are stored in the independent layers. Is it possible to do this thing in OpenGL? If yes, which technology we will use to create layers.

yaro_dup1
10-15-2003, 06:24 AM
Could you post more details about what do you want to do?

nexusone
10-15-2003, 11:33 AM
You can create layers using textured quads and blending.

Image 1 on a quad at -1 Z forground
Image 2 on a quad at 0 Z mid
Image 3 on a quad at +1 Z
background

And use like tha alpha channel as a mask to create transparent or simi-transparent areas on the diffrent layers.



Originally posted by ramana:
In Adobe PhotoShop the images are stored in the independent layers. Is it possible to do this thing in OpenGL? If yes, which technology we will use to create layers.

mithun_daa
10-15-2003, 01:57 PM
i am currently workin on developing layers, but the layers in my case are abstract. its just a class that adds any shape to it and maintains all the shapes on a layer. the layers i have are not physical n cannot be viewed. but the shapes on the layers are physical.i dont know if this is what u were lookin 4.


Originally posted by ramana:
In Adobe PhotoShop the images are stored in the independent layers. Is it possible to do this thing in OpenGL? If yes, which technology we will use to create layers.

dorbie
10-15-2003, 02:39 PM
Layers are easy in OpenGL, you just draw the layers in order and use various blend options and alpha to render them.

I have done this using independent alpha textures and destination alpha to generate the mask, but you don't even need this.

You could do a lot of the things Photoshop layers can do very easily in hardware using OpenGL.

Draw your background image then:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

Then draw your Layers, you'll see them accumulating. This would be the equivalent of a "Linear Dodge" layer mode.

Next you can change the glBlendFunc parameters, you have lots of choice, this would be the equivalent of changing the layer mode.

For something like a "Linear Burn" layer mode you'd use glBlendFunc(GL_ZERO, GL_SRC_COLOR);

For a "Normal" layer mode you'd use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); but to use this properly you need alpha information (to simulate image alpha or mask), so you would use vertex alpha or texture alpha to make this mode useful.

Or you could draw the mask invisibly to the framebuffer alpha first allowing you to store it independently (and paint it independently) and change your blend function to glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);

Try this and you'll see how simple this is. You should be able to drag layers around by moving their quads all with 100% hardware acceleration of the blends.

So in pseudocode:





Draw_Background_Image()

for (Each_Layer)
{

if( Destination_Alpha_Required_By_This_Layer_Mode )
{

Clear_Destination_Alpha()

Draw_Destination_Alpha_Mask()
}

Set_Layer_Mode_With_glBlendFunc()

Enable_Blending()

Draw_Layer()

Disable_Blending()

}


See REALLY simple stuff, couldn't be easier. All you've gotta do is draw your images, prefferably as textures on quads for fast manipulation and to enable cool effects later.

To use destination alphe you need to ensure you request alpha visual attributes when creating the OpenGL context.

[This message has been edited by dorbie (edited 10-15-2003).]

dorbie
10-15-2003, 02:59 PM
P.S. Best not to use z values between layers as this may cause problems. A z buffer is fundamentally incompatible with blending so it can serve no useful purpose beyond confusing you with tricky problems and projection may make registration between layers more difficult than it needs to be if you offset them in Z. You may still want to use 3D and the zbuffer for page curl effects etc, but the motivation is quite different and you still may not want to use depth to order the layers. Use the rendering order to resolve layer ordering, drawing the top layers last, at least initially.


[This message has been edited by dorbie (edited 10-15-2003).]