• Material proxy and render texture problem
    7 replies, posted
I'm making a material with procedurally changeable texture on it. More precisely - with changeable text. For sample, I added this code: local rttexture = GetRenderTarget( "MyTextRTback", 512, 256 ) local function RenderTextTexture( side, mat ) mat:SetTexture( "$basetexture", rttexture ) local oldW = ScrW() local oldH = ScrH() local OldRT = render.GetRenderTarget() local renderwidth = 512 local renderheight = 256 -- Set up our view for drawing to the texture render.SetRenderTarget( rttexture ) render.SetViewPort( 0, 0, renderwidth, renderheight ) cam.Start2D() render.Clear( 0, 0, 0, 255 ) draw.DrawText( "Sample text", "Trebuchet18", 0, 0, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) cam.End2D() render.SetRenderTarget( OldRT ) render.SetViewPort( 0, 0, oldW, oldH ) end matproxy.Add( { name = "MyText", init = function( self, mat, values ) end, bind = function( self, mat, ent ) RenderTextTexture( "back", mat ) end } ) And added MyText proxy into vmt. The problem is that the material becomes fully invisible. How do I make it to proprely render text on it?
bump
I'd use render.pushRenderTarget instead to clean up the code. Also try checking if you can see your rendertarget is rendering correctly with mat_texturelist. If it is, then it's something wrong with the material or proxy.
Could you please put some examples using those render.pushRenderTarget and render.popRender? I still don't get it what are they supped to do. >Also try checking if you can see your rendertarget is rendering correctly with mat_texturelist How?
Could you please put some examples using those render.pushRenderTarget and render.popRender? I still don't get it what are they supped to do. They're supposed to do exactly same shit you're doing with all this clusterf*ck but without actually doing it. local oldW = ScrW() local oldH = ScrH() local OldRT = render.GetRenderTarget() local renderwidth = 512 local renderheight = 256 render.SetRenderTarget( rttexture ) render.SetViewPort( 0, 0, renderwidth, renderheight ) -- stuff here render.SetRenderTarget( OldRT ) render.SetViewPort( 0, 0, oldW, oldH ) You can (and should) be using this instead. render.PushRenderTarget( rttexture) -- stuff here render.PopRenderTarget()
> Or did you just copypaste that bit from somewhere without understanding what it does? the stuff was copypasted from garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/cl_viewscreen.lua - function SWEP:RenderScreen(). I don't get it why it does work for tool screen but not any random material. Mine is still invisible.
bump
bump
Sorry, you need to Log In to post a reply to this thread.