Complicated Problem with canvases and cameras

BlitzMax Modules Forums/MiniB3D/Complicated Problem with canvases and cameras

I'm trying to make a map editor... and I have a main canvas where I show all the stuff... but I also have some canvases for previewing some objects that are going to be placed...
It all works on until I show up the preview canvas... then it starts to draw it but somehow it also draws that convas on the main canvas...
Here is a screen shot

Here are some code that migh me helpful to understand
Function MainWindowCanvasRender()
	SetGraphics CanvasGraphics( MainCanvas)
	SetCanvasGraphics(MainCanvas,ClientWidth(MainCanvas),ClientHeight(MainCanvas),16,0,60)				
	cam.update()
	If Renderer_flat = 1
		UpdateObjects(5)
	Else
		UpdateObjects(4)
	EndIf
					
	CameraClsMode cam.cam,True,True
	Wireframe(False)
	UpdateObjects(1)
					
	HideEntity grid
						
	UpdateWorld()
	RenderWorld()
					

	'Second Pass
	ShowEntity grid
	EntityColor grid , 155 , 155 , 155

	If Renderer_wire = 1
		updateobjects(5)
	Else
		updateobjects(4)
	EndIf
					
	CameraClsMode cam.cam , False , False

	Wireframe(True)
	UpdateObjects(2)

	UpdateWorld()
	RenderWorld()
			
	'Third Pass
	If Renderer_points = 1
		updateobjects(5)
	Else
		updateobjects(4)
	EndIf
						
	CameraClsMode cam.cam,False,False
			
	HideEntity grid

	Points_mode(1)
	UpdateObjects(3)
						
	UpdateWorld()
	RenderWorld()
	updateobjects(5)						
							
	Flip
End Function

Function TexturesWndCanvasRender()
	Local g:Int = 0 
	For Local canvas:Tgadget = EachIn TexturesWnd_CanvasList
				
		Select EventSource()
			Case canvas
				SetGraphics CanvasGraphics(canvas)
				Local obj_tex:Tobject_texture = Tobject_texture(Object_TextureList.ValueAtIndex(g))
				Local scalex:Float = Float(GadgetWidth(canvas))/Float(ImageWidth(obj_tex.img))
				Local scaley:Float = Float(GadgetWidth(canvas))/Float(ImageHeight(obj_tex.img))
				SetScale(scalex,scaley)
				SetColor 255,255,255
				DrawImage obj_tex.img,0,0

				If obj_tex.selected = 1

					SetColor 0,0,255
					SetLineWidth(5)
					SetScale 1,1
					DrawLine(0,0,ImageWidth(obj_tex.img),0)
					DrawLine(0,0,0,ImageHeight(obj_tex.img))
					DrawLine(ImageWidth(obj_tex.img),ImageWidth(obj_tex.img),ImageWidth(obj_tex.img),0)
					DrawLine(ImageWidth(obj_tex.img),ImageWidth(obj_tex.img),0,ImageWidth(obj_tex.img))
				EndIf
						
						
				Flip
						
		EndSelect
		g = g + 1
	Next
End Function

Function EditTreeWndPreviewCanvasRender()
	Cls
	SetCanvasGraphics(EditTreeWnd_PreviewCanvas,ClientWidth(EditTreeWnd_PreviewCanvas),ClientHeight(EditTreeWnd_PreviewCanvas),16,0,60)
	'UpdateObjects(4)
	If CreateTreeWnd_Model <> Null Then ShowEntity CreateTreeWnd_Model
	CameraViewport (EditTreeWnd_Cam.cam,0,0,ClientWidth(EditTreeWnd_PreviewCanvas),ClientHeight(EditTreeWnd_PreviewCanvas))
	UpdateWorld()
	RenderWorld()
	'DebugStop
	'SetGraphics CanvasGraphics(EditTreeWnd_PreviewCanvas)
	
	'DrawText "Press Escape To Exit",0,0
	Flip
	
	
End Function
Function CreateTreeWndPreviewCanvasRender()
	Cls
	SetCanvasGraphics(CreateTreeWnd_PreviewCanvas,ClientWidth(EditTreeWnd_PreviewCanvas),ClientHeight(EditTreeWnd_PreviewCanvas),16,0,60)
	'UpdateObjects(4)
	If CreateTreeWnd_Model <> Null Then ShowEntity CreateTreeWnd_Model
	CameraViewport (CreateTreeWnd_Cam.cam,0,0,ClientWidth(CreateTreeWnd_PreviewCanvas),ClientHeight(EditTreeWnd_PreviewCanvas))
	UpdateWorld()
	RenderWorld()
	'DebugStop
	'SetGraphics CanvasGraphics(EditTreeWnd_PreviewCanvas)
	
	'DrawText "Press Escape To Exit",0,0
	Flip
	
	
End Function
Function SetCanvasGraphics(canvas:Tgadget,width:Int,height:Int,depth:Int,mode:Int,rate:Int)
	SetGraphicsDriver GLMax2DDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
	TGlobal.width=width
	TGlobal.height=height
	TGlobal.depth=depth
	TGlobal.mode=mode
	TGlobal.rate=rate
	SetGraphics CanvasGraphics(canvas)

	TGlobal.GraphicsInit()
	ClearTextureFilters()
End Function



UpdateObjects(5) is for showing some objects and UpdateObjects(4) is for hiding them

(sorry i'm reply to your question :( .... but how you get the "2D line" 3D Grid? with a lot of cameraproject? )

Can you post a example because I don't really know what to do with the functions.

On another note, it might be a good idea to put this in a worklog so we can see your progress.

oh... I made a custom mesh... that has the triangles like a line...
Here is the code
Function CreateGrid:Tmesh(sgx:Int,sgy:Int,sx:Float,sy:Float)
	Local mesh:Tmesh = CreateMesh()
	Local surf:TSurface = mesh.CreateSurface()
	Local i:Int,vcount:Int=-1
	
	
	For i = 0 To sgx
		surf.AddVertex(-sgx*sx/2,0,i-sgy*sy/2)
		surf.AddVertex(sgx-sgx*sx/2,0,i-sgy*sy/2)
		vcount = vcount + 2
		surf.addtriangle(vcount-1,vcount,vcount-1)
	Next
	
	For i = 0 To sgy
		surf.addvertex(i-sgx*sx/2,0,-sgy*sy/2)
		surf.addvertex(i-sgy*sx/2,0,sgy-sgy*sy/2)
		vcount = vcount + 2
		surf.addtriangle(vcount-1,vcount,vcount-1)
	Next
	ScaleEntity mesh,sx,0,sy
	mesh.updatebuffer()
	MoveEntity mesh,1,0,1
	
	Return mesh
End Function


Btw on some systems it doesn't get drawn... or it gets drawn in a weird way...
Maybe Klepto will add one made out of the clasic GlLine or wathever it was.. so that every system will be able to draw the grid

ahh! was on wireframe on!! didn't see the prev code, sorry!
Thanks anyway!

It doesn't meather if its wire or not...

The next version will have 3Dline meshes built in. It is some kind of grid surface. You will add 3d lines to each surface and then all of them are drawn with the brush assigned.

btw: the current extended version already supports canvas graphics. You only have to keep track to reset the Cameraviewport for each camera.

THe thing is that I use Minib3dExt 0.31(or close) cuz the newer one does not work for me... I mean I replaced it in the game.. and it works but when I replace it in the app it doesn't render anymore altough I did modify the renderer like in the example...