Pasting an image with alpha mask on a texture

Member
Posts: 749
Joined: 2003.01
Post: #1
I have this big wall texture, and i want to paste on it some images with an alpha mask dynamically. To do this I found glTexSubImage2D, but unfortunately it replaces the whole rectangular area around the image, making the wall texture transparent where the image's pixels are transparent (while I'd like to keep the wall texture there)

What's an easy way to do this?

Thanks in advance.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
Are you certain you want to modify the wall texture? I'd instead draw the decal on top by drawing the quad twice. Once with the wall texture, and a second pass ( using glPolygonOffset ) with the decal texture and an appropriate blend mode.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #3
Hm, that would require one (small) quad for each decal (splat)? If so there might be too many (too much blood Rasp).

If nothing i think i can blit the image on the SDL surface of the texture, then get the small rectangle that has changed and pass it back in the opengl texture with glTexSubImage2D.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #4
You could accumulate the blood using two FBOs, ping ponging back and forth rendering the new blood over what was there previously. Would be much faster than doing it on the CPU in RAM.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #5
Hm thanks reubert, I'm still a opengl newbie, I didn't know about FBOs.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #6
this might be a good place to start:
http://www.gamedev.net/reference/article...le2331.asp

and in your situation it would be something like:
Code:
startup()
{
    bindFrameBuffer(fboa)
    renderWallInitialTextureToFBOQuad()
    unbindFrameBuffer(fboa)
    currentFBOTexture = fboa.texture
}

eachBloodAdd()
{
    bindFrameBuffer(fbob)
    renderWallToFBOQuadWithCurrentWallTexture(fboa.texture)
    renderBloodOnTopOfFBOQuad()
    unbindFrameBuffer(fbob)
    
    currentFBOTexture = fbob.texture
    
    swap(fbob, fboa)
}

eachFrame()
{
    renderWallTextureToMainOutputGeometryWithWallTexture(currentFBOTexture)
}

The main advantage being that everything is always in VRAM. You can also really easily rotate, color or scale your blood texture before rendering it over the wall, or use shaders to tweek the output even more.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #7
Thanks for your help, I think i might have it working (after hours of blood (mine)).

I'm a bit worried about compatibility, but then again I can always go back to the other method.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #8
Najdorf Wrote:I'm a bit worried about compatibility...

I wouldn't worry too much about compatibility. With OpenGL, by the time you've figured out how to be more compatible, most of it (the older hardware) is already dead and gone. Fill in the users that it doesn't work for later, if needed. It is vastly more important that it works for you first.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
Apple supports FBOs on NVIDIA GeForce 5200 and better, and ATI Radeon 9500 and better from 10.4.3 (or thereabouts). There are reasonable fallbacks (PBuffers and off-screen windows) for older OSes and hardware back to 10.2 and Rage 128.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #10
I woke up in the middle of the night all worried because I realised you could do it with one FBO. Just don't clear the color buffer and keep rendering blood over the top. Duh!

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #11
reubert Wrote:I woke up in the middle of the night all worried because I realised you could do it with one FBO. Just don't clear the color buffer and keep rendering blood over the top. Duh!

Yeah that's what I did really, sorry for not telling you Rasp

Still I'm not completely happy with the results, maybe i have to make a better splat texture :/

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Edge detection with sobel operator/mask g00se 5 10,770 May 20, 2011 12:23 AM
Last Post: g00se
  alpha not working in SDL image NSDuo 7 4,107 Feb 9, 2008 11:28 PM
Last Post: NSDuo
  Create texture from NSOpenGLContext image Wong4 3 4,446 Sep 29, 2007 02:42 PM
Last Post: OneSadCookie
  Using 8-bit greyscale texture as an alpha channel? TomorrowPlusX 12 4,904 Apr 10, 2006 08:43 AM
Last Post: TomorrowPlusX
  Changing the Mask in OpenGL kodex 2 3,791 Jan 18, 2006 09:21 PM
Last Post: kodex