TEXTURE HELP

how can i have a texture in the background and discover it when i draw a polygon??
i should see a portion of the texture, for example if i draw a polygon i should see just an arm of the entire texture and so on… help me pls!

Here’s one simple way.

  • Request a double buffered pixelformat with stencil buffers.
  • Download your image into a texture.
  • Clear Stencil buffer (to zero).
  • Enable stencil test.
    Start:
  • Clear color buffer
  • Draw your polygon into the stencil buffer with value 1.
  • Switch stencil comparison so that only pixels where the stencil buffer has a 1 will render.
  • Render a textured quad with the image.
  • SwapBuffers.
    Goto Start.

Note that the stencil buffer contents stay intact during the loop.
Every further polygon you render will reveal more of your image.
If you resize the window you would need to repaint all buffers. Remember the polygons your have drawn so far for that.

Originally posted by <Guest>:
If you resize the window you would need to repaint all buffers. Remember the polygons your have drawn so far for that.
Not only if window is resized. If part of window is covered by another window, stecil buffer may not be updated because pixel ownership test will fail and fragment may be discarded.

The safe and imho even more simple way is to draw all the polygons in each frame and simply texture them using the corresponding portion of the image either by manually calculating texture coordinates or by using texture matrices and texgen modes to do so.