views:

393

answers:

1

Hi there!

Is there a way to create a glass cup with OpenGL ES/OpenGl? And if it's possible, what can i read to start creating? Need to get the most realistic view of a glass, for example -

see glass cup image

For simplicity, without handles.

Maybe, anybody has example with sources?

Thanks.

+2  A: 

Getting something that looks very close to the image you linked would be very complicated (the handle is not the hard part). If this is a learning project, I would suggest starting smaller. Rougher approximations would be a better starting place.

You can make a semi-transparent object easily in OpenGL ES. The OpenGL feature you want is Alpha Blending. This won't get you very close to your glass though. http://www.opengl.org/resources/faq/technical/transparency.htm

A basic level of replicating this object would be to use a hand-drawn grayish texture that looks sort of like the interior refractions and draw it on a camera-oriented sprite with partial transparency. Then render a regular cup-shaped model with high transparency with only a small amount of ambient and diffuse lighting and a lot of specular lighting to make it look shiny.

The multi-bounce refraction effect of a rounded glass object is much more difficult. Especially if you want it to look convincing when something other than a blank background is behind the cup. It's fairly straightforward to do in a raytracer, but not in a rasterizer like OpenGL. Look up Caustics. There are methods to approximate this effect but they are not beginner projects. According to this there are some examples in GLUT if you're serious about it. http://www.opengl.org/resources/faq/technical/lights.htm

Alan
If you have access to shaders, that'll make both the lighting and reflections/refractions a whole lot easier. I'm not sure about OpenGL ES shader support, but standard OpenGL has good shader support and a relatively simple shader will allow you to do the dark edges, translucency, etc.
peachykeen