OpenGL and 2D Masking

This is a discussion on OpenGL and 2D Masking within the Game Programming forums, part of the General Programming Boards category; I created a 2D demo a while ago. It was pretty simple with just a sprite walking around. To make ...

  1. #1
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283

    OpenGL and 2D Masking

    I created a 2D demo a while ago. It was pretty simple with just a sprite walking around. To make him transparent, I had to use a seperate sprite map that was black. I am assuming this is called masking. I got use to DirectDraw/Direct3D's way of doing 2D. There was no "seperate image," as it was an offscreen surface. I would just tell it not to blit a certain color to the back buffer. It did the trick. Is there anything like that in OpenGL? I'd hate having two seperate images just in hope for transparency purposes.

  2. #2
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    You can use blending. If you have, say a png file with an alpha channel, then you can:
    Code:
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE );
    But if the images overlap you get weird colors, so to get rid of that you have to use masking still.

    I'm not really sure what I'm talking about, but I hope that was what you meant.

    David

  3. #3
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    In The Gimp, I remember you can set a transparent color to an image. If that's predetermined, and you load the image into the program, would a masking image now be unncessary?

  4. #4
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    That will make the image transparent if you use blending, but to make sure the images overlap properly, you have to use masking. NeHe has some tutorials over blending and masking, if you haven't already checked them out.

    Here in the game I'm working on, you can see what can happen if you don't mask an image.
    http://i14.photobucket.com/albums/a3...tions-As-1.png
    See how the asteroids overlap.

  5. #5
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Wow, that's just incredibly annoying I tried PNG, tried my theory, and it didn't turn out nice. I guess I'm just use to working with directx surfaces. OpenGL seems to have another take on this. I always hated masking because if I make one change in the art, I have to remember to do it for the mask.

  6. #6
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    I came across this small PNG library... it uses no masking
    http://www.coolgroups.com/alpha/

  7. #7
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Hmm, cool library. Did you remember to use the function
    glBlendFunc(GL_SRC_ALPHA, GL_ONE); ?

    Because that one works for me.

  8. #8
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Am I stuck with masking though? I just find it really annoying. I don't know why OpenGL can't just ask what the RGB color is to ignore, and it would draw the image without that color.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-22-2006, 03:39 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  3. Adding 2D graphics in OpenGL
    By Da-Nuka in forum Game Programming
    Replies: 7
    Last Post: 04-05-2005, 02:26 PM
  4. OpenGL DirectX 2D
    By c++.prog.newbie in forum Game Programming
    Replies: 11
    Last Post: 03-01-2005, 12:54 PM
  5. 2D Programming in OpenGL
    By guyver137 in forum Game Programming
    Replies: 2
    Last Post: 01-18-2003, 02:31 PM

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