Jump to content
  • Advertisement
Sign in to follow this  
Extremo

OpenGL Opengl blending?

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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, &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.images...englproblem.png

Thanks in advance!

EDIT:

Found the solution! It lies in me using 3 as internal format on glTexImage..

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!