This is a small modification of a program I posted earlier in this thread.
I were not able two fix it!
The program uses 2 blitzterrain:
I have problems when the second terrain is rendered using:
BT UpdateTerrainCull g_Terrain2ID
BT UpdateTerrainLOD g_Terrain2ID
All goes well if I don´t use those functions.
This happens independent of the position of the two terrains.
It happens also when I don't render the first terrain.
It does not happen when I don´t build the first terrain.
(once the functions are called the problem is irreversable.
Use y/n to toggle the LOD and cull functions)
Can someone compile this program and tell me what they see on their system
(it uses the media of blitzterrain examples).
If the variable "ter" printed on the display is 2 then the camera is on the second terrain.
Can you post your system specifications (especially if you don´t experience any problems with the code)?
Do I make a mistake setting up the terrains?
Can someone post a demoprogram using two(or more) blitzterrains?
My specifications:
My system DELL
Processor Intel(R) Core(TM) i3 CPU 540 @ 3.07GHz
Memory (RAM) 4.00 GB Graphics NVIDIA GeForce GTX 260
Windows 7 64 bit
dbpro 1.076
blitzterrain commercial version.
//BLITZ TERRAIN 2.00 EXAMPLE - LOD TERRAINS
//CREATED BY KARL HOBLEY (KAEDROHO) http://www.blitzwerks.co.uk
//CODE BELOW MAY BE USED IN COMMERCIAL AND NON COMMERCIAL PROJECTS
//CREATED AND TESTED WITH DBPRO 7.4
//This demo shows how to add LOD to a terrain. I will make the system create 3 LOD Levels and update them.
//LOD is basically, an algorithm to simplify parts of the terrain which are far away. Making draw speeds faster with low visual impact.
//BlitzTerrain reduces the amount of draw calls as well as polygons in distant areas for very high FPS gain.
//In this example, I am using a small terrain. The performance gain with LOD is much higher with bigger terrains.
//I only needed to add 4 extra lines to get LOD working.
//CONTROLS
//ARROWKEYS AND MOUSE - MOVE
// F1 - WIREFRAME ON. F2 - WIREFRAME OFF
//Setup
sync on : sync rate 0 : sync
center text screen width()/2,screen height()/2,"Loading..." : sync : cls
rem set display mode 1920,1080,32
//Load media
global g_HeightmapImgID : global g_TextureImgID : global g_DetailmapImgID
g_HeightmapImgID=1 : g_TextureImgID=2 : g_DetailmapImgID=3
load image "..\Media\heightmap.bmp",g_HeightmapImgID
load image "..\Media\texture.jpg",g_TextureImgID
load image "..\Media\detail.tga",g_DetailmapImgID
//Create terrain
//Make the terrain
global g_TerrainID
g_TerrainID=BT MakeTerrain()
//Set images
BT SetTerrainHeightmap g_TerrainID,g_HeightmapImgID
BT SetTerrainTexture g_TerrainID,g_TextureImgID
BT SetTerrainDetail g_TerrainID,g_DetailmapImgID
//Set some other values
BT SetTerrainScale g_TerrainID,20.0
BT SetTerrainYScale g_TerrainID,2.0
BT SetTerrainSplit g_TerrainID,8
BT SetTerrainDetailTile g_TerrainID,3.0
//LOD
BT SetTerrainLOD g_TerrainID,3 //3 LOD levels
BT SetTerrainLODDistance g_TerrainID,1,1000.0 //LOD Distances start at one and go up to 1 less the LOD level count
BT SetTerrainLODDistance g_TerrainID,2,2000.0
//Build
global g_TerrainObjectID
g_TerrainObjectID=1
//This command processes the heightmap and creates all the internal structures for the terrain
BT BuildTerrain g_TerrainID,g_TerrainObjectID
//This command sets the number of sectors get created every call to 'BT ContinueBuild'.
//As we dont need a loading bar, I set this to 0 which makes it create the whole terrain at once
BT SetBuildStep 0
repeat
//This command generates the sectors. It returns the percentage of how much of the terrain it has generated.
//When it has generated the whole terrain it will return -1
progress=BT ContinueBuild()
until progress=-1
g_Terrain2ID= BT MakeTerrain()
//Set images
BT SetTerrainHeightmap g_Terrain2ID,g_HeightmapImgID
BT SetTerrainTexture g_Terrain2ID,g_TextureImgID
BT SetTerrainDetail g_Terrain2ID,g_DetailmapImgID
//Set some other values
BT SetTerrainScale g_Terrain2ID,20.0
BT SetTerrainYScale g_Terrain2ID,2.0
BT SetTerrainSplit g_Terrain2ID,8
BT SetTerrainDetailTile g_Terrain2ID,3.0
//LOD
BT SetTerrainLOD g_Terrain2ID,3 //3 LOD levels
BT SetTerrainLODDistance g_Terrain2ID,1,1000.0 //LOD Distances start at one and go up to 1 less the LOD level count
BT SetTerrainLODDistance g_Terrain2ID,2,2000.0
//Build
global g_TerrainObject2ID
g_TerrainObject2ID=2
//This command processes the heightmap and creates all the internal structures for the terrain
BT BuildTerrain g_Terrain2ID,g_TerrainObject2ID
//This command sets the number of sectors get created every call to 'BT ContinueBuild'.
//As we dont need a loading bar, I set this to 0 which makes it create the whole terrain at once
BT SetBuildStep 0
repeat
progress=BT ContinueBuild()
until progress=-1
Position object g_TerrainObject2ID,0,0,5120
//Setup camera
set camera range 1,100000
hide mouse
position camera 100,100,5400
//Main loop
StartTime=timer()
ter =g_TerrainID
offset = 0
secull = 1
do
//Camera movement
Elapsedtime#=(timer()-StartTime)/3000.0+Elapsedtime#*0.7
StartTime=timer()
cx#=camera angle x()+mousemovey()/4.0
if cx#>90.0 then cx#=90.0
if cx#<-90.0 then cx#=-90.0
rotate camera cx#,camera angle y()+mousemovex()/4.0,0.0
if upkey() then move camera 1000.0*Elapsedtime#
if downkey() then move camera -1000.0*Elapsedtime#
if camera Position z() > 5120 then ter = g_Terrain2ID else ter = g_TerrainID
if ter = g_TerrainID then offset = 0 else offset = 5120
gheight#=BT GetGroundHeight(ter,camera position x(),camera position z() - offset)
if camera position y()-80<gheight# then position camera camera position x(),gheight#+80,camera position z()
//Wireframe
if keystate(59) then set object wireframe g_TerrainObjectID,1
if keystate(60) then set object wireframe g_TerrainObjectID,0
if inkey$() = "y" and secull= 0
secull = 1
endif
if inkey$() = "n" and secull= 1
secull = 0
endif
//Render the terrain
// the problem is also present if you don´t render the first terrain = comment out following 4 lines
BT SetCurrentCamera 0 //Set current camera to 0 (if the camera has moved/rotated since this command was last called, you must call it again!
if secull = 1
BT UpdateTerrainCull g_Terrain2ID //Update frustum culling
BT UpdateTerrainLOD g_Terrain2ID //Update LOD
endif
BT RenderTerrain g_Terrain2ID //Render the terrain
BT UpdateTerrainCull g_TerrainID //Update frustum culling
BT UpdateTerrainLOD g_TerrainID //Update LOD
BT RenderTerrain g_TerrainID //Render the terrain
rem BT SetCurrentCamera 0 //Set current camera to 0 (if the camera has moved/rotated since this command was last called, you must call it again!)
// !!!!!!! If you comment out following 2 lines the problem dissapears !!!!!!!
//FPS
text 10,10,str$(screen fps())
text 10,20,"ter: "+ str$(ter)
text 10,30,"toggle lod and cull on second terrain y/n: " + str$(secull)
//Position mouse
position mouse screen width()/2,screen height()/2
//Update screen
sync
loop