OpenGL: Overlay one texture over another and suppress white background

I am a starter of Iphone opengl ES programming. I have two textures, the first one is the background and occupies the full screen. I am printing the second picture on top of the first image but the white background of the second image covers part of the background. I want the background to be visible where the foreground picture has no color(or White). I am unable to figure out how to use the glBlendFunc correctly.

before printing the second image I am using Blending with following:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

Images at: http://www.flickr.com/x/t/0097002/photos/vjv2010/

--------------Solutions-------------

I want the background to be visible where the foreground picture has no color(or White).

You have two choices, the simplest one is to use alpha testing and add an alpha channel for your foreground image so that each white pixel (or no color zones) has a special value, let' say 0.0f and all other 1.0f.

Then when rendering the foreground you enable alpha testing with glEnable(GL_ALPHA_TEST) and set alpha function with glAlphaFunc(GL_GREATER, 0.5f) This will accept/draw only fragments that have an alpha value greater than 0.5f and discard/not draw all fragments that have an alpha value less than 0.5f.

Second choice is to use blending as you did, but you will need also to add extra alpha channel to your foreground and set glBlendFunc properly.

More here: http://iphone-3d-programming.labs.oreilly.com/ch06.html

Category:opengl es Time:2010-06-25 Views:1

Related post

  • How OpenGL handles the texture border when using GL_REPEAT? 2010-08-25

    I understand that GL_REPEAT parameter will ignore the integer portion of the texture coordinate, only the fractional part is used when doing texture mapping. The question is how OpenGL handles the texture border? For instance, if the texcoord is 2.0,

  • MonoTouch OpenGL app loses texture data when moved to background 2011-01-19

    I have a MonoTouch OpenGL app that has a bunch of textures. When the user hits the iPhone button to move the app to the background, all my texture data seems to go away. I just see a solid color filling the triangles that I'm drawing with the texture

  • opengl overlay on camera view 2012-01-24

    I still haven't found a proper way to show an opengl overlay oon top of camera preview, There's a hack, where you call setContentView(GLSurfaceView) addContentView(MyCameraSurfaceView) but it doesn't work properly - i.e. when you switch to anouther a

  • How do I get a colored texture brush to show up in Open GL ES on white background? 2009-09-14

    I want to draw with a texture brush, in a color of my choice, on a white background using OpenGLES. I have a bitmap image which I use CG to load and turn into a texture. This bitmap is mostly black, but has a white circle in the center that I want to

  • OpenGL paint program based on Apple's 'glPaint' on a white background - how to blend? 2010-05-08

    Trying to write a simple paint program for iPhone, and I'm using Apple's glPaint sample as a guide. The only problem is, painting doesn't work on a white background, since white + colour = white. I've tried different blending functions, but haven't b

  • How to overlay an element without white background image 2011-12-24

    I'm using this jQuery code for overlay $("a[rel]").overlay({ top: '24%' , mask: { color: '#0f0f0f', loadSpeed: 200, opacity: 0.9 }, closeOnClick: false , effect: 'apple', onBeforeLoad: function() { var wrap = this.getOverlay().find(".contentWrap"); w

  • Best way to suppress OpenGL ES (iPhone) texture / OpenAL sounds memory footprint? 2010-10-23

    What should i do? I have some 512x512 png. I compressed them to PVR (which results terrible quality), and I'm preparing to compress the PNGs with pngcrush tool. The PVRs have about 2x-x larger filesize than the PNGs, maybe I can experiment with JPG f

  • OpenGL and monochrome texture 2008-11-29

    Is it possible to pump monochrome (graphical data with 1 bit image depth) texture into OpenGL? I'm currently using this: glTexImage2D( GL_TEXTURE_2D, 0, 1, game->width, game->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, game->culture[game->

  • Which version of OpenGL supports rectangular textures (w/o extensions)? 2009-09-04

    Rectangular textures used to be support through extensions and at some version of OpenGL are now directly supported, i.e I can create textures with the same basic opengl methods just supplying non-power-of-two sizes. I've googled and can't seem to fi

  • Android OpenGLES Render-to-Texture 2009-11-11

    I write graphics apps for the iPhone and I'm looking to port my most recent app, 'Layers,' to the Android platform. Layers is painting app that allows users to draw on the screen and create multi-layered paintings with different brushes, colors, etc.

  • OpenGL ES multi-texture alpha blending question 2009-12-23

    This maybe a noob question, however, I haven't been able to find a suitable answers: I have an object in OpenGL ES (in fact, an UV mapped export from Blender) and I'd like to apply two textures to it. To be precise, I have a earth-like sphere and I w

  • OpenGL Threaded Tile Texture Loading with Qt 4.5 / 4.6 2010-01-21

    I am trying to develop am map application for scientific purposes at my university. Therefor I got access to a lot of tiles (256x256). I can access them and save them to an QImage in a seperate QThread. My Problem is, how can I actually manage to loa

  • OpenGL ES set Texture matrix for different Texturing units 2010-01-29

    with glMatrixMode(GL_TEXTURE); ..some matrix operations... i can change the current texture transformation matrix. However - it seems it affects not all texture units (i'm using multitexturing) how can i change the texture matrix for different textur

  • OpenGL "overlaying" two renderings 2010-02-15

    Exposition: 1) My viewport is 800x600 2) I have tex1 = frame buffer object; rendered to a texture, 800x600 3) I have tex2 = frame buffer object; rendered to a texture, 800x600 Now, I want to create the following image on the screen: tex1 _on top of_

  • Opengl problem with texture in model from obj 2010-05-25

    I writing small program in OpenGL, and I have problem ( textures are skew, and I dont know why, this model work in another obj viewer) What I have: http://img696.imageshack.us/i/obrazo.png/ What I want http://img88.imageshack.us/i/obraz2d.jpg/ Code o

  • Opengl: use a texture only to give alpha channel to a colored object 2010-06-11

    I'm new at OpenGL and I can't find out how to do this: I want to render a letter and be able to change it's color, so I have a texture with the letter on a transparent background. I managed to render it using this code: glEnable(GL_BLEND) glBlendFunc

  • Can OpenGL ES render textures of non base 2 dimensions? 2010-09-18

    This is just a quick question before I dive deeper into converting my current rendering system to openGL. I heard that textures needed to be in base 2 sizes in order to be stored for rendering. Is this true? My application is very tight on memory, bu

  • Android OpenGL ES Multiple Textures for one rect 2010-11-01

    In Android OpenGL ES, I want to be able to switch textures for a given Rectangle. I have one rect and I put two textures, depending on different conditions. I just want to switch between textures. I followed this code to create the textures: link tex

  • OpenGL ES black texture on Nexus S 2011-01-24

    OpenGL code that works on the Nexus One will not work properly on the Nexus S. Textures don't seem to render and I'm left with just black where textures should be. Anyone got any ideas? --------------Solutions------------- The accepted answer given h

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.571 (s). 13 q(s)