0

I have a textured object in my OpenGL ES scene (version 1.1) for which I want to change the alpha to 0.5.

I am trying the following code :

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND); 
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0, 1.0, 1.0, 0.5);

glVertexPointer(3, GL_FLOAT, 0, vertexes);
glNormalPointer(GL_FLOAT, 0, normals);
glTexCoordPointer(2, GL_FLOAT, 0, textures);

GLfloat ambientAndDiffuse[] = kAmbience;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ambientAndDiffuse);
GLfloat specular[] = kSpecular;
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, kShininess);
GLfloat emission[] = kEmission;
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);

glDrawElements(GL_TRIANGLES, vertexCount, GL_UNSIGNED_SHORT, indices);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_BLEND);

The problem is that the transparency of the model is not changing. The model is displayed on the screen correctly, however the alpha is still 1.

EDIT

My textures are jpgs. Do I need to save these as PNGs ?

Can anyone spot how I can correct this ?

Thank you.

GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113

2 Answers2

1

Ah think I've solved it - you need to turn off the lighting and then it seems to work.

glDisable(GL_LIGHTING);

GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
0

Have you set the texture environment variable to modulate? Like this:

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

That tells OpenGL to multiply the object's color by the texture's color. Also, I don't remember if you need to use a GL_COLOR_ARRY with glDrawElements() instead of just setting the current color.

user1118321
  • 25,567
  • 4
  • 55
  • 86