PDA

View Full Version : PNG Transparancy blending?



Extremo
08-07-2011, 06:36 AM
Oh well,

For the past 2 days I have been googling and reading as many tutorials as I possible can but it's time to say I am frustrated.

I am loading a picture with IMG_Load(a png) and I am pretty sure many of you have heard this before.

The problem I have however is that it does not care about the alpha channel. There simply is no transparacy. Might I say I work with 2D pictures. It simply has a white background and it's being very frustrating.

Here's my code:



void CSprite::Load (const string sFilename)
{
// Grafik laden
m_pImage = IMG_Load (sFilename.c_str () );

// Prüfen, ob alles glatt ging
if (m_pImage == NULL)
{
cout << "Fehler beim Laden von: " << sFilename.c_str ();
cout << endl;
cout << "Fehlermeldung: " << IMG_GetError () << endl;

// Framework herunterfahren
g_pFramework->Quit ();

// Gesamtes Spiel beenden
exit (1);
}
/*glLoadIdentity();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);*/
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &amp;m_pID);
glBindTexture(GL_TEXTURE_2D, m_pID);
glTexImage2D(GL_TEXTURE_2D, 0, 3, m_pImage->w, m_pImage->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pImage->pixels);
//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_pImage->w, m_pImage->h, GL_RGB, GL_UNSIGNED_BYTE, m_pImage->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, 0);
/*glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);*/
// Rect initialisieren
m_Rect.x = 0;
m_Rect.y = 0;
m_Rect.w = m_pImage->w;
m_Rect.h = m_pImage->h;

} // Load

void CSprite::Render ()
{
/*glLoadIdentity();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);*/
glBindTexture(GL_TEXTURE_2D, m_pID);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex3f(static_cast<GLfloat>(m_Rect.x)-m_Rect.w,static_cast<GLfloat>(m_Rect.y)-m_Rect.h,0.0f);
glTexCoord2f(1.0,0.0);
glVertex3f(static_cast<GLfloat>(m_Rect.x), static_cast<GLfloat>(m_Rect.y)-m_Rect.h,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(static_cast<GLfloat>(m_Rect.x), static_cast<GLfloat>(m_Rect.y),0.0f);
glTexCoord2f(0.0,1.0);
glVertex3f(static_cast<GLfloat>(m_Rect.x)-m_Rect.w,static_cast<GLfloat>(m_Rect.y),0.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
/*glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);*/
} // Render


Sorry for the German documentation. I really hope someone can point out what I am obviously not capable of finding out myself. I am very sorry to those who have seen this question a billion times, I really I am frustrated and appreciate ANY help.

Whenever I compile and run my game, this is the result I get:

http://img706.imageshack.us/img706/6262/openglproblem.png

Thanks in advance!

mfort
08-07-2011, 06:55 AM
You requested OpenGL to use RGB as the internal texture format (see number 3 in glTexImage2D call). You should ask for RGBA.



glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_pImage ...

Extremo
08-07-2011, 07:04 AM
You requested OpenGL to use RGB as the internal texture format (see number 3 in glTexImage2D call). You should ask for RGBA.



glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_pImage ...




Thank you!!!!!!!!!!!!!! Unbelievable easy mistake wow, 2 of my days gone! Your help was great! =)