GLBasic User Manual

Main sections

VIEWPORT

VIEWPORT x%, y%, width%, height%



Sets the viewport used for drawing to a specified rectangle. This command is useful for split screen programs or displaying a rear-view mirror for a car.
The pixel coordinates 0,0 for the viewport will be at screen location at x%, y%.
3D graphics will be scaled as if the viewport was the main window.
Setting width% or height% <=0 will reset the viewport to the full window.
You need to create the viewport before calling X_MAKE3D.

// --------------------------------- //
// Project: Multiple Viewports
// Start: Wednesday, August 11, 2004
// IDE Version: 2.40811

WHILE TRUE
PRINT "Test", 0, 0

MOUSESTATE mx, my, b1, b2
GOSUB Scene // 3D Scene

VIEWPORT mx, my, 150, 100
// Draw more than the viewport's boundaries
DRAWRECT -100, -100, 400, 600, RGB(0, 0, 64)
PRINT "Viewport.....", 0, 0
GETVIEWPORT vx,vy,vw,vh // Returns mx,my,150,100
GOSUB Scene

VIEWPORT 0,0,0,0 // Reset
PRINT "Back to normal", 0, 20
PRINT "Viewport x="+vx+" y="+vy+" width="+vw+" height="+vh,0,40
SHOWSCREEN
WEND

// ------------------------------------------------------------- //
// -=# SCENE #=-
// ------------------------------------------------------------- //
SUB Scene:
X_MAKE3D 1, 100, 45
X_CAMERA 0,0,10, 0,0,0
X_OBJSTART 1
X_OBJADDVERTEX 0, 0, 0, 0,0, RGB(255,255,255)
X_OBJADDVERTEX 1, 1, 0, 1,1, RGB(255,255,255)
X_OBJADDVERTEX 0, 1, 0, 0,1, RGB(255,255,255)
X_OBJEND
X_ROTATION GETTIMERALL()/30, 0, 1, 0
X_DRAWOBJ 1, 0
X_DRAWAXES 0,0,0
ENDSUB // SCENE

See also...