I’m trying to draw a gradient on a texture, so i did come up with this code though i just get a solid color red … Not a gradient, i know you can also use Color.Lerp but i don’t want because i want to be able to put any customizable color pattern/range on there i prefer. Could somebody explain me if i am doing something wrong ?
for (int h=0;h<256;h+=1) col += new Color( (float)h/255.0f,0.0f,0.0f);
for (int x=0;x<BackgroundTex.width;x+=1)
for (int y=0;y<BackgroundTex.height;y+=1)
{
BackgroundTex.SetPixel(x,y,col);
}
BackgroundTex.Apply();
I don’t think you understand programming well enough yet.
Your first loop gradually takes col, and loops 256 times adding various shades of red to col. When that loop finishes you have one solid red color.
Then you loop and add that one color to the texture.
Forget your first loop, build the col color inside the second loops, basing it on the x and y directly.
I have tried putting the loop that adds to color inside the x,y loop so in my mind i thought that would solve it but of course, you’d have the loop completed first before the color is added too, then i tried incrementing a separate variable called cnt inside the x,y loop and setting it to zero once it reaches 255 but that didn’t work out either, i actually have quite some programming experience still limited though but sometimes when i’m tired i just don’t see it Anyway what you say works, thanks a lot.
I realize now, i should increment the counter outside the x,y loop because that is two nested for loops
Nevermind, misread the code a bit Please use the code tags next time ^^