views:

300

answers:

2

I'm using C++ and OpenGL to make a basic 2D game, I have a png image with transparent areas for my player. It works perfectly on my laptop and lab computers, but on my desktop the entire image is mostly see through, not just the areas that are meant to be. What could cause/fix this?

Here is the code I've used and is the same on all machines

glPushMatrix(); 
glEnable(GL_TEXTURE_2D);    
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, playerTex);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glTranslatef(XPos, YPos, 0.0);
glRotatef(heading, 0,0,1);
    glBegin(GL_POLYGON);
        glTexCoord2f(0.0, 1.0); glVertex2f(-40,40);
        glTexCoord2f(0.0, 0.0); glVertex2f(-40,-40);
        glTexCoord2f(1.0, 0.0); glVertex2f(40,-40);
        glTexCoord2f(1.0, 1.0); glVertex2f(40,40);
    glEnd();

glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
A: 

Does setting glColor4f(1,1,1,1) help? (I can't remember if GL_REPLACE is affected by vertex color)

Check glGetError() at appropriate places to see if you're not doing anything really wrong.

Other generic tips:

  • try to lock down all loose ends of the render state.
  • make sure your PNG-read lib works correctly everywhere. (create texture data in code otherwise)
  • It might be hardware related, and then it helps if you list the OS:es and CPU types/drivers.
  • I'm assuming you're running the same executable on all computers?
Marcus Lindblom
GL_REPLACE means replace the vertex color (more exactly, the previous stage output), so no, it's not affecting it.
Bahbar
I tried the glGetError() not getting anything from thatOS: Win 7 32bit and in lab vista 64bitCPU: on desktop is Intel E6600, some other core 2 duo on laptopGraphics: on desktop ATI Radeon X1900, laptop Intel Integrated
Chris
A: 

I found the problem, I changed

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

to

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

and it works correctly, not sure why though.

Chris
Because mipmaps are not more automatically built?
Luca