Advertisement

render a simple tree

Started by April 26, 2002 04:20 AM
16 comments, last by adema 22 years, 9 months ago
Qixotl : you''re talning about alpha blending not alpha testing...

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
davepermen: how do i set the alpha component of my texture to 1 or 0?

i used the following command for my 32 bit texture:
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, width, height, GL_RGBA8, GL_UNSIGNED_BYTE, data);

Advertisement
in your data array you store

for(int i=0;idata[i*4+0] = r; // red at pixel i..
data[i*4+1] = g; // green at pixel i..
data[i*4+2] = b; // blue at pixel i..
data[i*4+3] = alpha; // alpha at pixel i..
}

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

quote:
Original post by davepermen
in your data array you store

for(int i=0;idata[i*4+0] = r; // red at pixel i..
data[i*4+1] = g; // green at pixel i..
data[i*4+2] = b; // blue at pixel i..
data[i*4+3] = alpha; // alpha at pixel i..
}

"take a look around" - limp bizkit
www.google.com



well the for-loop got corrupted

for(int i=0;smaller(i,width*height);i++) {
data[i*4+0] = r; // red at pixel i..
data[i*4+1] = g; // green at pixel i..
data[i*4+2] = b; // blue at pixel i..
data[i*4+3] = alpha; // alpha at pixel i..
}

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Or easier: Load your texture in Paint Shop or some other painting program. Select your tree outline. Click "paste into alpha channel". Save as *.tga and load the tga using nehe's tga loader code. Much easier that way.

and daveperman: You're code probabely won't work since the original tree texture probabely is 24 bit. This means making a new data block (in 32 bits) and for every pixel:
-copy the RGB values
-check the RGB to see what alpha should be set in data2[]
-set the alpha
-build the texture using the data2[] block

Paint shop is soo much easier

- An eye for an eye will make the world go blind -

[edited by - smarechal on May 2, 2002 4:56:06 AM]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

davepermen: thats exactly what i wanted. huge thanks for your help. i used the constant GL_RGBA instead of GL_RGBA8 otherwise it didn''t work


smarechal: i will try it with paintshop too, thanks for the tip.
Advertisement
quote:
Original post by smarechal
Or easier: Load your texture in Paint Shop or some other painting program. Select your tree outline. Click "paste into alpha channel". Save as *.tga and load the tga using nehe's tga loader code. Much easier that way.

and daveperman: You're code probabely won't work since the original tree texture probabely is 24 bit. This means making a new data block (in 32 bits) and for every pixel:
-copy the RGB values
-check the RGB to see what alpha should be set in data2[]
-set the alpha
-build the texture using the data2[] block

Paint shop is soo much easier

- An eye for an eye will make the world go blind -

[edited by - smarechal on May 2, 2002 4:56:06 AM]


for(int i=0;smaller(i,width*height);i++) {
data[4*i+0] = image[3*i+0];
data[4*i+1] = image[3*i+1];
data[4*i+2] = image[3*i+2];
data[4*i+3] = (image[3*i+0]==0&ℑ[3*i+1]==0&ℑ[3*i+2]==0)?255:0;
}

20 secs to write that code, and it will work for every texture with black = invisible.. (else compare against another color)

dunno, but starting some paintprogram, opening my file, manipulating alpha, saving, closing and then using it in my program takes more time.. and more size, remember you can't store alpha in .jpg for example.. but you can always generate it manually

oh, and if you're REALLY cool, you can even do this in the registercombiners, just comparing a color agaist the current processing pixel-color, store the result in alpha and do the alphatest..

that way its even done by the gpu

[edit] and only one fault in the first writing

"take a look around" - limp bizkit
www.google.com

[edited by - davepermen on May 2, 2002 4:14:23 PM]
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Handy bit of code davepermen. Thanx.

- An eye for an eye will make the world go blind -

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement