   OpenGL + SDL + PNG + Transparency = :argh:
  I imagine this topic has come up a few times, so apologies if my googling missed the answer. Nevertheless...I'm trying to load a PNG with transparency and use it. I have the following test code in place:static unsigned int texture = 0;static SDL_Surface *pSurface = 0;if (texture == 0){pSurface = IMG_Load("test.png");if(!pSurface){cout << "Failed to load the image--Error: " << SDL_GetError() << endl;exit(1);}glPixelStorei(GL_UNPACK_ALIGNMENT,4);glGenTextures(1, &texture);glBindTexture(GL_TEXTURE_2D, texture);glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);SDL_PixelFormat *pFmt = pSurface->format;//if there is alphaif (pFmt->Amask){gluBuild2DMipmaps(GL_TEXTURE_2D, 4, pSurface->w, pSurface->h, GL_RGBA, GL_UNSIGNED_BYTE, pSurface->pixels);}else // no alpha{gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pSurface->w, pSurface->h, GL_RGB, GL_UNSIGNED_BYTE, pSurface->pixels);}if (pSurface){SDL_FreeSurface(pSurface);pSurface = 0;}}glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);CCamera::Instance()->Render();glBindTexture(GL_TEXTURE_2D, texture);glPushMatrix();glTranslatef(0, 0, -5);glColor4f(1, 1, 1, 1);glBegin(GL_QUADS);glTexCoord2i(0, 0);glVertex3f(-1, 1, 0);glTexCoord2i(1, 0);glVertex3f(1, 1, 0);glTexCoord2i(1, 1);glVertex3f(1, -1, 0);glTexCoord2i(0, 1);glVertex3f(-1, -1, 0);glEnd();glPopMatrix();glBindTexture(GL_TEXTURE_2D, 0);glPushMatrix();glTranslatef(0, 0, -10);glColor4f(1, 1, 1, 1);glBegin(GL_QUADS);glVertex3f(-5, 5, 0);glVertex3f(5, 5, 0);glVertex3f(5, -5, 0);glVertex3f(-5, -5, 0);glEnd();glPopMatrix();SDL_GL_SwapBuffers();And prior to that, in the init section,glEnable(GL_TEXTURE_2D);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);Basically, it draws a square with my texture on it, then a larger white square behind it so I can judge if transparency is working.However, when I run the program, I end up with the transparent parts of the PNG texture showing up as whatever current clearcolor I'm using, instead of showing up white against the white block.Can anyone explain what I've done wrong, and why it's interpreting transparent bits as "show the clearcolor" instead of "show what's behind me"?   
  Make sure that you are drawing the back object first.   ;Quote:Original post by Anonymous PosterMake sure that you are drawing the back object first.*sigh* It's always the bloody obvious things, isn't it.Thanks :)   