Jump to content

Set color of a custom texture


Recommended Posts

Hello! I am making a custom CJ system and I am using custom clothes. I would like to make colorable clothes as well, where the player can define the color of the clothing or even the hair color for example. I am using dxCreateTexture to make the custom clothes' textures. My question is how can I change the color of the custom textures? Let's say I have a white T-shirt, and I want to use a colorpicker to change its color. Could somebody help me out with that please?

Link to comment

You've asked this question before just throwing that out there not trying to be an ass xDDD
You need to find a modeler to help you/teach you, or Youtube can be your best friend like how I mostly learned.
Man sharpens man.
You'll need to use zModeler or 3DS Max or Blender to either separate the textures into multiple pieces, (shirts, shoes, skin, etc)
Or you can search through the 100+ thousand GTA SA custom ped models on the internet, and try to find peds with the textures already separated (which I've seen many like this).
If you have questions add me on Skype and ask me (I won't do anything for you but I can teach you) xD
Good luck bro.

Link to comment

No I don't have to do what you wrote. I already did the system and it works perfectly without even using 3ds max or zmodeler or custom ped models. I am using only the CJ skin, clothes, clothing textures and texture replacing shaders. By the way I am asking how can I change the color of a texture created by dxCreateTexture, and I don't remember asking it before.

Link to comment

You need a color shader, or a renderTarget -> draw the texture image then draw one rectangle with the selected color -> create texture from the renderTarget pixels then destroy renderTarget.

What did I say before?

function changeTextureColor(textureElement, red, green, blue, alpha)
	local textureWidth, textureHeight = dxGetMaterialSize(textureElement) -- get the texture size
  	local tempRenderTarget = dxCreateRenderTarget(textureWidth, textureHeight) -- create render target with texture size
  
  	dxSetRenderTarget(tempRenderTarget) -- start rt
  	dxDrawImage(0, 0, textureWidth, textureHeight, textureElement) -- draw the texture image to the rt
  	dxDrawRectangle(0, 0, textureWidth, textureHeight, tocolor(red, green, blue, alpha)) -- draw the selected color rectangle to the rt
  	-- you can add custom texts to texture etc..
  	dxSetRenderTarget() -- end rt
  	
  	local rt_pixels = dxConvertPixels(dxGetTexturePixels(tempRenderTarget), "png") -- get the rt pixels and convert to png
  	destroyElement(tempRenderTarget) -- destroy rt because I converted to texture
  
  	return dxCreateTexture(rt_pixels) -- return the new texture element
end

 

Or the shader way (I dont tested the shader):

float red;
float green;
float blue;
float alpha;

technique colorChange
{
    pass P0
    {
        MaterialAmbient = float4(red, green, blue, alpha);
    }
}
-- You need to divide the r/g/b with 255 because shader color float range is 0-1.

local selectedRed = 128
local selectedGreen = 64
local selectedBlue = 32
local selectedAlpha = 200

dxSetShaderValue(colorChangeShader, "red", selectedRed / 255)
dxSetShaderValue(colorChangeShader, "green", selectedGreen / 255)
dxSetShaderValue(colorChangeShader, "blue", selectedBlue / 255)
dxSetShaderValue(colorChangeShader, "alpha", selectedAlpha / 255)

-- then apply the shader to the world texture

 

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