Please note that i am NOT trying to render to an image. What i am after is a DEPTH BUFFER IMAGE
THE EXAMPLE DOESN'T CRASH BUT IT DOESN'T WORK EITHER. IT PRODUCES TWO COMPLETELY BLACK IMAGES
If i run the following code i just get two black images.
Hit the tab key to try render a depth buffer
If i use the code recommended in the documentation and change the line to
SetRenderToImage(rd, -1) i get the attached error
// Project: DedpthRender
// Created: 2017-07-04
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "DedpthRender" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 12, 0 ) // 30fps instead of 60 to save battery
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
box1 = CreateObjectBox(20,20,20)
SetObjectColor(box1, 0xff, 0, 0, 0xff)
SetObjectPosition(box1, 0, 10, 0)
plane1 = CreateObjectPlane(50,50)
SetObjectColor(plane1, 0, 128, 0, 0xff)
RotateObjectLocalX(plane1, 90)
SetCameraPosition( 1, 0, 100, -20 )
SetCameraLookAt( 1, 0.0, 0.0, 0.0, 0.0 )
mode as integer
state = 0
laststate = state
ri = CreateRenderImage(GetDeviceWidth(), GetDeviceHeight(), 0, 0)
rd = CreateRenderImage(GetDeviceWidth(), GetDeviceHeight(), 1, 0)
si = CreateSprite(ri)
SetSpriteScale(si, 0.2, 0.2)
SetSpritePosition(si, 1, 1)
sd = CreateSprite(rd)
SetSpriteScale(sd, 0.2, 0.2)
SetSpritePosition(sd, GetDeviceWidth() - GetSpriteWidth(rd), 1)
global blank as integer
blank = 0
//drawbox(
do
if blank = 0
print("It's blank")
else
print("It's NOT blank!!!")
endif
Print( str(ScreenFPS()) )
drawbox(0, 0, GetSpriteWidth(si) + 1, GetSpriteHeight(si) + 1, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0)
drawbox(GetDeviceWidth() - (GetSpriteWidth(sd) + 1), 0, GetDeviceWidth(), GetSpriteHeight(sd) + 1, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0)
state = GetRawKeyState(9)
if laststate <> state and state = 1
print("Render")
SetRenderToImage(ri, rd)
ClearScreen()
Render3d()
SetRenderToScreen()
alphachannel(rd)
endif
laststate = state
Sync()
loop
function alphachannel(rd)
mb = CreateMemblockFromImage(rd)
size = GetMemblockSize(mb)
for c = 12 to size - 1 step 4
if GetMemblockInt(mb, c) <> 0
blank = 1
endif
next c
DeleteMemblock(mb)
endfunction