Log in or register to post comments

different 3D model not shown

January 22, 2013 - 12:01am #1

Ok guys i went through a lot of ontopic posts,but none fix me,I'm working on the ImageTarget sample project

i replaced the image target,was trying to replace the 3D model with some free collected 3D model

i did choose the famous banana.h, and its texture,the texture loaded easily

const char* textureFilenames[] = {
        "banana.png"
//        "TextureTeapotBrass.png",
};

I did change the cordinates of model inside setup3dObjects method,with banana's.

    for (int i=0; i < [textures count]; i++)
    {
        Object3D *obj3D = [[Object3D alloc] init];
        
        obj3D.numVertices = bananaNumVerts;
        obj3D.vertices = bananaVerts;
        obj3D.normals = bananaNormals;
        obj3D.texCoords = bananaTexCoords;
        
//        obj3D.numIndices = NUM_TEAPOT_OBJECT_INDEX;
//        obj3D.indices = teapotIndices;

        
        obj3D.texture = [textures objectAtIndex:i];
        NSLog(@"obj width:%d",obj3D.texture.width);
        [objects3D addObject:obj3D];
        [obj3D release];
    }

The dataset loaded successfully,the target was identifyed and also the frame rendered, i printed the obj3D's(the rendering 3D model) properties  inside renderFrameQCAR,it's printing.

The problem is,there's no banana is on screen...! i think i'm missing something silly, anyone point me please, i'm going mad

different 3D model not shown

October 11, 2017 - 12:50am #14

I am finding difficulty in java code of the same can you please help me out.i cant see the banana model .And not getting how to change kobjectscale.

different 3D model not shown

February 7, 2013 - 3:56am #13

Oh, great! You're welcome.

different 3D model not shown

February 7, 2013 - 3:49am #12

i was very frustrated,i don't know how to thank you... it worked...u kinda saved me man...! thanks a lotttt

different 3D model not shown

February 7, 2013 - 3:30am #11

Hi, first, a little question about your code:

why do you use glActiveTexture(GL_TEXTURE1); ?

this should be glActiveTexture(GL_TEXTURE0);

(which is consistent with the following code

glUniform1i(texSampler2DHandle, 0);

Second: the banana model that comes from the obj2opengl script package, requries a kObjectScale of about 100 to be visible; can you double-check that ? (if it is too small, you won;t be able to see it)

Other than that, I just tested the model by starting from a brand new Image Targets sample, and I would recommend you do the same (just to exclude any other possible causes related to other changes in your application code), and apply the following corrections:

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaVerts[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaTexCoords[0]);

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

And also replace glDrawElements() with this:

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

 

Everything else should stay the same as in the original sample code (except changing the kObjectScale to 100, as I said).

This should just work (as I just verified).

I hope this helps.

 

different 3D model not shown

February 7, 2013 - 2:45am #10

Hi i tried it this doesn't show the model,doesn't error as well,and the renderFrameQCAR method prints this log ,  NSLog(@"text%d",obj3D.texture.width);

so its getting right texture. do i have problems with cordinates?

can this codes be changed to do something?

glActiveTexture(GL_TEXTURE1 );
            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
            glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
            glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);

            glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
            ShaderUtils::checkGlError("EAGLView renderFrameQCAR");

 

different 3D model not shown

February 7, 2013 - 1:54am #9

Hi, thanks for the update:

to make it work you should then use those arrays in your OpenGL code, something like this:


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

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &bananaTexCoords[0]);

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

(In your code you were using obj3D.vertices, obj3D.normals, etc.  that can only work if your obj3d contains the banana stuff...)

 

different 3D model not shown

February 6, 2013 - 9:12pm #8

hi AlessandroB

sorry as it was not working i switched to different project lately,i had to come back to this

the banana.h file got

unsigned int bananaNumVerts, float bananaVerts [ ], float bananaNormals [ ], float bananaTexCoords [ ]

any help will be apreciated if you can tress what's wrong with my approach

different 3D model not shown

January 24, 2013 - 5:41am #7

Hi, can you check what "arrays" are defined in your Banana.h header?

(verts array, normals array ?, tex coords array ?)

 

different 3D model not shown

January 24, 2013 - 3:57am #6

Hi AlessandroB,

yes i'm using openGL 2,but the matter of worry is,when i use

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
            glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);
            
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

that doesn't even view me a blink, i tried rotating the texture too,it didn't solve the problem,only this weird vertion shows a blink

            glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);
            glNormalPointer(GL_FLOAT, 0, (const GLvoid*)obj3D.normals);
            glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*)obj3D.texCoords);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY) ;//added from forum help
            
            glEnableVertexAttribArray(vertexHandle);
            glEnableVertexAttribArray(normalHandle);
            glEnableVertexAttribArray(textureCoordHandle);

i can't really under stand all this openGL ES codes,that's why can't tress where is the actual problem

different 3D model not shown

January 23, 2013 - 4:45am #5

Hi ullash,

the code

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
glEnableVertexAttribArray(vertexHandle);

is only valid in OpenGL ES 2.0,

while

glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);

is only valid when using OpenGL ES 1.1

So, they are kind of equivalent functions but one is for OGLES 2.0 and the other is for 1.1.

If you use the glUseProgram(), glUniform4fv etc (as I see from your code), it means you are using OpenGL ES 2.0, so you must use

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
glEnableVertexAttribArray(vertexHandle);
 

The other thing is: if you see a textured model, but the texture looks messed up (i.e. "no structure" as you mention), this might be simply due to the need to flip the texture top-down (just open it in an image editor, flip it vertically and save it); I mention this because I saw this happening already to many users (and the flip trick solved the issue).

 

 
 

 

different 3D model not shown

January 23, 2013 - 4:12am #4

Hi P.Uthaman i got some responses with your suggestion, they texture appears but structure gone,i'm gonna fix this tell me one thing

is

            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
            glEnableVertexAttribArray(vertexHandle);

and

            glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);

stands for same purpose?

and this version below shows me a yellow(texture) but can't find any structure

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);
            NSLog(@"text%d",obj3D.texture.width);
//            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
//            glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
//            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);
            
            glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);
            glNormalPointer(GL_FLOAT, 0, (const GLvoid*)obj3D.normals);
            glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*)obj3D.texCoords);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY) ;//added from forum help
            
            glEnableVertexAttribArray(vertexHandle);
            glEnableVertexAttribArray(normalHandle);
            glEnableVertexAttribArray(textureCoordHandle);
            
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
            glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
            glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
//            glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
            glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
            ShaderUtils::checkGlError("EAGLView renderFrameQCAR");

sorry for annoying you man... any help is appreciated :)

AlessandroB thanks man,but i met those points way before,going through the forum, i now guess that the problem is in openGL presentation

different 3D model not shown

January 22, 2013 - 7:02am #3

@ ullash.podder:

one thing you may want to check is the scale factor applied to your mesh; sometimes a model does not show up just because it is too small compared to the scale of your image target;

another hint on the OpenGL code side is to check if you're using glDrawArray() or glDrawElements(), as very often the exported models need glDrawArray() instead of glDrawElements(). 

different 3D model not shown

January 22, 2013 - 4:16am #2

HI ullash,

I am also faced same issue fixed with adding glEnableClientState(GL_TEXTURE_COORD_ARRAY) after glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords) to make it finally accept the texture.

 

Thanks,

P.Uthaman

Log in or register to post comments