Planes, Terrains and texture layers. With HideEntity. Wierd, wierd problem.

Blitz3D Forums/Blitz3D Programming/Planes, Terrains and texture layers. With HideEntity. Wierd, wierd problem.

Sure thing. I'll copy and paste from the relevant areas. Oh, this is a different shadow routine to what I mention in the other thread, in case that causes any confusion!

Okay, this is where the sea plane is created. This is called once:

watersurface%=CreatePlane()
watertex%=LoadTexture("bmp/water1.bmp",8) ;Basic blue sea texture
watertex2%=LoadTexture("bmp/water2.bmp",8) ;This is the first scrolly texture
watertex3%=LoadTexture("bmp/water3.bmp",8) ;This is the second

EntityTexture watersurface,watertex,0,0
EntityTexture watersurface,watertex2,0,1
EntityTexture watersurface,watertex3,0,2

TextureBlend watertex2,3
TextureBlend watertex3,3

ScaleTexture watertex,1500,1500
ScaleTexture watertex2,10000,10000
ScaleTexture watertex3,10000,10000


Then, here's the part where the shadows are made, called every frame:

.assignshadows

terrx#=40960:terry#=40960 ;These don't need to be set every frame, they're just here while I work on the routine!

;Deciding where to scroll the texture to.
acttx#=EntityX(maincam)
actty#=EntityZ(maincam)
placeshadx#=(1/terrx#)*acttx#
placeshady#=1-((1/terry#)*actty#)
placeshadx#=placeshadx#*4
placeshady#=placeshady#*4
placeshadx#=placeshadx#-0.5
placeshady#=placeshady#+0.5
PositionTexture shadowtex,placeshadx#,placeshady#

HideEntity maincam ;Hide the normal camera
ShowEntity shadowcam ;Show the camera for snapping the shadows

;Position the shadowcam above the main camera
PositionEntity shadowcam,EntityX(maincam),EntityY(maincam)+8000,EntityZ(maincam)
RotateEntity shadowcam,90,0,0

;Some of this is commented depending what method I use to get rid of the water. Right now, it's set up to do what's in the screenshot, rotating the water by 90 degrees. Incidentally, the alpha didn't work either.

;HideEntity watersurface
HideEntity groundmesh
RotateEntity watersurface,90,0,0
;RotateEntity groundmesh,90,0,0

;EntityAlpha watersurface,0
;EntityAlpha groundmesh,0

;No illumination for objects, and make background white...
AmbientLight 0,0,0
LightColor sun,0,0,0
CameraClsColor shadowcam,255,255,255
CameraZoom shadowcam,10

;Not really necessary, but I was desperate for anything to fix it...
Cls

;Snap the shadows
RenderWorld

;Copy from the backbuffer direct to the shadow texture
CopyRect 0,0,512,512,0,0,BackBuffer(),TextureBuffer(shadowtex)

;Reset values to what they were before being darkened
AmbientLight ambr%,ambg%,ambb%
LightColor sun,sunr%,sung%,sunb%

;Put the cameras back
HideEntity shadowcam
ShowEntity maincam

;Return visibility settings to normal

;ShowEntity watersurface
ShowEntity groundmesh
RotateEntity watersurface,0,0,0
;RotateEntity groundmesh,0,0,0

Return


Oh, and the code to scroll two layers of texture on the water. Probably not important, but you never know. This is also called every frame:
	If worldtype$="island" Or worldtype$="ocean"
		wx#=wx#+0.02*framedrawtime#
		PositionTexture watertex2,wx#,0
		PositionTexture watertex3,0-wx#,0.5	
	EndIf


I don't think I missed anything relevant, and I hope I've not made a really stupid obvious mistake. I can't see what possible error I could have made that results in a duplicate sea plane being made. But then I've had problems in Blitz before and figured there's a bug in Blitz, until I find the really stupid mistake I've made, so that could well be happening here.

I guess I should really write a seperate short program and see if this occurs there.

-Glenn