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:
filling the screen black
drawing the polygon in white
setting the blend function to GL_DST_COLOR, GL_ZERO
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:
drawing the polygon in opaque white
setting the blend function to GL_DST_ALPHA, GL_ZERO
drawing the tiled rectangle opaque
setting the blend function to GL_ONE_MINUS_DST_ALPHA, GL_ZERO
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.
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.