Texture masking problem

Hey,
I’m currently working on a 2d sideways scrolling game (using orthagonal mode), and I’m having trouble drawing the landscape. What I would like is a polygon rendered at the bottom of the screen and textured, and a sky texture drawn in the background.

I can get the terrain working with no background by:

  1. filling the screen black
  2. drawing the polygon in white
  3. setting the blend function to GL_DST_COLOR, GL_ZERO
  4. drawing a rectangle tiled with the texture over the polygon

This, however leaves me no way of drawing the background.

Another approach I tried was to set the clear color to transparent and then:

  1. drawing the polygon in opaque white
  2. setting the blend function to GL_DST_ALPHA, GL_ZERO
  3. drawing the tiled rectangle opaque
  4. setting the blend function to GL_ONE_MINUS_DST_ALPHA, GL_ZERO
  5. drawing the background

The problem with this method was that it required the framebuffer to have an alpha component, which seemed to make my program run unacceptably slowly.

Is there a better approach to this? I took a look at stencil buffering, but I couldn’t get that to work - and it also had a massive framerate hit.

Hi Jobbernowl

I’m confused, need more info…

Why blend at all?

Why not just draw the sky as one textured polygon, say at z=1, then draw the ground in front of it, say at z= 0.5 (assuming that z increases into the screen)

PS - if there are see through parts in the ground texture, put the alpha in the texture, and use alpha test to “cut out the holes”. No alpha (frame) buffer required…

Cheers for your reply, but I don’t think you understood exactly what I’m doing. The goal is to read in information about the terrain from a file - so clearly I can’t just have a static texture for the landscape.

Hence, I draw a polygon in the shape of the ground in white on a black background, then set the blend mode to GL_DST_COLOR, GL_ZERO and draw the texture as a tiled rectangle over the top, so it only shows up over the polygon.

Obviously drawing the sky before the white polygon won’t work, since then it’ll be blended with the colour values of the background and look crazy.

Never mind, I started thinking laterally and realised I could just draw the sky as a second polygon that filled the remainder of the screen.

Thanks anyway!