- Online Community Forums » Programming Questions » How implemennt multipes viewports

This thread is locked; no one can reply to it. rss feed Print
How implemennt multipes viewports
Member #16,693
June 2017

Hello, I'm trying to implement a 2D camera with viewport resize capability. The idea is being able to resize the level render, to specific size (smaller than display) to allow ui elements. What is the best aproach? render the entire level to a bitmap and scale this bitmap?


Eric Johnson
Member #14,841
January 2013

Have you looked into using transformations (ALLEGRO_TRANSFORM)? You could scale ("resize") the display and translate ("move") it around wherever you want on the screen.

Chris Katko
Member #1,881
January 2002

I've never used transforms for that... unless you really want scaling or something. But just re-adjusting the size of the viewport is as simple as keeping track of it.


1. Make a sub-bitmap the size of the viewport, draw to it, and then draw the "viewport bitmap" to the screen.

2. Change the clipping rectangle for the screen, draw your viewport graphics, and then change the clipping rectangle back to normal.

All my viewports (I don't do scaling) are simply x, y, w, h, x_offset, y_offset.

x,y - position on the SCREEN
w,h - width/height
x_offset,y_offset - offset into the world in map coordinates.

“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: