# Clamping large content to smaller area

I'm using OpenGL (with LWJGL) in Java, but the question is language independent.

I have some region (a rectangle for simplicity), and, let's say, a big tiled map which I want to show in this area. The area is not the whole screen, I want to render something around it.

I can think of two approaches, but they are not very good and hard to do.

• Render the whole tiled map and everything else, including background and the frame, on top - leaving the window. Yes, works, but it'd be pain.
• Render only visible tiles and only the visible portions of the border tiles. This is not possible if I for example render a font using external library - there I don't have such fine control.
• Some OpenGL trick?

You should be able to use glViewport() to limit rendering to a specific portion of the screen. Just keep in mind that you might have to adjust your matrixes as well.

In C++, the call would be as simple as this:

glViewport(left, top, width, height);


You should find a wrapper for this in LWJGL as well.

glScissor() would be another alternative if you don't want to worry about transformations.

you can try drawing with a clipping mask, you could have a rectangle (or even irregular shapes) for the mask that represents that space.

looks like LWJGL has that functionality (https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Masking).

however if you want to make some kind of minimap i think @Mario sugestion is more appropriate.