Rendering 32-bit images - alpha is ignored

This is a discussion on Rendering 32-bit images - alpha is ignored within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by ulillillia Of course I know that, but some functions, like alpha blend, will not work when height ...

  1. #46
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by ulillillia View Post
    Of course I know that, but some functions, like alpha blend, will not work when height is negative. The main thing is that it matches BMP files which otherwise helps keep the consistancy in style and retain maximum support. If I want bottom-up coordinates instead of top down (as most graphics edittors use), just take the image height, then subtract the coordinate and 1 extra. The coordinate (0, 255) on a 256x256 image is the bottom left pixel. 256 minus 255 gives 1 but the actual position is 0. It's simple math at about the 4th grade level.
    Um, I know that. Didn't know that some functions couldn't work with top-down bitmaps. Sounds like those functions are badly broken.

  2. #47
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    As I explained you don't need to specify a color table of 1 entry (not that useful), so you don't need RGBQUAD.

  3. #48
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158

    Talking found something lol

    Looking again at your Massive Reply, it seems you call InitializeDrawing before loading the targa file. So you try to create a bitmap with no bitmap data and an uninitialized BITMAPINFOHEADER.
    (Note that when you create a HBITMAP, the pixel data your pointer points to is copied, so you can't use your own pointer to change the data later on.)
    Am I right?
    Last edited by pronecracker; 04-18-2007 at 12:43 PM.

  4. #49
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    If I don't include RGBQuad, then AlphaBlend fails because the bitmapinfo thing has something uninitialized. If I do include it, then I just get compiler errors (cannot convert along with some others). You're saying I don't need it, but there's an uninitialized value if I don't include it. Please explain what I need to do.... You're only giving conflicting information.

  5. #50
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by ulillillia View Post
    If I don't include RGBQuad, then AlphaBlend fails because the bitmapinfo thing has something uninitialized.
    So initialize it. Set it to NULL. The documentation clearly says this.

  6. #51
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Quote Originally Posted by ulillillia View Post
    Of course I know that, but some functions, like alpha blend, will not work when height is negative.
    Not if you try to mirror it vertically while drawing, by passing a negative height. But you can mirror it while creating a bitmap. For example, you can pass a negative height to CreateDIBitmap() to specify that the bitmap is top-down. That works fine.

  7. #52
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Hey maybe you could just read my post and tell if I found the bug?

    I'm not giving conflicting information. I explained what the RGBQUAD[1] is for, and then I told you that you don't need it. In post #36 I gave you an example from my code, in which I implicitly set the RGBQUAD stuff to 0.
    Last edited by pronecracker; 04-18-2007 at 01:02 PM.

  8. #53
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Yes, it's working now and I calculated the resulting color displayed (after snagging a screenshot) and it is exactly what I'm expecting it to be. I ran my alpha transparency formula with the original on the background and the colors were off by fractions and rounding them gives identical values. I wonder what the premultiplication is used for and why it's needed.... Maybe for simplification of the formula (as, looking at my formula there, it's a little lengthy).

    Yes, it was the placement of InitializeDrawing that messed things up. I moved it by using copy paste then commented out the original and it then worked. Yay! Now let's see if I can do the hills correctly which also has alpha. The bitmap font will be more complex since it gets cropped out with random amounts (for each character). I know how to get the character and location needed, cropping the image would be new. I'll try figuring that out on my own but if I'm unable to resolve it for some reason, then I'll ask about it again. Thanks for the assistance.

  9. #54
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Yeah, finally, victory!! Pretty simple solution, actually.

  10. #55
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    I also noticed I misplaced the "initialize object positions" function. The two merely needed to be switched around. I've added the fog (and had a bug since I forgot to declare a char as unsigned then I had a copy paste mistake where I forgot to fix the array. The mountain's scaling is 1125 (exactly 10 miles distance) and the visibility is 1350 (exactly 12 miles). The fog now works exactly as expected. Yep, I've got the formula for fog as well, another derivative of the fundamental color-averaging formula. Next up, the hills (of which have a scaling of 900 (exactly 8 miles).

  11. #56
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Great, it does not look hard at all to understand, your fog thing, if I'd only know what those words mean.

  12. #57
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    What are you confused about with the fog? The formula? What the fog does? I'm figuring out text displaying which uses AlphaBlend. I'm only having trouble getting wordwrap working right (infinite loops - oy!). The text stuff is a more complex usage of AlphaBlend. Everything is now working outside the text.

  13. #58
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    I only meant that I wouldn't know what BC, PDIST or VIS are.

  14. #59
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    BC - base color (the color without fog)
    FG - fog color (the color of the fog at maximum intensity)
    DIST - the object's distance (the more distance, the stronger the effect the fog has)
    VIS - visibility (the distance at which fog has it's maximum effect).
    MCOL - the resulting color, of which is displayed.

    This screenshot shows the fog in my program. The visibility is 1350. The mountains have a scaling of 1125 making them 5/6 that of the fog color. The hills up closer have a scaling of 900 making them 2/3 that of the fog color. The houses have 3 making them almost unaffected by fog.

    Edit: left out the MCOL variable
    Last edited by ulillillia; 04-20-2007 at 11:28 AM. Reason: left out details

  15. #60
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Ok thanks for that information, maybe I could use that some day.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit color depth bitmap problem with XP
    By kalabala in forum C++ Programming
    Replies: 0
    Last Post: 12-22-2008, 05:56 AM
  2. binary numbers
    By watshamacalit in forum C Programming
    Replies: 4
    Last Post: 01-14-2003, 10:06 PM
  3. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 06:24 AM
  4. 32 bit or 16 ???
    By GiraffeMan in forum C Programming
    Replies: 11
    Last Post: 04-24-2002, 12:56 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21