Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Showing the part of the window with the stencil test and window content scrolling


Sometimes you'll need to draw only a part of the window content inside the closed region. In this case, you could have used the scissor test to define the rectangular region. Pixels would be drawn only inside this region. The downside of this approach would be that this region is strictly rectangular and each side of the region would be parallel with the corresponding screen side.

In this recipe, you'll learn how to use stencil test, which provides a more general solution to this problem. Stencil test defines a bit mask with any shape.

Getting ready

Before getting started, make sure you have the stencil buffer available on your graphic card. Nowadays, almost any graphic card allows you to use stencil buffer with at least 8 bits per pixel depth. This will provide enough space to draw 255 masked layers of windows.

Be sure to initialize the stencil buffer before setting up the graphic mode with this code:

SDL.SDL_GL_SetAttribute...