Log in or register to post comments

Black image being displayed

February 16, 2012 - 6:00am #1

While we installed our AR application to a phone, the augmented image is displayed as a black image. It is working fine in the phone that we were using to develop it. Any ideas how to resolve it...

Re: Black image being displayed

March 28, 2012 - 7:30am #5

ksiva,

I figured it out last night and came up with exactly what you replied with.
Works like a charm.

Thanks so much for your help!

Re: Black image being displayed

March 27, 2012 - 7:07pm #4

I just tested this with the ImageTargets sample and the textures that are included with the sample. This should work:

QCAR::Matrix44F modelViewProjection;

QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();

ShaderUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f,
                                 &modelViewMatrix.data[0]);
ShaderUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f, 
                             &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0],
                            &modelViewMatrix.data[0] ,
                            &modelViewProjection.data[0]);

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeNormals[0]);

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

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
//glUniform1i(_textureUniform, 0);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                   (GLfloat*)&modelViewProjection.data[0] );
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeTexcoords[0]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
               (const GLvoid*) &planeIndices[0]);

glDisableVertexAttribArray(vertexHandle);
glDisableVertexAttribArray(normalHandle);
glDisableVertexAttribArray(textureCoordHandle);

Try that first, then try out your custom texture loading code.

- Kim

Re: Black image being displayed

March 27, 2012 - 12:23pm #3
ksiva wrote:

It sounds like your texture isn't created/bound correctly. Try making the texture image a power-of-two (e.g. 512x512).

Or, perhaps you need to set the texture stage before binding the texture, like the samples show:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

If that's not the issue we'll need more info.

- Kim

I'm having the same issue.

It is rendering a black image instead of an image I provide.
Any help would be much appreciated

Here is all relavent code:

In the initWithFrameMethod:
_nationTexture = [self setupTexture:@"tile_floor.png"];

Setup Texture Method:

- (GLuint)setupTexture:(NSString *)fileName {

CGImageRef spriteImage = [UIImage imageNamed:fileName].CGImage;
if (!spriteImage) {
NSLog(@"Failed to load image %@", fileName);
exit(1);
}

size_t width = CGImageGetWidth(spriteImage);
size_t height = CGImageGetHeight(spriteImage);

GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte));

CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4,
CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);

CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage);

CGContextRelease(spriteContext);

GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);

free(spriteData);
NSLog(@"Loaded image for texture: %@", texName);
return texName;
}

In Render Method:

QCAR::Matrix44F modelViewProjection;

ShaderUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
&modelViewMatrix.data[0]);
ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
&modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0],
&modelViewMatrix.data[0] ,
&modelViewProjection.data[0]);

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeNormals[0]);

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

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _nationTexture);
glUniform1i(_textureUniform, 0);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &planeTexcoords[0]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
(const GLvoid*) &planeIndices[0]);

glDisableVertexAttribArray(vertexHandle);
glDisableVertexAttribArray(normalHandle);
glDisableVertexAttribArray(textureCoordHandle);

Re: Black image being displayed

February 17, 2012 - 10:28am #2

It sounds like your texture isn't created/bound correctly. Try making the texture image a power-of-two (e.g. 512x512).

Or, perhaps you need to set the texture stage before binding the texture, like the samples show:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

If that's not the issue we'll need more info.

- Kim

Log in or register to post comments