Wierd texture problems

Blitz3D Forums/Blitz3D Programming/Wierd texture problems

Shifty Geezer(Posted 2005) [#1]
I've an alpha-textured quad mouse pointer, and every once in a while when I start my program the texture is visible targer and over the top of everything else. Only it's not the quad mouse-pointer because that's small and moves as normal. And it seems random whether it appears or not.

I'm using two cameras, a perspective and ortho. And I use 'CameraClsMode(TG_cam\camera,0,1)' for the 2D UI ortho camera if that helps explains things

???

Shifty Geezer
...


jhocking(Posted 2005) [#2]
code and screenshot plz


KuRiX(Posted 2005) [#3]
I have heard that alpha objects do not behave correctly with z-buffer in b3d. That means that there is no order preference for drawing alpha objects...


Stevie G(Posted 2005) [#4]
Yes , alpha ordering is based on distance from the camera so just make sure that you set the entityorder so that it is rendered last.

Stevie


Shifty Geezer(Posted 2005) [#5]
Screenshot here...


Code is basically what I posted in this thread as _lib_ToodeeGooey...
http://www.blitzbasic.com/Community/posts.php?topic=49827#558341

The wierd thing is if it's an EntityOrder issue, what entity is it drawing? There's only one object with that texture applied and that's the small mousepointer. I load the hand texture, apply it to the quad, and move the quad with the mouse. The large blob is static, and only appears rarely and I can't duplicate the problem on demand. This is the only place I reference the texture...
Function TG_SetPointer(img$)
	; FUNCTION : sets pointer image

	TG_pointer\texture= LoadTexture(img$,2)
	TG_pointer\sprite=TG_Create_Sprite(TG_pointer\texture)

	TG_pointer\pos_x=MouseX()
	TG_pointer\pos_y=MouseY()
	TG_pointer\siz_x=TextureWidth(TG_pointer\texture)
	TG_pointer\siz_y=TextureHeight(TG_pointer\texture)	
	PositionEntity TG_pointer\sprite, TG_pointer\pos_x, TG_pointer\pos_y, UI_DISTANCE+200
End Function
called with TG_SetPointer("UI\pointer.png"), and for rendering I use...
Function TG_Draw_UI()
	; Scene_cam is a pointer to the scene camera
	UpdateWorld
	RenderWorld
	
	PositionEntity TG_pointer\sprite,mouse\x,mouse\y,UI_DISTANCE+200
	
	CameraProjMode (Shiftycam\camera,0)
	CameraProjMode (TG_cam\camera,2)
	
	RenderWorld
	
	CameraProjMode (Shiftycam\camera,1)
	CameraProjMode (TG_cam\camera,0)
End Function



Stevie G(Posted 2005) [#6]
Can I suggest that you position the GUI camera far away from the scene as the un-ortho camera seems to be picking up the previous render. Also, you should ensure that the GUI camera is rendered last by setting the entityorder.


jhocking(Posted 2005) [#7]
I second that thinking. Given that you are using separate renders for the scene and the GUI, my first suspicion is that the two are conflicting. Another thing to check; are you hiding the hand for the scene render and only showing it for the GUI render?


Shifty Geezer(Posted 2005) [#8]
Good points. I'm not sure about the hand, with the UI camera drawing over the scene camera if it were the scene cam showing the hand wouldn't it appear under the UI? And why isn't it being cleared away when the scene-cam's buffer is cleared?

BTW The deep blue on the right with the black border is the background to the UI; a textured quad. Also pertinant is the scene-cam is using a viewport up to the edge of this UI graphic, so I'm not clearing the whole frontbuffer area. Could it be that with the viewport the texture is loaded into an overlapping space in the display memory somehow?

Also what's the distance suggested for the ortho camera? At the moent it's at z=-10000. I've been told elsewhere that figures this large can mess up z-ordering and I should use smaller scales!

I'm not sure how the hand can be picked up by the scene camera as it's positioned WELL behind the scene camera (-9980) and is moved there before the first render scene, but I'll try disabling it between updates just in case something weird is going on. Annoyingly I've no way of knowing for sure if the problem is fixed as I can't reproduce it! I can go several days without seeing the glitch and then it appears!


Stevie G(Posted 2005) [#9]
Why don't you just use a standard camera for rendering the GUI .. it's equally as easy to get pixel perfect images displayed and I've never had any problems with it. I've always had problems with ortho camera's though.

In fact, why are you using two renderworlds?? If the GUI camera is outwith the range of the main camera then it is not necessary. A single renderworld will update both camera's. Are you setting the entityorder of the GUI cam at all? When you call renderworld .. I'm pretty sure the camera's are rendered in the order they are created.

I have code I use which I can send you if you like?


jhocking(Posted 2005) [#10]
*poof*


jhocking(Posted 2005) [#11]
A single renderworld will update both camera's... I'm pretty sure the camera's are rendered in the order they are created.

If that's true, that's pretty spiffy. I didn't know that.

CameraClsMode(TG_cam\camera,0,1)

I just noticed this part of the first post. I haven't messed with this command in forever; I'll have to look it up to refresh my memory. What with the two renders, this seems suspicious.


Stevie G(Posted 2005) [#12]
I hope you're not suggesting I'm a buffty boy James ;)

The way he's set the cameraclsmode command is correct assuming he's rendering the GUI camera last.


Shifty Geezer(Posted 2005) [#13]
Why don't you just use a standard camera for rendering the GUI .

In fact, why are you using two renderworlds??

Uh...because I'm not clever enough to know otherwise?!

I have code I use which I can send you if you like?
Yes please! I was using two cameras because I didn't know pixel-mapped displays could be attained with perspective cameras, and the two Renderworlds because I didn't know how else to render two carmeras in the order I wanted. No idea what would happen with two cameras trying to render different scenes at the same time.

jhocking : The CameraClsMode (cam,0,1) disables clearing of the colour but clears the z-buffer so the game objects appear behind the UI. This isn't actually a concern in the current setup because I don't draw any objects behind the UI, but I assume it'll be a slight speed optimization not clearng the z-buffer twice a frame. Hopefully Stevie G will will render all this shennanigans obsolete though!


jhocking(Posted 2005) [#14]
Have you tried commenting out that line to see what happens? It doesn't sound like it should make a difference, but it may be worth checking anyway.


Stevie G(Posted 2005) [#15]
Shifty,

Here's a small demo of how I do this ... just replace the texture name with your own as per the norm.

I do use a second camera as this keeps the gui separate from everything else and means you don't have to worry about camerazoom etc.. not that that's a big issue mind.

Hopefully it will resolve you problems ...

Stevie

Graphics3D 640,480,16,1
AmbientLight 255,255,255

Global CAMERA = CreateCamera() , LIGHT = CreateLight()
Global GH = GraphicsHeight()
Global GW = GraphicsWidth()
Global HGW = GW * .5
Global HGH = GH * .5
Global GUIcamera
Global GUIcursor
Global GUIsx#, GUIsy#

;draw some backgound stuff
For l = 0 To 50
	entity = CreateCube()
	ScaleEntity entity , Rand(1,5), Rand(1,5), Rand(1,5 )
	RotateEntity entity , 0, Rand(-180,180 ), 0
	EntityColor entity, Rand( 128,255 ), Rand( 128,255 ), Rand( 128,255 )
	PositionEntity entity, Rand(-100,100 ), Rand(-100,100 ), Rand(-100,100 )
Next

GUI_Init()

While Not KeyDown(1)

	TurnEntity CAMERA, 1, 1, 0

	GUI_Position( GUIcursor , MouseX(), MouseY() )

	RenderWorld()
	Flip
	
Wend

;===========================================================================
;===========================================================================
;===========================================================================

Function GUI_Init()

	GUIcamera = CreateCamera()
	CameraClsMode GUIcamera,False,True
	CameraRange GUIcamera, .1,5
	PositionEntity GUIcamera, 0,0,10000
	EntityOrder GUIcamera,-999

	;get 3d reso independant scaling
	GUIplane = CreatePlane( 1, GUIcamera )
	RotateEntity GUIplane, -90,0,0
	PositionEntity GUIplane, 0,0,1
	EntityPickMode GUIplane, 2
	CameraPick ( GUIcamera, 0,0 )
	sx# = PickedX()
	sy# = PickedY()
	CameraPick ( GUIcamera, GW, GH )
	GUIsx# = ( PickedX() - sx ) / Float( GW )
	GUIsy# = ( sy - PickedY() ) / Float( GH )
	FreeEntity GUIplane
	
	;cursor
	GUIcursor = GUI_Quad( GUIcamera, 16 , 16 , LoadTexture( "../TrackEditor/Cursor.png", 4 )  , True , 0 , 0 , 1,  -1000 ) 

End Function

;===========================================================================
;===========================================================================
;===========================================================================

Function GUI_Position( Entity , x#, y# )

	PositionEntity Entity, ( x - HGW ) * GUIsx , ( HGH - y ) * GUIsy, 0

End Function

;===========================================================================
;===========================================================================
;===========================================================================

Function GUI_Quad( parent , sx#, sy#, Texture , Free = False , ox#=0, oy#=0 , oz# = 1 , order=-998 )

	mesh = CreateMesh( parent )
	s = CreateSurface( mesh )
	For iy = 0 To 1
		For ix = 0 To 1
			px# = ( ix * sx - ox ) * GUIsx
			py# = ( -iy * sy + oy ) * GUIsy
			AddVertex s, px, py, oz, ix+.5*(1.0/sx), iy+.5*(1.0/sy )
		Next
	Next
	AddTriangle s, 0,1,3
	AddTriangle s, 3,2,0
	EntityFX mesh, 1
	EntityTexture mesh , Texture
	If Free FreeTexture Texture
	EntityOrder mesh, order
		
	Return mesh

End Function




Shifty Geezer(Posted 2005) [#16]
Many thanks Stevie. Will look into it. I see the camera placement sues the pixie-style texture placement for pixel-accurate textures!

Joe : If I comment out that line, the game graphics are erased when the UI camera is rendered.


jhocking(Posted 2005) [#17]
duh, I knew that, I just forgot.


Shifty Geezer(Posted 2005) [#18]
Kinda wierd though. I'd have thought if you weren;t clearing the buffer the graphics would draw over the top of the previous scene. Somewhere along the line the buffer is getting cleared per render but I don't know where that is.

Stevie : Many thanks for that! Reworked my UI to use your system and it shold be faster as well as hopefully removing that big bug. Though annoyingly, after finishing off late last night I looked at my program with a sense of satisfaction, and then realized that all the work I'd just put in actually had the same results as before - a 2D interface. That 's the worst part of programming, when you're not adding anything new but reworking stuff you've already programmed. Ugh!


Stevie G(Posted 2005) [#19]
Glad to be of help.