Code archives/3D Graphics - Effects/Wireframe x-ray target

This code has been declared by its author to be Public Domain code.

Download source code

Wireframe x-ray target by BlitzSupport
(Posted 25 years ago)
This code grabs a section of the screen, rendered in wireframe mode to the backbuffer (but not shown), then draws it over the 3D scene, giving the effect of a small wireframe box over... the... uh...

Just try it! The only problem is that wireframe isn't guaranteed to work on all graphics cards, sadly, but there's all sorts of other neat stuff you can do with variations on this trick :)
; --------------------------------------------------------------
; WireBox Demo... james @ hi - toro . com
; --------------------------------------------------------------
; Just plug right into your existing code to see it really rocking ;)
; --------------------------------------------------------------
; Use mouse to move wirebox...
; --------------------------------------------------------------

; --------------------------------------------------------------
; WireBox stuff...
; --------------------------------------------------------------

; x pos, y pos, width, height, image...
Global wireX, wireY, wireWidth, wireHeight, wireBox

; Call at start of main loop * after setting wireX and wireY *...
Function GetWireBox (width, height)
	WireFrame 1
	RenderWorld
	wireWidth = width: wireHeight = height
	wireBox = CreateImage (wireWidth, wireHeight)
	MaskImage wireBox, 255, 0, 255
	GrabImage wireBox, wireX, wireY
	WireFrame 0
End Function

; Call just before 'Flip'...
Function DrawWireBox ()
	If wireBox
		DrawImage wireBox, wireX, wireY		
		FreeImage wireBox
	EndIf
End Function

; --------------------------------------------------------------

AppTitle "Move mouse over cube..."
HidePointer ()

Graphics3D 640, 480
SetBuffer BackBuffer ()

cube = CreateCube ()

Global light = CreateLight ()
LightColor light, 255, 0, 0

cam = CreateCamera ()
MoveEntity cam, 0, 0.75, -5

Color 0, 255, 0 ; Just for on-screen 'target'...

Repeat

	; --------------------------------------------------------------
	; **** WireBox part 1, at start of main loop ****
	; --------------------------------------------------------------
	wireX = MouseX () - (wireWidth / 2): wireY = MouseY () - (wireHeight / 2)
	GetWireBox (64, 64)
	; --------------------------------------------------------------

	TurnEntity cube, 0, 0.5, 0
	
	UpdateWorld	
	RenderWorld

	; --------------------------------------------------------------
	; **** WireBox part 2, just before 'Flip' ****
	; --------------------------------------------------------------
	DrawWireBox ()
	; --------------------------------------------------------------

	; Quick target thing...
	Rect wireX - 1, wireY - 1, wireWidth + 2, wireHeight + 2, 0
	Line wireX + (wireWidth / 2) - 4, wireY + (wireHeight / 2), wireX + (wireWidth / 2) + 4, wireY + (wireHeight / 2)
	Line wireX + (wireWidth / 2), wireY + (wireHeight / 2) - 4, wireX + (wireWidth / 2), wireY + (wireHeight / 2) + 4

	Flip

Until KeyHit (1)

End