ProXicT

08-23-2013, 08:23 PM

Hello, World!

I'm developing a small game with my friend and we have a small but important problem.

We are trying to make transparency with 32-bit bitmap textures but not successfully. We think that the problem is in depth test or in blending, but we are beginners in OpenGL, so we can't solve this problem. Hope you can ;-)

Here is our coding of draw function:

void SC_OBJ::sDrawOBJ()

{

glTranslatef(0,0,-1.0f);

glEnable(GL_TEXTURE_2D);

//glDisable(GL_COLOR_MATERIAL);

glColor3f(1,1,1);

for(int drawed = 0; drawed < facenum; drawed++)

{

if(triangle[drawed].busemtl == true)

{

if(material[triangle[drawed].materialindex].bmap_d == true)

{

glDisable(GL_DEPTH_TEST); // Maybe here is our problem?

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

}

usetex = material[triangle[drawed].materialindex].map_Kd_index;

stexture[usetex].sUseTexture();

glEnable(GL_DEPTH_TEST);

}

glBegin(GL_TRIANGLES);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[0], triangle[drawed].ny[0], triangle[drawed].nz[0]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[0],triangle[drawed].t[0]);glVertex3f(triangle[drawed].vx[0], triangle[drawed].vy[0], triangle[drawed].vz[0]);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[1], triangle[drawed].ny[1], triangle[drawed].nz[1]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[1],triangle[drawed].t[1]);glVertex3f(triangle[drawed].vx[1], triangle[drawed].vy[1], triangle[drawed].vz[1]);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[2], triangle[drawed].ny[2], triangle[drawed].nz[2]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[2],triangle[drawed].t[2]);glVertex3f(triangle[drawed].vx[2], triangle[drawed].vy[2], triangle[drawed].vz[2]);

glEnd();

}

glDisable(GL_BLEND);

}

And here is a part from our texture loader:

glGenTextures(1, &uTEXTURE[0]);

glBindTexture(GL_TEXTURE_2D, uTEXTURE[0]);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 4, texturedata.width, texturedata.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturedata.imageData);

Here are a couple of screenshots to show, what exactly happens...

proxict.rajce.idnes.cz/OpenGL_screenshots#Screen0.jpg - This is not how it should look like...// in our scene

proxict.rajce.idnes.cz/OpenGL_screenshots#screen2.jpg - This is not how it should look like...// in our scene

proxict.rajce.idnes.cz/OpenGL_screenshots#Sniper0001.jpg - Rendered picture in Cinema 4D

proxict.rajce.idnes.cz/OpenGL_screenshots#Sniper2_0001.jpg - Another rendered picture in Cinema 4D

Thanks in advance...

I'm developing a small game with my friend and we have a small but important problem.

We are trying to make transparency with 32-bit bitmap textures but not successfully. We think that the problem is in depth test or in blending, but we are beginners in OpenGL, so we can't solve this problem. Hope you can ;-)

Here is our coding of draw function:

void SC_OBJ::sDrawOBJ()

{

glTranslatef(0,0,-1.0f);

glEnable(GL_TEXTURE_2D);

//glDisable(GL_COLOR_MATERIAL);

glColor3f(1,1,1);

for(int drawed = 0; drawed < facenum; drawed++)

{

if(triangle[drawed].busemtl == true)

{

if(material[triangle[drawed].materialindex].bmap_d == true)

{

glDisable(GL_DEPTH_TEST); // Maybe here is our problem?

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

}

usetex = material[triangle[drawed].materialindex].map_Kd_index;

stexture[usetex].sUseTexture();

glEnable(GL_DEPTH_TEST);

}

glBegin(GL_TRIANGLES);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[0], triangle[drawed].ny[0], triangle[drawed].nz[0]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[0],triangle[drawed].t[0]);glVertex3f(triangle[drawed].vx[0], triangle[drawed].vy[0], triangle[drawed].vz[0]);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[1], triangle[drawed].ny[1], triangle[drawed].nz[1]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[1],triangle[drawed].t[1]);glVertex3f(triangle[drawed].vx[1], triangle[drawed].vy[1], triangle[drawed].vz[1]);

if(normalnum > 0)glNormal3f(triangle[drawed].nx[2], triangle[drawed].ny[2], triangle[drawed].nz[2]);if(texcoordnum > 0)glTexCoord2f(triangle[drawed].s[2],triangle[drawed].t[2]);glVertex3f(triangle[drawed].vx[2], triangle[drawed].vy[2], triangle[drawed].vz[2]);

glEnd();

}

glDisable(GL_BLEND);

}

And here is a part from our texture loader:

glGenTextures(1, &uTEXTURE[0]);

glBindTexture(GL_TEXTURE_2D, uTEXTURE[0]);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 4, texturedata.width, texturedata.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturedata.imageData);

Here are a couple of screenshots to show, what exactly happens...

proxict.rajce.idnes.cz/OpenGL_screenshots#Screen0.jpg - This is not how it should look like...// in our scene

proxict.rajce.idnes.cz/OpenGL_screenshots#screen2.jpg - This is not how it should look like...// in our scene

proxict.rajce.idnes.cz/OpenGL_screenshots#Sniper0001.jpg - Rendered picture in Cinema 4D

proxict.rajce.idnes.cz/OpenGL_screenshots#Sniper2_0001.jpg - Another rendered picture in Cinema 4D

Thanks in advance...