Alpha blending problems
I am trying to add a particle system to my game engine, but it''s not going so well. I am using TGAs for the textures on particles, but the texture does not seem to be applied. Here''s my code:
void CBubbles::Render()
{
// enable alpha blending and texturing
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glDepthMask(GL_FALSE);
// set the blend mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
// get modelview matrix
float mat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
// for billboarding
CVector right(mat[0], mat[4], mat[8]);
CVector up(mat[1], mat[5], mat[9]);
// select the bubble texture
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// to avoid constant dereferecning...
CVector partPos;
float size;
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
// draw the quads
glBegin(GL_QUADS);
for(int i = 0; i < m_numParticles; ++i)
{
partPos = m_particleList.m_pos;
size = m_particleList.m_size;
glTexCoord2f(0.0, 0.0); glVertex3fv((partPos + (right + up) * -size).array);
glTexCoord2f(1.0, 0.0); glVertex3fv((partPos + (right - up) * size).array);
glTexCoord2f(0.0, 1.0); glVertex3fv((partPos + (right + up) * size).array);
glTexCoord2f(1.0, 1.0); glVertex3fv((partPos + (up - right) * size).array);
}
glEnd();
glDisable(GL_BLEND);
glDisable(GL_ALPHA);
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE);
}
The texture for this part of the particle system is a blank tga that just has an alpha channel. This code worked in another example program i made, but now its failing. When I run the code, I just get colored quads, instead of quads with an alpha blended quads. The texture isnt being applied. Can someone help me out? Thanks. </i>
// get modelview matrix
float mat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
I get the matrix once per frame, just after camera positioning, for billboarding and camera movements.
glBindTexture(GL_TEXTURE_2D, m_texture);
How sure are you that the texture loaded?
glTexCoord2f(0.0, 0.0); glVertex3fv((partPos + (right + up) * -size).array);
glTexCoord2f(1.0, 0.0); glVertex3fv((partPos + (right - up) * size).array);
glTexCoord2f(0.0, 1.0); glVertex3fv((partPos + (right + up) * size).array);
glTexCoord2f(1.0, 1.0); glVertex3fv((partPos + (up - right) * size).array);
Is there a reason why you are drawing the quad texcoords in a Z shape vs a box?
The texture for this part of the particle system is a blank tga that just has an alpha channel.
what do you mean by blank? Is this why there is no texture? in modulate mode the final frag color is glcolor*texcolor.
This code
worked in another example program i made, but now its failing. When I run the code, I just get colored
quads, instead of quads with an alpha blended quads. The texture isnt being applied.
What if you loaded a real image w/ rgb and a?
zin
zintel.com - 3d graphics & more or less
float mat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
I get the matrix once per frame, just after camera positioning, for billboarding and camera movements.
glBindTexture(GL_TEXTURE_2D, m_texture);
How sure are you that the texture loaded?
glTexCoord2f(0.0, 0.0); glVertex3fv((partPos + (right + up) * -size).array);
glTexCoord2f(1.0, 0.0); glVertex3fv((partPos + (right - up) * size).array);
glTexCoord2f(0.0, 1.0); glVertex3fv((partPos + (right + up) * size).array);
glTexCoord2f(1.0, 1.0); glVertex3fv((partPos + (up - right) * size).array);
Is there a reason why you are drawing the quad texcoords in a Z shape vs a box?
The texture for this part of the particle system is a blank tga that just has an alpha channel.
what do you mean by blank? Is this why there is no texture? in modulate mode the final frag color is glcolor*texcolor.
This code
worked in another example program i made, but now its failing. When I run the code, I just get colored
quads, instead of quads with an alpha blended quads. The texture isnt being applied.
What if you loaded a real image w/ rgb and a?
zin
zintel.com - 3d graphics & more or less
By blank I mean just white. I think someething is messing up the binding of the texture. I know the texture is being loaded. As for the Z pattern of texturing that was a mistake I made, but the alpha problem still exists. Heres the code for loading the texture:
Texture texture;
bool tgaFileToLoad = TRUE; // toggle TGA or BMP
// get a texture object
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture); // enables the texture object.
// the following fucntions affect the
// texture specified by the 2nd parameter
if (tgaFileToLoad)
{
LoadTGA(&texture, "sparky.tga");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
//MessageBox(NULL, "Texture is Loaded", "Textures",MB_OK | MB_ICONEXCLAMATION);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, texture.imageData);
// we''re done with the TGA data
free(texture.imageData);
I think something else in my program is messing up my binding or something. What kind of commands could cause conflicts?
Texture texture;
bool tgaFileToLoad = TRUE; // toggle TGA or BMP
// get a texture object
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture); // enables the texture object.
// the following fucntions affect the
// texture specified by the 2nd parameter
if (tgaFileToLoad)
{
LoadTGA(&texture, "sparky.tga");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
//MessageBox(NULL, "Texture is Loaded", "Textures",MB_OK | MB_ICONEXCLAMATION);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, texture.imageData);
// we''re done with the TGA data
free(texture.imageData);
I think something else in my program is messing up my binding or something. What kind of commands could cause conflicts?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement