Log in or register to post comments

Android 4.0 - Asus Transformer - Cube texture problem

April 24, 2012 - 1:18am #1

Hi,

Since my Asus update to 4.0 cube rendered over trackable lost his textures.
It's totally black.

Here is my code. Any ideas ?It works good on Samsungs/Sony Ericson/ HTC etc... texture is png but jpg also dont work :

renderCube:

void
renderCube( QCAR::Matrix44F modelViewMatrix ){
	const Texture* const thisTexture1 = textures[1];
	static double prevTime = getCurrentTime();
	double time = getCurrentTime();
	float dt = (float)(time-prevTime);
	static float licznikCzasowy = 0.0f;
	licznikCzasowy += dt * 120.0f/3.1415f;

	#ifdef USE_OPENGL_ES_1_1
		LOG("renderCube 1.0");
		// Load projection matrix:
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(projectionMatrix.data);
		// Load model view matrix:
		glMatrixMode(GL_MODELVIEW);
		glLoadMatrixf(modelViewMatrix.data);
		glTranslatef(0.f, 0.f, kObjectScale);
		glScalef(kObjectScale, kObjectScale, kObjectScale);
		// Draw object:
		//glBindTexture(GL_TEXTURE_2D, thisTexture1->mTextureID);
		glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &hTexCoords[0]);
		glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &hVerts[0]);
		//glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, thisTexture1->mTextureID);
		glDrawArrays(GL_TRIANGLES, 0, hNumVerts);
	#else
		LOG("renderCube 2.0.");
		QCAR::Matrix44F modelViewProjection, objectMatrix;
		Obiekt1* obiekt = &dominoArray[0];
		SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
		SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);
		SampleUtils::rotatePoseMatrix(licznikCzasowy, 0.0f, 0.0f, 0.1f, &modelViewMatrix.data[0]);
		SampleUtils::multiplyMatrix(&projectionMatrix.data[0],&modelViewMatrix.data[0] , &modelViewProjection.data[0]);
		prevTime = time;
		glUseProgram(shaderProgramID);
		glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &hVerts[0]);
		glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &hTexCoords[0]);
		glEnableVertexAttribArray(vertexHandle);
		glEnableVertexAttribArray(textureCoordHandle);	
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, thisTexture1->mTextureID);
		glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] );

		glDrawArrays(GL_TRIANGLES, 0, hNumVerts);
	
		SampleUtils::checkGlError("ImageTargets renderFrame");
	#endif
}

render frame:

JNIEXPORT void JNICALL
Java_com_ARFixer_opolgraf_ImageTargetsRenderer_renderFrame(JNIEnv *env, jobject obj)
{
    //LOG("Java_com_ARFixer_opolgraf_GLRenderer_renderFrame");
    if ( prevTimeFocus == 0){
    	prevTimeFocus = getCurrentTime();
    }
	float dt = (float)(getCurrentTime()-prevTimeFocus);
	//licznikCzasowyFocus += dt;
	
	// ? JNI_TRUE : JNI_FALSE;
    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
	//LOG("dt: %f", dt);
	LOG("USE_OPENGL_ES_1_1");
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif
	
	LOG("USE_OPENGL_ES_2?");
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);


// Did we find any trackables this frame?
	if ( state.getNumActiveTrackables() == 0 ){
		noTrackActive( env, obj );
		//LOG("dt: %f", dt);
		if ( dt > 3 ){
			licznikCzasowyFocus = 0.0f;
			prevTimeFocus = getCurrentTime();
			if ( QCAR::CameraDevice::getInstance().setFocusMode(QCAR::CameraDevice::FOCUS_MODE_TRIGGERAUTO)){
				LOG("FOCUSED !");
			}
			else{
				LOG("FOCUS FAILEd !");
			}
		}
	}
	else{     
		jstring name = yesTrackActive(env, obj, state);
	}
	
    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1   
	LOG("USE_OPENGL_ES_1_1");     
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
	LOG("USE_OPENGL_ES_2");
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif

    QCAR::Renderer::getInstance().end();
}

Re: Android 4.0 - Asus Transformer - Cube texture problem

April 27, 2012 - 5:16am #3
ksiva wrote:
const Texture* const thisTexture1 = textures[1];

Just to check, you do mean to reference the second texture added in Java, right? Index 0 would reference the first one.

What if you use the teapot texture from the ImageTargets sample instead? That should help us determine if it's an issue with the image or the code.

You might want to change your texture image to have a power-of-two size if it doesn't already.

- Kim

Ufff It works :) Texture image was 300px x 300px after resizing to 256x256 its ok.

Strange that all works fine in number of phones and tablets. We test it personaly at: Motorola Xoom, 4 kinds of Samsungs Phones, Samsung Galaxy Tabs, Iphone, iPads but all works on Android lower then 4.0
If that problem will be present in all android 4 devices maybe you should add error throw that will not allow adding textures in wrong size :) ? or some kind *of warning / notice :)*
*

Thx Kim.

Re: Android 4.0 - Asus Transformer - Cube texture problem

April 24, 2012 - 6:30pm #2
const Texture* const thisTexture1 = textures[1];

Just to check, you do mean to reference the second texture added in Java, right? Index 0 would reference the first one.

What if you use the teapot texture from the ImageTargets sample instead? That should help us determine if it's an issue with the image or the code.

You might want to change your texture image to have a power-of-two size if it doesn't already.

- Kim

Log in or register to post comments