LWJGL Forum

Programming => OpenGL => Topic started by: manji on July 30, 2009, 15:33:00

Title: how render through holes?
Post by: manji on July 30, 2009, 15:33:00
Let's say I have a single wall, and I want to make a window on it and render the scenery outside. The wallpaper is one texture, multiplied many times, so I can't just make a transparent spot on a texture. Could someone please give me hint?
Title: Re: how render through holes?
Post by: bobjob on July 30, 2009, 23:25:59
yes you could make the wall one texture. This effect is useful for something like a wire fence.

make sure to setup openGL like so:
GL11.glEnable(GL11.GL_BLEND); // Enabled blending
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // selects blending method
GL11.glEnable(GL11.GL_ALPHA_TEST); // allows alpha channels or transperancy
GL11.glAlphaFunc(GL11.GL_GREATER, 0.9f); // sets aplha function

as well as turn depth testing on.
and when you make your texture get rid of the alpha range as much as possible, so that the is 100% transperant, or %0 transperant.


if you want the texture to be semi-transperant, then you will have to draw it after the scene.

Title: Re: how render through holes?
Post by: Ciardhubh on July 31, 2009, 07:19:36
Title: Re: how render through holes?
Post by: manji on July 31, 2009, 10:04:31
Thank you both for you answers. I'll see what I can do.
@Ciardhubh
I have made a model with a hole on it. The problem is how to apply the texture (it's a small texture, repeated as many times needed).
Let's exclude the second option, too diffcult for me.
I have also tried stencil testing and I could't make it. The scenery outside wasn't seen from inside. I should study more for this.
Title: Re: how render through holes?
Post by: Ciardhubh on July 31, 2009, 11:49:06
Quote from: manji on July 31, 2009, 10:04:31
I have made a model with a hole on it. The problem is how to apply the texture (it's a small texture, repeated as many times needed).

For simple models like a wall you could look into texture coordinate generation (glTexGen*(...), http://www.glprogramming.com/red/chapter09.html). This can automatically generate your texture coordinates for you.

It might also be useful to set texture coordinates by hand as a learning exercise and then move to a modelling program (e.g. Blender) to do them for you later on.

Quote from: manji on July 31, 2009, 10:04:31
I have also tried stencil testing and I could't make it. The scenery outside wasn't seen from inside. I should study more for this.

http://www.glprogramming.com/red/chapter10.html