render.SetScissorRect Helpo

well i started to play around with 3D2D today, but i wanted todo some clipping so that things don’t get drawn where they shouldn’t

its abit odd but from what it looks like
it draws on screen like a vgui panel but clips in world…

looking at the pictures again… it doesn’t even look like its doing the clipping i want… its just kinda like breaking it

it was kinda hard to take pics…
its a black rectangle in top left

Pics!

http://img59.imageshack.us/img59/7726/rpdowntownv20011.jpg

^ What i want

http://img225.imageshack.us/img225/4081/rpdowntownv20010.jpg

^ what im testing with
v what happend

http://img13.imageshack.us/img13/9200/rpdowntownv20009.jpg

http://img825.imageshack.us/img825/7871/rpdowntownv20008.jpg

http://img37.imageshack.us/img37/5853/rpdowntownv20012f.jpg

http://img198.imageshack.us/img198/6522/rpdowntownv20014.jpg

http://img13.imageshack.us/img13/5783/rpdowntownv20015q.jpg

Codez



function CamTest()
	cam.Start3D(EyePos(), EyeAngles())
	cam.Start3D2D(Vector(-1063,-1321,312),Angle(0, 270, 90),1)
	surface.SetDrawColor(Color(0,0,0,255))
	render.SetScissorRect(0,0,222,116,true)
	surface.DrawRect(0,0,2220,116)
	render.SetScissorRect(0,0,222,116,false)
	cam.End3D2D()
	cam.End3D()
end
hook.Add("RenderScreenspaceEffects","CamTest",CamTest)


i also tryed hooking HUDPaint, no change
ideas anyone?

Correct me if I’m wrong, but I believe it has to do with cam.Start3D() being used in conjunction with cam.Start3D2D(). Use one, not both.

Scissor Rectangle is AABB screen space.

hmm
that might be mybad then, but i couldn’t seem to get it to work at all without useing cam.Start3D
could someone give an example of 3D2D without startin 3D 1st?

yes i understand this but i assumed it could work with 3D2D because you draw it the exact same way you do a HUD

You don’t need to use clipping at all. Just use cam.Start3d2d there is a perfectly good example on the wiki and many pre-made addons you can take an example from.

i do infact need clipping, this was just an example to test it
i will need / use clipping for a few things in the future but for right now its to make sure i dont draw off the set screen

You just draw it so it doesn’t go off screen, clipping is silly when you control what you draw 100%.

well yes, but thats only if i redefine what i want to draw, play with it.
and make it fit…well im not doing that, im not sure what is going to be drawn on that screen or who will do it.
i just need to make sure it doesn’t leave the screen.
clipping is the only solution i can see as of yet, so unless you can suggest a better method…

better yet, let me rephrase my initial question / w/e

How do I draw something in 3D2D but clip it?

You could just write your own tools for clipping stuff.
Here’s an example to get you started:



local clip = {}

function setBoundingClip(x,y,width,height)
	clip.x = x
	clip.y = y
	clip.width = width
	clip.height = height
	clip.set = true
end

function clearBoundingClip()
	clip.set = false
end

function rect(x,y,width,height)
	if(clip.set) then
		if(x < clip.x) then 
			width = width - (clip.x - x)
			if(width <= 0) then return end
			x = clip.x
		end
		if(y < clip.y) then 
			height = height - (clip.y - y)
			if(height <= 0) then return end
			y = clip.y
		end

		local rect_r = x + width
		local clip_r = clip.x + clip.width
		
		local rect_b = y + height
		local clip_b = clip.y + clip.height

		if(rect_r > clip_r) then
			width = width - (rect_r - clip_r)
			if(width <= 0) then return end
		end
		if(rect_b > clip_b) then
			height = height - (rect_b - clip_b)
			if(height <= 0) then return end
		end
	end
	surface.DrawRect(x,y,width,height)
end

--example:
--setBoundingClip(0,0,256,256)
--rect(0,0,400,200)


Not tested, but should work.
Might want to add UV stuff there too using Surface.DrawTexturedRectUV.

creating functions to emulate clipping probly wouldn’t be the best idea…
but it might be the only one if i cant find another way todo this

Lord wants to clip text as well (without having to trim the text), so that does not work so well.

In that case, ya could try render targets (not the most ideal solution I know, but I think that’s about as close as you’re gonna get).

That requires the person to restart their Gmod before it works too, unfortunately.

Really? That’s odd.

You could use regular clip planes for this me thinks.