Jump to content

Writing text on textures?


Threule

Recommended Posts

1 hour ago, Dimos7 said:

i guess with photoshop or something like this maybe

Then it wont work as expected, let's say I want to print the username on the back of a shirt, I cant do that with photoshop because i have to create all the possible variables

Edited by Threule
Link to comment
  • Moderators

nope, not an example.

 

But there are of course examples on wiki:

https://wiki.multitheftauto.com/wiki/EngineApplyShaderToWorldTexture

https://wiki.multitheftauto.com/wiki/DxCreateRenderTarget

If you merge those wiki codes, you probably get some results. If you want to have some specific information about these functions, feel free to ask. But make sure to check wiki first X 10.

 

( one uncertainty ) If render target textures can't be used for shaders directly, then you can also copy them to another texture.

https://wiki.multitheftauto.com/wiki/DxGetTexturePixels

https://wiki.multitheftauto.com/wiki/DxCreateTexture

 

All required wiki examples:

addEventHandler("onClientResourceStart", resourceRoot,
    function()
        myRenderTarget = dxCreateRenderTarget( 80, 100 )            -- Create a render target texture which is 80 x 100 pixels
    end
)

addEventHandler( "onClientRender", root,
    function()
        if myRenderTarget then
            dxSetRenderTarget( myRenderTarget )                     -- Start drawing on myRenderTarget
            dxDrawText ( "Hello", 10, 20 )                          -- Draw a message
            dxSetRenderTarget()                                     -- Stop drawing on myRenderTarget

            dxDrawImage( 50,  50,  100, 100, myRenderTarget )       -- Now use myRenderTarget as a material and draw it lots of times
            dxDrawImage( 150, 350, 150, 100, myRenderTarget )
            dxDrawImage( 250, 250, 100, 150, myRenderTarget )
            dxDrawImage( 350, 30,  150, 150, myRenderTarget )
        end
    end
)

local myRenderTarget = dxCreateRenderTarget(500, 500, true)

--
-- Function to draw text to our render target with '''modulate_add''' blend mode when the 'r' key is pressed
--
function updateRenderTarget()
    dxSetRenderTarget(myRenderTarget, true)
    dxSetBlendMode("modulate_add")  -- Set 'modulate_add' when drawing stuff on the render target

    dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear")

    dxSetBlendMode("blend")         -- Restore default blending
    dxSetRenderTarget()             -- Restore default render target
end
bindKey("r", "down", updateRenderTarget )

 

theTechnique = dxCreateShader("shader.fx")
explosionTexture = dxCreateTexture( "tex/Explosion.png")

function replaceEffect()
	engineApplyShaderToWorldTexture(theTechnique, "fireball6")
	dxSetShaderValue (theTechnique, "gTexture", explosionTexture)
end
addEventHandler("onClientResourceStart",resourceRoot,replaceEffect)

Shader

texture gTexture;

technique TexReplace
{
    pass P0
    {
        Texture[0] = gTexture;
    }
}

 

 

 

 

Edited by IIYAMA
  • Haha 1
Link to comment
1 hour ago, IIYAMA said:

nope, not an example.

 

But there are of course examples on wiki:

https://wiki.multitheftauto.com/wiki/EngineApplyShaderToWorldTexture

https://wiki.multitheftauto.com/wiki/DxCreateRenderTarget

If you merge those wiki codes, you probably get some results. If you want to have some specific information about these functions, feel free to ask. But make sure to check wiki first X 10.

 

( one uncertainty ) If render target textures can't be used for shaders directly, then you can also copy them to another texture.

https://wiki.multitheftauto.com/wiki/DxGetTexturePixels

https://wiki.multitheftauto.com/wiki/DxCreateTexture

 

All required wiki examples:


addEventHandler("onClientResourceStart", resourceRoot,
    function()
        myRenderTarget = dxCreateRenderTarget( 80, 100 )            -- Create a render target texture which is 80 x 100 pixels
    end
)

addEventHandler( "onClientRender", root,
    function()
        if myRenderTarget then
            dxSetRenderTarget( myRenderTarget )                     -- Start drawing on myRenderTarget
            dxDrawText ( "Hello", 10, 20 )                          -- Draw a message
            dxSetRenderTarget()                                     -- Stop drawing on myRenderTarget

            dxDrawImage( 50,  50,  100, 100, myRenderTarget )       -- Now use myRenderTarget as a material and draw it lots of times
            dxDrawImage( 150, 350, 150, 100, myRenderTarget )
            dxDrawImage( 250, 250, 100, 150, myRenderTarget )
            dxDrawImage( 350, 30,  150, 150, myRenderTarget )
        end
    end
)

local myRenderTarget = dxCreateRenderTarget(500, 500, true)

--
-- Function to draw text to our render target with '''modulate_add''' blend mode when the 'r' key is pressed
--
function updateRenderTarget()
    dxSetRenderTarget(myRenderTarget, true)
    dxSetBlendMode("modulate_add")  -- Set 'modulate_add' when drawing stuff on the render target

    dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear")

    dxSetBlendMode("blend")         -- Restore default blending
    dxSetRenderTarget()             -- Restore default render target
end
bindKey("r", "down", updateRenderTarget )

 


theTechnique = dxCreateShader("shader.fx")
explosionTexture = dxCreateTexture( "tex/Explosion.png")

function replaceEffect()
	engineApplyShaderToWorldTexture(theTechnique, "fireball6")
	dxSetShaderValue (theTechnique, "gTexture", explosionTexture)
end
addEventHandler("onClientResourceStart",resourceRoot,replaceEffect)

Shader


texture gTexture;

technique TexReplace
{
    pass P0
    {
        Texture[0] = gTexture;
    }
}

 

 

 

 

Today no one wanna try to code by yourself. They just ask for the code and done.

Whatever.

  • Thanks 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...