Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

graveyard filla

problem with drawing pieces of transparent textures (OpenGL)

This topic is 5195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

high, i have a tilemap image (its like a checkerboard image of my tiles) which i use as a texture, then i "slice" this texture to map my quads (individual tiles) with. basically, i have one big tilemap image and then i slice it into pieces and use that piece as the texture for a single tile. heres the problem: i cant get transparency to work while slicing the texture.... transparency works fine if i map the ENTIRE texture to the quad, but if i only map a portion of the quad (via glTextCoord()), the transparency stops working. heres what im talking about, firstly, heres what the tilemap looks like: if you look at the bottom row of tiles, you will see that they have transparent pieces to them (they are edges of buildings as you are about to see) now heres what this looks like in game do you see what the problem is? if you look at the bottom and top of the building, where i used the tiles which had transparent pieces, the transparent part is showing up!! even more weird, is its showing up BLACK! why is it black, and not transparent? i dont think its something weird im doing with my code, if you notice the sprite next to the building, his transparency is working! also, i wanted to make sure its not my image loading code, so i tried mapping the ENTIRE tilemap to my players quad... look what that looks like.. if you look at the bottom row of tiles, they ARE transparent! so why will transparency work if i map an ENTIRE texture to a quad, but it craps out on me and gives me black when i try to map a piece of a texture to a quad ??? anyone experiance this before? any help is greatly appreciated!!! (will post code if its needed) [edited by - graveyard filla on May 27, 2004 4:04:38 PM] [edited by - graveyard filla on May 27, 2004 5:55:30 PM] [edited by - graveyard filla on May 27, 2004 5:59:32 PM]

Share this post

Link to post
Share on other sites
There could be some diffrent things making your quad not showing up transparent. You say it works when you map the texture to your player tile.
Are you rendering the player tile and the "map" tiles with diffrent settings? Blending, vertex alpha enabled/disabled etc.

- Patrik Willbo

The Lord says He can get me out of this mess, but He's pretty sure you're fucked.
- Stephen (Braveheart)

[edited by - Willbo on May 27, 2004 6:18:35 PM]

Share this post

Link to post
Share on other sites
the code i do for drawing a tile is the same for drawing a regular quad... although i DO blit the whole tilemap with Draw_Quad() to test to see if it will have transparency (the 3rd pic)... but there is no difference really... heres the 2 functions..

void System::Draw_Quad(GLuint &texture,float x, float y,float width,float height)
//bind the texture we sent in to this quad


//draw this quad white


glBegin(GL_QUADS); /* Draw A Quad */

glTexCoord2f(0.0f, 1.0f);
glVertex2f(x, y + height); /* Bottom Left */

glTexCoord2f(1.0f, 1.0f);
glVertex2f(x + width,y + height); /* Bottom Right */

glTexCoord2f(1.0f, 0.0f);
glVertex2f(x + width,y); /* Top Right */

glTexCoord2f(0.0f, 0.0f);
glVertex2f(x,y); /* Top Left */



void System::Draw_Tile(float x, float y, float x_loc, float y_loc)
//bind the texture we sent in to this quad


//draw this quad white


//float corner_offset = 32.0f/64.0f; //(map.tmap_height*TILESIZE);

float t_perc_w = 32.0f/((float)map_data.tmap_width*(float)TILESIZE);
float t_perc_h = 32.0f/((float)map_data.tmap_height*(float)TILESIZE);


/* Bottom Left */
glTexCoord2f(x_loc, y_loc + t_perc_h); //was 0.0f,1.0f

glVertex2f(x, y + 32.0f);

/* Bottom Right */
glTexCoord2f(x_loc + t_perc_w , y_loc + t_perc_h); //was 1.0, 1.0

glVertex2f(x + 32.0f,y + 32.0f);

/* Top Right */
glTexCoord2f(x_loc + t_perc_w , y_loc); //was 1.0,0.0

glVertex2f(x + 32.0f,y);

/* Top Left */
glTexCoord2f(x_loc,y_loc); //was 0.0 0.0




there really is no difference... i dunno why this is happening.. thanks for any help

Share this post

Link to post
Share on other sites
instead of colorkeying your textures, just add a regular alpha chanel (Assuming you have a decent image editor... and if you don''t get the GIMP for free). As long as blending is turned on, OpenGL doesn''t care if you color key your textures, don''t have any transparency, or load the alpha data right from the actual file, it''s going to treat it like it has alpha anyway, so might as well use it.

That, and color keys just bite.

Share this post

Link to post
Share on other sites
leai, i just tried that but no luck.. for some reason the alpha channel isnt coming through.. instead of being transparent its a white background... maybe i made the alpha channel wrong in the image editor? i dont think i did.... also, i use SDL_CreateRGBSurface and copy my image onto that surface before loading it, so its in RGBA order... i read somewhere that this stops alpha channels from working.. but if i try not copying my image to an RGB surface, i cant get ANYTHING to look right (screen turns all black)... im just trying to figure out how why its now being transparent in the first place just because im only texturing a piece of the image...

Share this post

Link to post
Share on other sites
hmm.. still no good, the alpha part of the texture is just coming out white... maybe i didnt do the image part right or something? could you email me an image which you know has an alpha channel if you dont mind? maybe its my code? heres my code to load a texture

GLuint System::Load_Texture(string image, bool is_transparent)

GLuint texture;

//Create The Texture


SDL_Surface *img = IMG_Load(image.c_str());//Load_Image(image);//IMG_Load(image.c_str());//Load_Image(image.c_str());


// SDL_SetColorKey(img, SDL_SRCCOLORKEY,SDL_MapRGB(img->format, 255, 0, 255));

SDL_Surface *img2 = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA,img->w,img->h,32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);

SDL_BlitSurface(img, NULL,img2, NULL);

//Typical Texture Generation Using Data From The Bitmap


//Linear Filtering


// Generate The Texture

glTexImage2D(GL_TEXTURE_2D, 0,4,img2->w,img2->h, 0 ,GL_RGBA,GL_UNSIGNED_BYTE, img2->pixels);

//free our image and return our texture


return texture;

thanks alot for all your help!!!

Share this post

Link to post
Share on other sites

im starting to get really frustrated. i finnally figured out how to add an alpha channel in the GIMP... anyway, i add the alpha channel to the spots i want....

I GET THE SAME EXACT EFFECT!!!!!!!!!!!!!!!!!!!!!!!

if i map the ENTIRE tilemap image, onto the enemy's quad, THE TRANSPARENCY WORKS!!!!!

BUT, when i map only a PERCENTAGE of the texture to a 32x32 quad (my tile), THE TRANSPARENCY IS BLACK!!!

also, im 100% positive the alpha channel i did correctly in the image editor, because it IS transparent if i map the ENTIRE texture to a quad... but if i try mapping only a percentage of this texture, THE TRANSPARENT PART IS BLACK!!!!!

(read my first post, it is doing the SAME exact thing, only this time im not color-keying anything, im using alpha channels....)

i only call glEnable(GL_BLEND); ONCE, at the begining of the game... i make sure to fill the quad with a white opaque color before drawing.. in fact, read my second post on this thread. it contains my 2 functions i use to draw, Draw_Tile() and Draw_Quad(), they are EXACTLY the same except Draw_Tile() "slices" the tilemap into a single tile piece...

does ANYONE have any idea on why this is happening. i know there must be someone out there who maps portions of a texture with either color keys, alpha channels, or something. PLEASE respond to this thread, post your code, anything.. any help is greatly appreciated...

[edited by - graveyard filla on May 28, 2004 6:22:35 PM]

[edited by - graveyard filla on May 28, 2004 7:37:50 PM]

Share this post

Link to post
Share on other sites
after tearing out my hair, i think i figured out the problem.

i was trying all kinds of things, going crazy, when i thought - "hey self, lets try drawing a 32x32 quad, we will map a portion of the tilemap to this quad, just like i do when i draw my map, but instead, i will only draw a SINGLE tile instead of a scree full of them"

ok, so i draw only a single tile, mapped with a portion of the texture which *SHOULD* appear transparent..


ok, so it IS possible to map a portion of a transparent texture!!

im thinking that the black im seeing, is actually the background - how do i change this! im thinking, since there is "nothing" "behind" the tile, it shows up black - but when i manually draw the SAME quad, "on top of" (after) i draw the map, its background DOES show up transparent...

the one labeled "no good", is an actual tile that is in my map[][] array. i render this whole map array before i render ANYTHING else, so this is "on the bottom".

the one labeled "good!" is a tile rendered in the EXACT manner the "no good" one is, EXCEPT, i render this one AFTER i draw my whole map, so it is "on top of" my map. notice that the transparent part IS transparent!!!

"the whole thing" is just my entire tilemap texture rendered to a 128x128 quad (the size of the texture). again, the transparency is working because its "on top of" my map.

this is why the tilemap texture would appear to be normal if i mapped it to my player/enemy quads, because my player/enemies are rendered AFTER/on top of the map!!

so HOW do i get rid of the background, so that instead of getting a black piece where it should be transparent, i get a REAL transparent piece??

thanks for any help...

edit: thinking about it, the reason its showing black is because theres literally nothing "behind" it. how would i go about doing this then... do i have to have 2 maps which represent 2 different layers? one with trasparent tiles, and another without transparent tiles? first i would draw the opaque map, then i would draw the transparent map right after? im REALLY hoping i wont have to do this... this will be complicated and a huge pain in the ass, effecting everything from collision, to my map editor, it will just be such a big deal to do for such a small problem...

[edited by - graveyard filla on May 28, 2004 8:17:51 PM]

[edited by - graveyard filla on May 28, 2004 8:18:46 PM]

Share this post

Link to post
Share on other sites
Reality Check: well, why do you want transparency if there is nothing behind it? See what i mean?

If there isn't, just make a regular bmp that joins to the other tiles visually. Otherwise, blit the ground first, then whatever is on top of the ground for layered effect. There isn't any other way to do it.

However, keep in mind that many of ye old classic RPGs just used regular non-transparent tiles to achieve their effects.

The other thing i'll point out is that you are creating what appears to be a 3/4 perspective with square tiles. This is bad from a design point of view (like using a hammer to set screws). Either make a true top-down view with square tiles (like Final Fantasy), or a 3/4 view with diamond tiles.

here is some wonderfull info on isometric vs topdown tiling systems and how to make them work.

EDIT: oh, and when you open a thread, say "hi" or "hello". "high" is the opposite of "low" ;-)

[edited by - leiavoia on May 28, 2004 9:54:09 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!