Both are wrong, but second one is closest to right.
Render targets are textures and they can be created outside onClientRender. They should be created once, and when you want to update it you should use dxSetRenderTarget(gTarget) just like you are doing (this can be called in onClientRender or outside) and then draw stuff on it just like you are doing right now and then call dxSetRenderTarget() which you are doing right.
But since dxCreateRenderTarget creates a texture like dxCreateTexture does and is a dx function, you have to draw it each frame (in onClientRender), so dxDrawImage with gTarget has to be done always in onClientRender if you want it to be visible.
Important notes: when the mta loses focus (alt-tab is used, etc) then render targets are cleared so they are empty, and you have to redraw everything in the render target. onClientRestore is called when mta is back in focus again and you can draw on the render target again there. onClientRestore has a parameter "didClearRenderTargets" but dont check if it's true, instead always redraw to render target when onClientRestore is called.
Text may have bad quality in render targets, so you should experiment with dxSetBlendMode (look it up on mta wiki for example) for better visual quality.
Another important thing to remember is that when you are drawing in render targets you cant enable postGUI (for example in dxDrawText) since then the text wont be visible in the render target, but you can draw the render target with postGUI enabled.
Here is an example using your example as base:
sWidth, sHeight = guiGetScreenSize()
sW, sH = 105, 32
cFont = dxCreateFont("files/fonts/SegoeWPN_0.ttf", 32, false)
gTarget = dxCreateRenderTarget(sW, sH, true)
function updateRenderTarget()
-- Set second argument to true to clear the render target
-- before drawing on it.
dxSetRenderTarget(gTarget, true)
-- Clipping the text here using same width and height
-- as the render target is not necessary, since the render target does that automatically.
dxDrawText("CWS:Home", 0, 0, sW, sH, tocolor(0, 0, 255), 0.5, cFont, "center", "center")
dxSetRenderTarget()
end
updateRenderTarget()
addEventHandler("onClientRestore", root, updateRenderTarget)
function testRender()
dxDrawImage((sWidth/2)-(sW/2), (sHeight/2)-(sH/2), sW, sH, gTarget)
end
addEventHandler("onClientRender", getRootElement(), testRender)