Glass

Help with the Ecere 3D Graphics Engine: Camera, Mesh, Object, Material, OpenGL integration, etc.
Post Reply
sacrebleu
Posts: 27
Joined: Sun Jan 17, 2010 12:37 pm

Glass

Post by sacrebleu »

:? How to draw glass? Is this handled by the engine?
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Glass

Post by jerome »

Take a look at this FAQ at openGL.org.
15.040 How can I render glass with OpenGL?
This question is difficult to answer, because what looks like glass to one person might not to another. What follows is a general algorithm to get you started.
First render all opaque objects in your scene. Disable lighting, enable blending, and render your glass geometry with a small alpha value. This should result in a faint rendering of your object in the framebuffer. (Note: You may need to sort your glass geometry, so it's rendered in back to front Z order.)
Now, you need to add the specular highlight. Set your ambient and diffuse material colors to black, and your specular material and light colors to white. Enable lighting. Set glDepthFunc(GL_EQUAL), then render your glass object a second time.
When you set a material to be translucent and call ApplyTranslucency() on a Mesh (as indicated in the thread about materials), primitives are broken up and get rendered from back to front Z order. There is also a Display::DrawTranslucency() method which lets you control when the translucent primitives are drawn, otherwise it is drawn when you reset the camera to 'null' on the display (usually at the end of an OnRedraw() method). You can try using this to draw your glass objects in 2 passes following the OpenGL.org's advice above.

You can use both translucent textures and translucent material color attributes to achieve the glass effect you're looking for. So far not so many nice glass effects have been achieved with Ecere yet, and you're most welcome to share with us your findings or screenshots :).

Here are some screenshots from the 3D samples:
The 'cube2' sample (translucent texture)
The 'cube2' sample (translucent texture)
The 'transCube' sample (50% opacity with opaque textures)
The 'transCube' sample (50% opacity with opaque textures)
A pick-up (3DS model) in the ModelViewer
A pick-up (3DS model) in the ModelViewer
Hoping this inspires you to render some great looking glass :)

Cheers,

Jerome
Post Reply