Jump to content

Text to shader


Gallardo9944

Recommended Posts

Hello.

I've been searching for a while and still can't understand the way of drawing a text with an ability to rotate it left or right. Basically, the only thing I've found is that I have to use a shader for that. Unfortunately, I dunno anything particular about drawing stuff with shaders. Is there an ability to draw a text with an .fx shader? I've also read that I could use "DxDrawMaterialLine3D" for that, so if that's also possible, I'd really appriciate an example of drawing rotated texts with that.

Thanks in advance.

Link to comment
  
-- The client script. Add  in meta 
local text = "This text is going to rotate..." 
local fontScale, font = 2.0, "default-bold" 
  
local renderTarget = dxCreateRenderTarget(dxGetTextWidth(text:gsub("#%x%x%x%x%x%x", ""), fontScale, font), dxGetFontHeight(fontScale, font), true) 
local shader = dxCreateShader("textureReplace.fx") 
  
function updateRenderTarget() 
    dxSetRenderTarget(renderTarget, true) 
    dxDrawText(text, 0, 0, 0, 0, tocolor(255, 255, 255, 255), fontScale, font) 
    dxSetRenderTarget() 
    dxSetShaderValue(shader, "tex", renderTarget) 
end 
updateRenderTarget() 
  
addEventHandler("onClientRestore", root, 
function() 
     updateRenderTarget() 
end) 
  
addEventHandler("onClientRender", root, 
function() 
    dxSetShaderTransform(shader, 45, 0, 0) -- This is where the shader is rotated 
    local width, height = dxGetMaterialSize(renderTarget) 
    dxDrawImage(200, 200, width, height, shader) 
end) 
  

  
//textureReplace.fx shader file. Add this in meta as <file src="textureReplace.fx" /> 
texture tex; 
  
technique tech 
{ 
    pass p0 
    { 
        Texture[0] = tex; 
    } 
} 
  

Code not tested.

If the quality looks bad, you can take a look at

dxSetBlendMode 

Edited by Guest
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...