can a bmp image format handle transparency
Asked Answered
C

3

19

I am making this C++ program that has buttons, button containers, chat boxes, etc., and I want to wrap it around by textures.

I want to generate a smooth edge for all the rectangles I made, and I don't want vertex plotting method to do the work for it, since it consumes more CPU usage and not that looks pretty good, and I don't know if it can work with texture coordinates(i.e. glTexCoord(u, v) with glVertex2f(x, y) w/c should only be 4 since it is a quad)

I use to load textures using SDL_LoadBMP() w/c can load only a format of .bmp.(I'm not that sure because it says only LoadBMP there).

So my questions are:

  • can a .bmp format handle transparency? if so, how to do it?

  • can you show me some code samples using SOIL to load image of format .gif or any other formats that can handle image transparency?

  • can a quad handle an irregular/polygons shape like hexagon or star without drawing its background?

additional question

*how to import a primitive textbox that renders through c++ opengl so I can copy the texts there into clipboard? as for chatting session in my program.


I made my own library that draws the text using GL_POINTS and doesn't look good when resizing the window because the points were spread-out. It takes const char* for the text to avoid #include <*string*> because I want my program to be not dependent on core functions of C++.

So the better solution is to draw it using bitmaps.

Some suggest to draw it using images so I really need the transparency thing because I want it to draw using quad only.

Crosslet answered 7/1, 2013 at 11:47 Comment(0)
M
18

Yes, the bitmap format does support transparency.

It depends on the compression method, the default RGB method supports 24-bit color, but BITFIELDS compression supports 32-bit color (24-bit + alpha channel).

You can read more at http://en.wikipedia.org/wiki/BMP_file_format

I am using it successfully in the Lime project, here is an implementation written in Haxe: https://github.com/openfl/lime/blob/4adb7d638d15612e2542ae3a0ef581a786d21183/src/lime/_internal/format/BMP.hx

Marxmarxian answered 12/4, 2015 at 3:43 Comment(0)
I
1

This answer only addresses whether a bmp file can handle transparency, and how to load a png file using SOIL, and I think if you look further by inference it shows you how to load a gif file also. According to this wikipedia article, bmp is one file type that supports transparency through an alpha channel. But according to this SO article it doesn't. In my own experience I have not found a way to make bmp transparency work. So theoretically 32bit bmp files are supposed to support transparency, but I doubt it. (Maybe I will eat my words?)

Ok, from the SOIL website, this code tells how to load a png file which handles transparency:

/* load an image file directly as a new OpenGL texture */
 GLuint tex_2d = SOIL_load_OGL_texture
 (
       "img.png"
       SOIL_LOAD_AUTO,
       SOIL_CREATE_NEW_ID,
       SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB |
       SOIL_FLAG_COMPRESS_TO_DXT
 );
Introversion answered 7/1, 2013 at 12:5 Comment(2)
I have found a tutorial site here that showing how to add an alpha channel on a bmp image using a photoshop. My bmps were in 24bpp so it has no alpha channel on it. I don't try converting it to 32bpp yet. Also I have found out that my mipmap function have not the parameters of RGB + A w/c is the alpha (RGBA) , so I'm still have many options to do. In your code sample, how can I determine the dimensions of the images (w, h)? does SOIL have that function to automatically calculate it?Crosslet
also how to determine the size of the buffer to be pass on the last parameter of gluBuild2DMIPMaps ? I have seen some of those but I don't get the idea there unsigned char* data = (unsigned char*) malloc(w * l * 4); and that data is to be put on type of void*(?) I'm confused. I also need to know all the requirements to load an image. thnxCrosslet
C
0

BMP transparency is possible in Photoshop, with a 24 bits depth, at least. It doesn't appear as an option of "imwrite" in Matlab.

Curbstone answered 11/5, 2014 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.