Log in or register to post comments

Problems with renderFrame in Nexus devices

April 14, 2015 - 8:35am #1

Hi all.

I'm trying to replace the teapot with a png image when the program finds the target.

 

Here's the code I use:

 

private void renderFrame() {

		State state = mRenderer.begin();
		mRenderer.drawVideoBackground();
		if (Renderer.getInstance().getVideoBackgroundConfig().getReflection() == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
			GLES20.glFrontFace(GLES20.GL_CW); // Front camera
		else
			GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

		if (state.getNumTrackableResults() == 0)
			displayMessage("nothing");
		// did we find any trackables this frame?
		for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {

			TrackableResult result = state.getTrackableResult(tIdx);
			Trackable trackable = result.getTrackable();
			ImageTarget itarget = (ImageTarget) trackable;

			Log.d("USER", itarget.getName());
			Matrix44F modelViewMatrix_Vuforia = Tool
					.convertPose2GLMatrix(result.getPose());
			float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();
			float[] modelViewProjection = new float[16];
			Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f,
					OBJECT_SCALE_FLOAT);
			Matrix.scaleM(modelViewMatrix, 0, OBJECT_SCALE_FLOAT,
					OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
			Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, 0.0f);
			Vec3F targetSize = itarget.getSize();
			Matrix.scaleM(modelViewMatrix, 0, targetSize.getData()[0],
					targetSize.getData()[1], 1.0f);
			Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession
					.getProjectionMatrix().getData(), 0, modelViewMatrix, 0);

			GLES20.glUseProgram(shaderProgramID);

			if (!mActivity.isExtendedTrackingActive()) {
				
				GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
						false, 0, mTeapot.getVertices());
				GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
						false, 0, mTeapot.getNormals());
				GLES20.glVertexAttribPointer(textureCoordHandle, 2,
						GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
				GLES20.glEnableVertexAttribArray(vertexHandle);
				GLES20.glEnableVertexAttribArray(normalHandle);
				GLES20.glEnableVertexAttribArray(textureCoordHandle);

				int index = 0;
				if (itarget.getName().equals("ERMITA-2-1")) {
					index = 1;
				}
				GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
				GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
						mTextures.get(index).mTextureID[0]);
				GLES20.glUniform1i(texSampler2DHandle, 0);
				// pass the model view matrix to the shader
				GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
						modelViewProjection, 0);
				GLES20.glEnable(GLES20.GL_BLEND);
				GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,
						GLES20.GL_ONE_MINUS_SRC_ALPHA);
				GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6,
						GLES20.GL_UNSIGNED_SHORT, mTeapot.getIndices());
				GLES20.glDisable(GLES20.GL_BLEND);

				lastTrackableId = -1;

				GLES20.glDisableVertexAttribArray(vertexHandle);
				GLES20.glDisableVertexAttribArray(normalHandle);
				GLES20.glDisableVertexAttribArray(textureCoordHandle);
				//
			} else {
				GLES20.glDisable(GLES20.GL_CULL_FACE);
				GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
						false, 0, mBuildingsModel.getVertices());
				GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
						false, 0, mBuildingsModel.getNormals());
				GLES20.glVertexAttribPointer(textureCoordHandle, 2,
						GLES20.GL_FLOAT, false, 0,
						mBuildingsModel.getTexCoords());

				GLES20.glEnableVertexAttribArray(vertexHandle);
				GLES20.glEnableVertexAttribArray(normalHandle);
				GLES20.glEnableVertexAttribArray(textureCoordHandle);

				GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
				GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
						mTextures.get(0).mTextureID[0]);
				GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
						modelViewProjection, 0);
				GLES20.glUniform1i(texSampler2DHandle, 0);
				GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0,
						mBuildingsModel.getNumObjectVertex());

				SampleUtils.checkGLError("Renderer DrawBuildings");
			}
			SampleUtils.checkGLError("Render Frame");
		}

		GLES20.glDisable(GLES20.GL_DEPTH_TEST);
		// GLES20.glDisable(GLES20.GL_BLEND);
		mRenderer.end();
	}

 

 

It works with some devices like Galaxy S2 and generic tablets. The problem I have encountered raises with following devices:

 

Nexus 4: Android 5.1: Recognizes target (prints log) and some strange things appear on screen. It's seems it manages to render the texture but it inmediately disappears.

Nexus 10: Android 5.1:  Recognizes target (prints log) but does nothing, no rendering at all. No error messages.

One Plus One: Android 4.4: Same as Nexus 10.

 

Any ideas?

Problems with renderFrame in Nexus devices

April 30, 2015 - 6:24am #7

But I code everyting in the Java class. Anyways, I've followed all the steps and I get the same results...

Problems with renderFrame in Nexus devices

April 28, 2015 - 10:00pm #6

I would try starting from ImageTargets in C++ sample app and just making the modifications discussed in this article and see if it works:

https://developer.vuforia.com/library/articles/Solution/How-To-Draw-a-2D-image-on-top-of-a-target-using-OpenGL-ES

 

Problems with renderFrame in Nexus devices

April 28, 2015 - 7:50am #5

Hi, it never worked in all devices, I'm facing this problem from the beggining. They can't render the texture properly.

Problems with renderFrame in Nexus devices

April 21, 2015 - 9:53am #4

I would suggest rolling the code back to the point where it was working on all the devices and then gradually adding elements back in and debugging along the way.

Problems with renderFrame in Nexus devices

April 21, 2015 - 12:45am #3

Thanks!

 

That's exactly the code I copied, then I made some other modifications, but the strange thing is that IT WORKS in some devices and DOESN'T in others... :(

Problems with renderFrame in Nexus devices

April 20, 2015 - 8:04pm #2
Log in or register to post comments