java - (OpenGL) Clamping large content to smaller area -
i'm using opengl wigh lwjgl in java, that's not important here. i'm not asking code, hint on how this. language independent.
i have region (a rectangle simplicity), and, let's say, big tiled map want show in area. area not whole screen, want render around it.
i know few approaches, either huge pain or unsuitable.
- render whole tiled map , else, including background , frame, on top - leaving window. yes, works, it'd pain.
- render visible tiles , visible portions of border tiles. again, doable hard, , ie. when use external font drawing library, can't tell "hey, stop @ line, there's border." not approach, i'd say.
- some opengl magic i'm not aware of.
guide me.
when area guaranteed axis-aligned rectangle, can use glviewport
and/or glscissor
(the latter glenable(gl_scissor_test)
) prevent opengl rendering outside rectangle.
in case of modifying viewport, image resulting scaled fit viewport rectangle. using scissor test, area "cut out", not scaled respect viewport setting. differences not matter -you can same result via both paths adjusting transformations accordingly. note that, if need call glclear
when render "tiled map", clear operation not limited set viewport, scissor test allow limit clearing.
if you're area can not described axis-aligned rectangle, i'll recommend having @ stencil buffer. algorithm simple:
- clear stencil buffer 0.
- just render shape want tiled map appear _only stencil buffer.
- when rendering tiled map, enable stencil test , set discard fragments pixels stencil buffer 0.
steps 1 , 2 have done once (as long area not changing, or windo size). have @ glstencilfunc
, glstencilop
functions details of how that.
Comments
Post a Comment