restrict viewport and mouse to certain area

Hello,

I want to render both 2D and 3D always to a fixed aspect ratio (16:9), so if the screen for example is 4:3, I want to display a 16:9 image centred on the screen with black bars at the top and bottom. (So the actual screen mode used is 4:3, I just restrict my rendering and perhaps even mouse input to an area within that).

What’s the best way to restrict the viewport so?

I’ve tried:

for region in base.win.getDisplayRegions():
  region.setDimensions(blah...)

Which kinda works, except gibberish is rendered where the black bars should be (obviously that area is not getting cleared to black) and also mouse selection gets screwed up (the mouse behaves as if objects were being rendered in the full area).

I don’t know whether it’s the best solution, but you may be able to achieve what you want by creating and rendering into a secondary, empty display region behind your main display region (or display regions) – that should provide the black bars that you want.

As to the mouse, this manual page might help.

Thanks, the mouse manual page was a great help.

As an example, I’m currently doing:

		for region in base.win.getDisplayRegions():
			region.setDimensions(0,1, 0.1,0.9)
		
		base.mouseWatcherNode.setDisplayRegion( base.win.getDisplayRegion(0) )
		
		dr = base.win.makeDisplayRegion(0,1, 0.9,1) # black bar top
		dr.setClearColorActive(True)
		
		dr = base.win.makeDisplayRegion(0,1, 0,0.1) # black bar bottom
		dr.setClearColorActive(True)

Which seems to work.

I’m curious if it’s documented anywhere what the default display regions are used for? By default there seem to be four regions that take up the entire screen. Are there always gauranteed to be four?

I stand to be corrected by one of the more authoritative members, but I imagine that they belong to render, render2d and perhaps aspect2d and pixel2d – I’m not sure of whether the latter two have display regions of their own, however.

If I recall correctly, in order of back-to-front, there’s one for “render”, one for “render2d” (also containing aspect2d and pixel2d), one for “render2dp” (if “want-render2dp” is enabled, which is it by default), and one that overlays them all for the sake of taking screenshots of the entire window.

All of them except for the latter one are created in direct/src/showbase/ShowBase.py, I believe.

Ok, thanks guys!