Log in or register to post comments

Black texture on Android 2.2 devices

May 22, 2012 - 4:05am #1

Hello,

I took the sample project FrameMarkers as basis for my changes. My goal is to use a transparent texture to hide an object behind it but on some devices which run with Android 2.2 or 2.3.6 the texture is always black. It's not possible to load a transparent or a normal texture for one of the two new objects I use. I even tried to apply the texture of a letter to it, without success.

I used the obj2OpenGL Perl script to add two simple objects (cylinder and arrow) which are shown when the marker with id 4 is recognized. The texture for each of them is very simple: A picture with a simple green or blue pattern. Each image has 64x64 pixels and is saved as png in the assets folder. I changed the loadTextures() method to load the new images:

private void loadTextures()
{
        mTextures.add(Texture.loadTextureFromApk("letter_Q.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("letter_C.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("letter_A.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("letter_R.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("arrow.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("cylinder.png", getAssets()));
}

and left the initRendering function in c++ as it was.

For the arrow the variables vertices, normals, ... are used and for the cylinder vertices2, normals2 , ... are used. The cylinder has its own matrices to handle each of them differently.

Here are some parts of the renderFrame() function:
Addition to switch statement:

case 4:
	vertices = &arrowVerts[0];
	normals = &arrowNormals[0];
	texCoords = &arrowTexCoords[0];
	numIndices = arrowNumVerts;
	vertices2 = &cylinderVerts[0];
	normals2 = &cylinderNormals[0];
	texCoords2 = &cylinderTexCoords[0];
	numIndices2 = cylinderNumVerts;
	break;

And the OpenGL calls:

if (marker->getMarkerId() == 4) {
	// cylinder

	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, vertices2);
	glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, normals2);
	glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE,
						  0, texCoords2);

	glEnableVertexAttribArray(vertexHandle);
	glEnableVertexAttribArray(normalHandle);
	glEnableVertexAttribArray(textureCoordHandle);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID + 1);
	glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
				   (GLfloat*)&modelViewProjection2.data[0]);

	glDrawArrays(GL_TRIANGLES, 0, numIndices2);
	glDisable(GL_BLEND);
}

// arrow and letters
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, normals);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE,
					  0, texCoords);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
			   (GLfloat*)&modelViewProjection.data[0]);

if (marker->getMarkerId() == 4) {
	glDrawArrays(GL_TRIANGLES, 0, numIndices);
} else {
	glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, indices);
}

On a Galaxy S2 9100G (Android 2.3.6) only the arrow has a texture and the cylinder is black. On a HTC One V (Android 4) or on a Galaxy S Plus (Android 2.3.6) both objects have their texture and none appears black. Does anyone have an idea what the problem is?

Log in or register to post comments