The following code demonstrates a simple way to put a 3d camera view onto a blugui panel gadget. The code does show a revolving cube in the camera viewport and the same cube revolving on the panel gadget. I must warn you that the frame rate is exceptionaly bad. I can only achieve 1 fps on my 4 gig intel dual core system with a nvidia geforce 6500 graphics card and 4 gigs system ram. I beleive that this code would work great in a level editor where the 3d view is static or only updated when a change is made to the overall scene.
startBlue "***","******"
SET DISPLAY MODE 800, 600, 32 `Set screen mode
`**************************************************
`* Set up main window *
`**************************************************
set window on
set window size 800, 600
set window title "CAMERA VIEW TO PANEL GADGET TEST"
set window layout 1, 1, 0
set window position 0, 0
resetmainwindow `This command fixes the main window so that gadgets appear properly.
`set sync rate on at the fastest rate the system will allow and set backdrop on.
sync on : sync rate 0: sync
backdrop on
`Convert main window to a gadget window.
window1 = createGadgetFromWindow(mainWindow())
`Get main window client width and height.
window1_client_width = gadgetClientWidth(window1)
window1_client_height = gadgetClientHeight(window1)
`Calculate window 2 width and height so that window 2 is half the area of the main window.
window2_width = window1_client_width / 2
window2_height = window1_client_height
`Create window 2 gadget.
window2 = createWindow(0, 0, window2_width, window2_height, "3D IMAGE TO PANEL GADGET TEST", WINDOW_NORMAL, 0, 0, window1)
`Set window 2's parent as window one since the parent parameter in the create window command seems to be tempermental.
setgadgetparent window2, window1
`Calculate panel 1 gadget width and height.
panel1_width = gadgetClientWidth(window2)
panel2_height = gadgetClientHeight(window2)
`Create panel 1
panel1 =createPanel(0, 0, panel2_width, panel2_height, window2)
`Create Camera.
make camera 1
`Make, Color and Position a box on the screen
MAKE OBJECT BOX 1, 10, 10, 20
color object 1,rgb(255,255,255)
position object 1,0,-50,0
`Create and color a light.
set point light 0,-100,500,0
color light 0,255,255,255
`Disable autocam
autocam off
`Color backdrop black.
color backdrop 1, rgb(0,0,0)
`Position camera 1 and point it at the object.
position camera 1,-200,0,-50
point camera 1,0,-50,0
`Set the camera view to be the right side of window 1 because the window 2 and the panel 1 occupy the left half of window 1.
SET CAMERA VIEW 1, 400, 0, 799, 599
`set variable image1 = 1 for get image command.
image1 = 1
`Start point of main loop.
start:
`Grab the image in the camera viewport.
get IMAGE image1, 400, 0, 799, 599, 1
`Place the image on the panel.
setpanelimage panel1, image1
`Rotate the box by 10 degrees around the y axis.
rotate object 1, 0,wrapvalue(object angle y(1)+10),0
`Use fastest sync possible for updating the screen.
FASTSYNC
`Place frames per second info at top left corner of camera viewport.
text 400, 10, "FPS = " + str$(SCREEN FPS())
`Check for escape key to end program or go back to start.
`IN ORDER FOR THE ESCAPE KEY TO WORK, YOU NEED TO CLICK ON THE MAIN WINDOW FIRST!
a$ = inkey$()
if a$ =chr$(27) then end else goto start
make memblock 1, 0 `This command is necessary for the setpanelimage command. Without it, The viewport image
`will not show up on the panel. AS demonstrated by the program, the memblock can be a 0 byte
`or null memblock. I don't know if that is a bug or not, but it does save some memory from
`being used.
Anybody that wants to use this code for any reason is welcome to do so without any restrictions.
IF anyone can optimize this code to run faster, I would be interested in how it was optimized because, right now I don't have a clue as to speed this up.
I will be using this code myself as part of my world editor, just not in my game engine unless it can be made to run faster.