Jump to content

dxDrawRectangle - alpha 0 to 255 from side-to-side


Recommended Posts

Hi,

I wanted create black dxDrawRectangle which alpha is from left 255 to right 0.

Something like this

spacer.png

 

Image isn't my.

 

Please help, I know so far that I should use Interpolatebetween but don't have idea how to.

 

Link to post
2 hours ago, XaskeL said:

Try creating something like this in a shader (it's really easy) or make a similar background in Photoshop.

image.png

Could you explain more? I don't know how to use this.

 

I was thinking smoething like that (from user Pa3ck), above is for 2-colors dxDraw, I need for alpha 

addEventHandler ("onClientResourceStart", resourceRoot, 
    function () 
        texture = dxCreateTexture (300, 25)
        local pixels = dxGetTexturePixels (texture)
        for i=0,300 do	 
			local progress = 100 / 300 * i / 100
			local r, g, b = interpolateBetween ( 255, 0, 0, 255, 255, 0, progress, "Linear")
            for j=0,25 do
                dxSetPixelColor (pixels, i, j, r, g, b, 255)
            end
        end
        dxSetTexturePixels (texture, pixels)
		texture2 = dxCreateTexture (600, 25)
        local pixels2 = dxGetTexturePixels (texture2)
        for i=0,300 do	 
			local progress = 100 / 300 * i / 100
			local r, g, b = interpolateBetween ( 255, 255, 0, 0, 255, 0, progress, "Linear")
            for j=0,25 do
                dxSetPixelColor (pixels2, i, j, r, g, b, 255)
            end
        end
        dxSetTexturePixels (texture2, pixels2)
	end)

addEventHandler ("onClientRender", root,
    function ()
         dxDrawImage (300, 300, 300, 25, texture)
		 dxDrawImage (600, 300, 300, 25, texture2)
    end)
Link to post
2 hours ago, xXBlasterXx said:

Could you explain more? I don't know how to use this.

 

I was thinking smoething like that (from user Pa3ck), above is for 2-colors dxDraw, I need for alpha 


addEventHandler ("onClientResourceStart", resourceRoot, 
    function () 
        texture = dxCreateTexture (300, 25)
        local pixels = dxGetTexturePixels (texture)
        for i=0,300 do	 
			local progress = 100 / 300 * i / 100
			local r, g, b = interpolateBetween ( 255, 0, 0, 255, 255, 0, progress, "Linear")
            for j=0,25 do
                dxSetPixelColor (pixels, i, j, r, g, b, 255)
            end
        end
        dxSetTexturePixels (texture, pixels)
		texture2 = dxCreateTexture (600, 25)
        local pixels2 = dxGetTexturePixels (texture2)
        for i=0,300 do	 
			local progress = 100 / 300 * i / 100
			local r, g, b = interpolateBetween ( 255, 255, 0, 0, 255, 0, progress, "Linear")
            for j=0,25 do
                dxSetPixelColor (pixels2, i, j, r, g, b, 255)
            end
        end
        dxSetTexturePixels (texture2, pixels2)
	end)

addEventHandler ("onClientRender", root,
    function ()
         dxDrawImage (300, 300, 300, 25, texture)
		 dxDrawImage (600, 300, 300, 25, texture2)
    end)

image.png

local SHADER_CODE = [===[
	float3 g_f3Color = (float3)0.0;
	
	struct PSInput
	{
		float4 Position : POSITION0;
		float2 TexCoord : TEXCOORD0;
	};

	float4 PixelShaderFunction ( PSInput PS ) : COLOR0
	{
		return float4( g_f3Color, 1.0 - PS.TexCoord.x );
	};
	
	technique
	{
		pass P0
		{
			PixelShader = compile ps_2_a PixelShaderFunction();
		}
	}
]===];

local _dxDrawRectangle = dxDrawRectangle;
local g_pShader = dxCreateShader( SHADER_CODE );

function dxDrawRectangle( fX, fY, fWidth, fHeight, pColor, bPostGUI, bLerpAlpha )
	if ( not bLerpAlpha ) then
		_dxDrawRectangle( fX, fY, fWidth, fHeight, pColor, bPostGUI );
	else
		dxSetShaderValue( g_pShader, "g_f3Color", pColor );
		dxDrawImage( fX, fY, fWidth, fHeight, g_pShader, 0, 0, 0, -1, bPostGUI );
	end
end;

addEventHandler( "onClientRender", root, function ( )
	dxDrawRectangle( 600, 400, 256, 256, { 0, 0, 0 }, false, true );
end );

Please put a reaction to the message, it is on the bottom right. Don't be indifferent.

  • Like 2
Link to post

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