Archived

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

Masking

This topic is 5270 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

I just finished the texture masking tutorial, and it was exactly the thing I needed.. but I have a question about masking. So, I have a bmp picture that I want to display with masking (because it is not rectangular. Can I somehow derive the mask out of the picture itself, knowing that areas of a certain RGB value (let''s say 1.0f, 0.0f, 1.0f) must not be drawn, while everything else should? Thanks a lot! G-9405

Share this post


Link to post
Share on other sites
Yes you can. After you load the image into memory, create a second array, same size, this will be your mask. Now, go through your image and set a 0 in the mask everytime you encounter said rgb value, otherwise set a 1.

[edited by - Wildfire on July 7, 2003 10:48:15 AM]

Share this post


Link to post
Share on other sites
I was thinking if it is possible to modify the original texture, and not create a mask. For example, to add a 0.0f alpha wherever there is a certain RGB value. Or simply not render such RGB valued pixels. But I''m so new to OpenGL that I have totally no idea how to do that.

I have two more questions though.
1. How can I display a large .bmp file using glDrawPixels, and not texture mapping? OR even better, is is possible to get around the limitation that a texture must be a pwoer of two?
2. Can anyone please briefly explain glBlendFunc to me? I just don''t seem to get it, and I did try the Red Book explanation?

Sorry for asking that much, but this is all stuff I do not find in tutorials...

G-9405

Share this post


Link to post
Share on other sites
There is an RGBA mode which has an alpha value. The solution remains pretty much the same though. You need a buffer where you can store RGB+A of the image. The RGB values can come from the .bmp, the A can be set by you. Then use the buffer to generate your texture.

glTexImage2D(..., ..., ..., ..., ..., ..., GL_RGBA, ..., buffer);

I think newer GC support textures that are not the power of two. But you can get around that limit pretty easily. Load a texture with ^2 and only map a part of it onto a quad/triangle whatever. This way you could also have more then one texture in a single .bmp.
Doing it by hand (i.a. glDrawPixels) will probably be a lot slower...

Tried this tutorial yet?

Share this post


Link to post
Share on other sites
Thanks for the fast reply, Wildfire.

I have already tried what you suggested about mapping only what I need from a ^2 texture. It renders fine, but it is a HUGE waste of memory. I have 12 pictures, 2000x1500 each. If I load them that way, I must load 12 pictures, 2048x2048 each, which is too much for a 256 RAM computer, and is an UGLY way to do it. This is why I was thinking abuot glDrawPixels for the large images that do not need transparency (being backgrounds for a 2D game), and using texturing for the smaller srpites rendered on top. The problem is that glDrawPixels requires a format and type parameter, and if I load the bytes from a .bmp, I have no idea what to set format and type to.

For the transparency issue, I will read the TGA loading tutorial and see if I can simply get the alpha values from there. Finally, is TGA comression lossless or is it similar to the JPEG compression?

Thanks a lot!

G-9405

Share this post


Link to post
Share on other sites
Those textures are huge, agreed. But I think the problem is more with graphicscard memory and speed, rather then system memory.
Maybe you should try using smaller textures. If you could reduce the size of a texture to 1024x512 for example you could stuff eight of those into one 2048x2048 image.

Nehe''s tutorial only covers uncompressed tgas without alpha channel afaik. Try searching here for the format specifications. If I''m not mistaken tga uses rle-encoding only, not sure. I am sure however that, whatever tga uses, is lossless.

Share this post


Link to post
Share on other sites
Alright, so I tried using DrawPixels, but all I get is a black screen. The way I load the bitmap is like this:

FILE *File = NULL;
if (!filename)
return FALSE;
File = fopen (filename, "r");
if (File) {
fclose (File);
Bitmap = auxDIBImageLoad (filename);
}

It's the exact same routine that I use to load .bmps for textures. My .bmp is exactly SCREEN_WIDTH x SCREEN_HEIGHT in size. Then, I draw like this:

glRasterPos2i (0, SCREEN_HEIGHT);
glDrawPixels (SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, Bitmap->data);

I noticed that glTexImage2d requries the same format and type parameters, so I used them from there. But it still won't work...

G-9405

[edited by - Godji on July 8, 2003 5:11:15 AM]

Share this post


Link to post
Share on other sites