Thanks a bunch everybody for answering!
Blendman wrote: "Clever code with raycasting."
This works beautiful. Only thing I can imagine is the fact that panning or zooming will still use the whole window. I would never have thought about raycasting.
Bengismo wrote: "1) You can render your 3D view to an image (SetRenderToImage()) then place a sprite which fills just your view area which uses your rendered image. Then the 3D view is correctly centered in the view area. "
Clever, I tried it, but my sprite is always empty, I'm now just getting the screen, an putting it on the same place, so it should show the sphere, but it doesn't. Commenting the sprite just shows a sphere as expected.
Also, if this would work, how would you scale the sprite appropriately?
I really don't get why the sphere is not showing, I'm calling Sync() so it should render, shouldn't it?
SetWindowTitle( "testGUI" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)
CreateRenderImage(1, 1024, 768, 0, 0)
SetRenderToImage(1, 0)
CreateObjectSphere(2,20,20,20)
SetObjectPosition(2, 0, 0, 0)
Sync()
SetRenderToScreen()
CreateSprite(1, 1)
spriteX As Float = 0
spriteY As Float = 0
SetSpriteX(1, spriteX)
setSpriteY(1, spriteY)
SetSpriteImage(1,1)
// **** GUI
// left
w = 200
CreateSprite(2,0)
SetSpriteSize(2,w,GetVirtualHeight())
SetSpriteColor(2,70,70,70,255)
// Top
h = 200
CreateSprite(3,0)
SetSpriteSize(3,GetVirtualWidth() - w, h)
SetSpritePosition(3,w, 0)
SetSpriteColor(3,50,50,50,255)
do
Print( ScreenFPS() )
Sync()
loop
Bengismo wrote: "2) Alternatively you can use SetCameraOffCenter( 1, 1 ) and SetCameraBounds( cameraID, left, right, top, bottom ) to render your 3D view only to the view area on the screen."
This sounds like exactly what I need, but how does it work? I now have this:
// Project: testGUI
// Created: 2018-04-16
SetWindowTitle( "testGUI" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default font
SetCameraOffCenter( 1, 1 )
SetCameraBounds( 1, 200, GetScreenBoundsLeft() - 200, 200, GetScreenBoundsRight() - 100 )
// **** GUI
// left
w = 200
CreateSprite(1,0)
SetSpriteSize(1,w,GetVirtualHeight())
SetSpriteColor(1,70,70,70,255)
// Top
h = 200
CreateSprite(2,0)
SetSpriteSize(2,GetVirtualWidth() - w, h)
SetSpritePosition(2,w, 0)
SetSpriteColor(2,50,50,50,255)
CreateObjectSphere(2,5,20,20)
SetObjectPosition(2, 0, 0, 0)
do
Print( ScreenFPS() )
Sync()
loop
This code doesn't seem to do anything, fiddeling with values doesn't seem to change things!
Thanks for any help guys, you give me so much insights!