Cluebie lwjgl question

Actually it more a general ogl question.

What I’m trying to do is draw a 2d textured quad to the screen. should be simple…

The problem I am having, which I’m sure is cos I’ve missed somthing obvious, is that when I draw on quad over the other one, I want to just see the shape of the picture and I don’t.

What i seem to be able to do is draw one image on top of the other but with the transparent bit darwing black, or loose the transparent bit (what I want to do) but it also blends the images together (which I don’t want to do). Does this make any sense? I’m just wanting to draw a sprite.

I’m using a png for my texture which I’m using DevIL to load (as per nehe lessono6 port) my test rendering code is:


glPushMatrix();
            
            glEnable(GL_BLEND);
            glDisable(GL_DEPTH_TEST);
            
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            texture.bind();
            
            glBegin(GL_QUADS);
                  glVertex2f(50.0f, 50.0f);
                  glTexCoord2f(0.0f, 1.0f);
                  glVertex2f(100.0f, 50.0f);
                  glTexCoord2f(1.0f, 1.0f);
                  glVertex2f(100.0f, 100.0f);
                  glTexCoord2f(1.0f, 0.0f);
                  glVertex2f(50.0f, 100.0f);
                  glTexCoord2f(0.0f, 0.0f);
            glEnd();
            
            glTranslatef(10f, 10f, 0f);
            glBegin(GL_QUADS);
                  glVertex2f(50.0f, 50.0f);
                  glTexCoord2f(0.0f, 1.0f);
                  glVertex2f(100.0f, 50.0f);
                  glTexCoord2f(1.0f, 1.0f);
                  glVertex2f(100.0f, 100.0f);
                  glTexCoord2f(1.0f, 0.0f);
                  glVertex2f(50.0f, 100.0f);
                  glTexCoord2f(0.0f, 0.0f);
            glEnd();
                        
            glPopMatrix();

and just before this I’m clearing the colour and depth buffers. Any ideas?

Cheers,
Dan.

edit slight typo

  1. Make sure the image you’re loading is actually RGBA!
  2. Make sure that when you glTexImage2D with it that you specify its src. and dest. formats as being GL_RGBA
  3. Use GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA for sprites.

Cas :slight_smile:

Methinks you want regular weighted transparency, which would be:
glBlend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Your current blend does a kind of additive blend which means you’ll see the two sprites combined together when they overlap.

Edit: Heh, too slow. Incidentally you don’t ever seem to set the current vertex colour. Unless you’re really sure you probably want to set it to 0xFFFFFFFF before doing any sprite rendering stuff.

No need, he’s using GL_REPLACE texture env mode.

Cas :slight_smile:

Thank you both for your replies, I’ll try your suggestions when I get chance.

Cheers,
Dan.

edit typo’s

Thanks that worked for my original image.

Now I’ve just got to work out why DeviIL creashes native side on some images… Probably better go and read the docs when I have time.

Dan.

Put all data for the next vertex before the vertex:


                  glColor3f(1,1,1); // color for next
                  glTexCoord2f(0.0f, 0.0f); // texcoord for next
                  glVertex2f(50.0f, 100.0f); // last, the vertex

Thanks for letting me know that, I was thinking that it would make more sense that way, but it seemed to work on my little test app :wink:

Cheers,
Dan.