Howdy,
I'm using a render target as the basetexture for a material that I've created. The issue that I'm running into is that the content drawn in the render target isn't the correct size.
Here's a snippit of code to demonstrate:
local newRenderTarget = GetRenderTarget( "Test", 512, 512 );
local params = {
["$basetexture"] = "models/debug/debugwhite",
["$model"] = 1,
["$additive"] = 1,
["$vertexalpha"] = 1,
["$vertexcolor"] = 1,
["$nocull"] = 1
};
local testMaterial = CreateMaterial(
"decal",
"UnlitGeneric",
params
);
testMaterial:SetTexture( "$basetexture", newRenderTarget );
hook.Add( "HUDPaint", "Test", function()
--Store these to local vars in order to reset the render target
local oldW, oldH, oldRT = ScrW(), ScrH(), render.GetRenderTarget();
--Set the render target to the newly created one
render.SetRenderTarget( newRenderTarget );
render.SetViewPort( 0, 0, 512, 512 );
render.Clear( 0, 0, 0, 255 );
render.ClearStencil();
render.ClearDepth();
--Draw a white rectangle over the whole render target
surface.SetDrawColor( Color( 255, 255, 255, 255 ) );
surface.DrawRect( 0, 0, 512, 512 );
--Draw a red rectangle over half of the render target
surface.SetDrawColor( Color( 255, 0, 0, 255 ) );
surface.DrawRect( 0, 0, 256, 256 );
--Reset the render target
render.SetRenderTarget( oldRT );
render.SetViewPort( 0, 0, oldW, oldH );
--Draw the material on screen to see if it's functioning correctly
surface.SetDrawColor( Color( 255, 255, 255, 255 ) );
surface.SetMaterial( testMaterial );
surface.DrawTexturedRect( 0, 0, 512, 512 );
end );
As you can see, I am creating a render target that is 512 pixels tall and wide. I then draw rectangles into the render target, after which I draw the material to the screen. The result isn't as expected however as shown in this screenshot:
https://i.imgur.com/C9gElYQ.jpg
So my questions are: Why is the red portion of the material transparent, and why is it incorrectly scaled?
Sorry, you need to Log In to post a reply to this thread.