Log in or register to post comments

OpenGLES question

January 19, 2011 - 5:52am #1

I managed to replace the "teapot" by my own model. This works fine.
The model (like the teapot) is "sitting" a little bit over the target and in the center of that.
I try to move the object to a different position on the target (x and y) and also in Z-direction.
But I get weird results (GLES 2.0).

For the z-direction I use e.g.
"SampleUtils::translatePoseMatrix(0.0f, 0.0f, -1.0f, &modelViewMatrix.data[0]".

Any help is welcome

Frank

OpenGLES question

July 27, 2012 - 2:34pm #31

Have you added that texture to the project?

 

  1. Add the texture images to the assets folder.
  2. In the main activity class (e.g. ImageTargets.java) find the loadTextures() method. Add additional calls to mTextures.add for each of your image files. Note that the order in which the textures are added determines their order in the native texture array.
  3. In the native renderFrame() method (e.g. in ImageTargets.cpp) find the point at which the texture object is obtained (textures[textureIndex]). Change the texture index to select the desired texture. The indices start at 0, where index 0 is the first texture added in the loadTextures() Java method.

OpenGLES question

July 27, 2012 - 12:29pm #30

Hi, i try with banana.h
i try do this :

"// set input data to arrays

glVertexPointer(3, GL_FLOAT, 0, bananaVerts);

glNormalPointer(GL_FLOAT, 0, bananaNormals);

glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords);

 

// draw data

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

*/ " 

i save banana.jpg like banana.png and also i change kObjectScale value.
but when i run the app, i don't see the banana :(

any idea?
thx,

sry 4 my english,
Grettings from Chile :) 

Re: OpenGLES question

May 23, 2012 - 12:25am #29
dereklan wrote:

me too, I want to know how to flip the texture image vertically,anybody knows?

I've had several issues with textures and custom 3D objects.
Some times I had to flip the image vertically (this can be easily done with Paint under Windows) and the last time I had to go from 16 to 8 bits for it to work correctly.

Give it a try!

Re: OpenGLES question

May 23, 2012 - 12:22am #28

GrannySmith, there might be some issue with the object you're using.
Did you try to translate it to the center?

Re: OpenGLES question

May 23, 2012 - 12:18am #27

Hello Peter
What is is exactly that you're trying to do? Are you working with the iOS or the Android SDK?

I normally work under iOS, if you're on the same page, look for the 'renderFrameQCAR' in the EAGLView.m class.
Inside that function you'll find the rendering of the object, there this line:
ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,&modelViewMatrix.data[0]);
should modify the scale.
if you want an object to be bigger, look for the declaration of the kObjectScale variable.

For example, line 76 for the Android ImageTargets.cpp class
static const float kObjectScale = 3.f;

Best
Juan

Re: OpenGLES question

May 22, 2012 - 10:51pm #26

HELLO ereryone
kObjectScale should modify which line program?
i want see banana more bigger

Re: OpenGLES question

April 13, 2012 - 5:49am #25

Thanks to this thread i was able to create my 3d Object transform it to an .h file and display it correctly in my app. Still, there is one thing which bothers me:
When i am rotating the marker (the real physical Marker :) ) the relativ position of my 3D Object to the marker is moving. In the attached pictures you can see how the position changed in different angles.
Any ideas what could cause this?
I didn't change anything of the code from the example given in this thread.

Re: OpenGLES question

March 9, 2012 - 12:51am #24
omais wrote:

Hi Frank.
Hi i am able to use Custum 3d model but object is distorted, not showing correctly. and i want to know that how to apply texture on the object, step you mentioned is not working, object is with Black & white color.
Thanks

me too, I want to know how to flip the texture image vertically,anybody knows?

Re: OpenGLES question

March 8, 2012 - 3:18am #23
strange99 wrote:

Hellkero,

it's very simple (depending on your model):

I used a model generated from a "special" software; the problem was, that this model used more than one mesh and therefore more than one texture.
I imported the model in 3DSMAX (use "Merge to one mesh") and exported the model again (without any further modifications) as "*.obj". Bute there were again more than one texture. I used then DAZ Studio 3D to import the model.
There is a plugin "Texture Atlas" (29 $), which merges the textures to one.
Exported again as Wavefront .obj.

These steps are only necessary if the model has more than one mesh and/or more than one texture.

Now the part for QCAR: (assuming jour model has the name "model.obj" and the texture has the name "texture.png" - OK ?)

use the script "obj2opengl.pl" (I'm using a Mac w. Snow Leo):

Invoke "perl obj2opengl.pl model.obj".
This will generate a file "model.h". Save this to your "ImageTargets/jni" Folder.

Now edit "ImageTargets.cpp":

include this line
#include "model.h"
right after
#include "teapot.h".

Now replace the lines from

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

to

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);

with these:

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

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

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &modelTexCoords[0]);

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

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );

glDrawArrays(GL_TRIANGLES, 0, modelNumVerts);

Save it and invoke "ndk-build" in the folder "ImageTargets". If everything is fine the you should "Clean" your project in Eclipse and then "Build Project" and run it on your device.

If your model looks too small, you should set the scaling like this (factor 3.0):

SampleUtils::scalePoseMatrix(3.0f, 3.0f, 3.0f, &modelViewMatrix.data[0]);

If you want to replace the texture (assuming your target is "stones") the you should copy the file "texture.png" (by draggin' into the "assets" folder).

Now include this line

mTextures.add(Texture.loadTextureFromApk("model.png", getAssets()));

BEFORE the line

mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));

in "ImageTargets.java" in the procedure "private void loadTextures()"

This will load the texture "model.png" as Texture with the index 0;

I hope this helps you (and others).

Frank

Hi Frank.
Hi i am able to use Custum 3d model but object is distorted, not showing correctly. and i want to know that how to apply texture on the object, step you mentioned is not working, object is with Black & white color.
Thanks

Re: OpenGLES question

March 8, 2012 - 12:18am #22
omais wrote:

I also want to know, plz help...

Hi, Please can somebody help me... Is this question not related to this topic, y not body is answering... :confused:

Re: OpenGLES question

March 7, 2012 - 7:05am #21
poj wrote:

Hi all,

Franks step for banana.h work fine for me too. But now I download free model from internet. it come as obj file and mtl file. Any idea how to get png file for Texture.

I also want to know, plz help...

Re: OpenGLES question

March 6, 2012 - 8:00am #20

did you ok now?

Re: OpenGLES question

March 6, 2012 - 7:59am #19
poj wrote:

Hi all,

Franks step for banana.h work fine for me too. But now I download free model from internet. it come as obj file and mtl file. Any idea how to get png file for Texture.

I also want to know, anyone know that???

Re: OpenGLES question

September 27, 2011 - 2:23am #18
ksiva wrote:

That's exactly right. The only problem I see is that you used banana.png instead of banana.jpg, did you resave the texture as a png?

Also, you will need to scale up the object quite a bit. Try setting kObjectScale to 50 or so.

- Kim

Wow...This is really a good example on how to replace the teapot with some other object. And setting the kObjectScale to 200 made my banana visible! :D

Note: i used banana.obj from
http://heikobehrens.net/2009/08/27/obj2opengl/

It's a easier start for those who don't have the object files yet. (I used this since i was stuck creating an object from scratch using unity. Dunno how to convert it to .obj file)

Thanks guys.. ;)

Re: OpenGLES question

August 28, 2011 - 4:24am #17

Hi all,

Franks step for banana.h work fine for me too. But now I download free model from internet. it come as obj file and mtl file. Any idea how to get png file for Texture.

Re: OpenGLES question

July 11, 2011 - 8:10am #16

Hi everyone

How to make the moving object? I want to make one of the banana moves to the right and left, and one of them does not move. How to do that?

Thanks
-Mah

Re: OpenGLES question

May 4, 2011 - 11:34am #15

rassall_jubair
1. Try to reinstall cygwin with the Development library.
2. Run the cygwin type perl -v (check if perl is installed)
3. type: perl obk2opengl.pl your_file.obj
4. It will create your_file.h in the same folder.

Re: OpenGLES question

March 23, 2011 - 1:18am #14

Hello,

I am facing problem o run this perl scrip(obj2openl.pl) of mentioned link.I open my widnows xp command promt then go to the script (ob2opengl)directory. I write following command:

perl obj2opengl.pl cube.obj

But i Receiving two error

error in option spec: "centre=f{3}"
error in option spec: "ARRAY(01ad2c60)"

I also try in cygwin to run this cript by follwing command:

./object2opengl.pl cube.obj

but i got following error:

bash:./obj2opengl.pl.......permission denied

I know this is not a right place to discuss about this script. But i hardly need obj converter to .h file for my 3d file.

Any Idea how i can execuite this obj2opengl.pl script in my windows xp pc.

thanks

Rassall

Re: OpenGLES question

February 8, 2011 - 5:46am #13

You may need to need to flip your texture vertically. Open it in any image processing program, flip it and resave it.

- Kim

Re: OpenGLES question

February 7, 2011 - 8:49pm #12

Hi everyone,

I followed Frank's steps using banana.h too, its work thx to everyone, but the problem is texture doesn't seem to be correctly it looks mess up . Any idea to fix that?

teecat

Re: OpenGLES question

February 7, 2011 - 6:44am #11

17 MB might be a little big for a single resource file...

While easy to work with, these header files are not the most efficient approach for getting 3D content into your application. One problem is that they are plain text, rather than a binary format, and are therefore much larger than necessary. If you have complex models you may want to look around for an OpenGL ES model importer than can handle binary formats.

Note also that the perl script produces a header file with many comment lines, and higher float precision than is strictly necessary. All this adds to the file size. You can try modifying the perl script to remove the comments, as a first step.

- Kim

Re: OpenGLES question

February 4, 2011 - 8:23pm #10

Kim

Thx, the banana work perfectly! And i got another question here.

Is there a limit or maximum size for 3D model?
Because when i try to use my model which header file size is 17MB, got crash when try to running with this message.

ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.qualcomm.QCARSamples.ImageTargets/.ImageTargets }

hellkero

Re: OpenGLES question

January 22, 2011 - 1:06pm #9

That's exactly right. The only problem I see is that you used banana.png instead of banana.jpg, did you resave the texture as a png?

Also, you will need to scale up the object quite a bit. Try setting kObjectScale to 50 or so.

- Kim

Re: OpenGLES question

January 21, 2011 - 11:11pm #8

Hi, Frank its me again
Sorry for reply late, i just got a device back.After following your steps, but the model still doesn't show up. :(
I'm using banana.h and its texture from Heiko for testing.
This is my code.

include part

#include "SampleUtils.h"
#include "Texture.h"
#include "CubeShaders.h"
#include "Teapot.h"
#include "banana.h"

for draw model part

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);
        
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);     

and this part for texture

    	
mTextures.add(Texture.loadTextureFromApk("banana.png", getAssets())); 
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                                                 getAssets()));
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                                                 getAssets()));

not sure i'm doing rigth..:confused:

Re: OpenGLES question

January 20, 2011 - 10:49pm #7

Kim,

thank you for your reply !

Indeed, this was my brain and - of course - a big mistake ... oops.

you're right, I was thinking about the target is also an object ...

That's "virtual reality".

But, I'll try your code and/or modifying my model.

Re: OpenGLES question

January 20, 2011 - 6:25am #6

Frank, I tried your translation code, and it is working as expected. The problem is, it's not the result your brain is expecting!

When you sink the teapot under the target, you expect the target plane to occlude the teapot. This won't happen without drawing an object for occlusion, however. Here's some sample code for drawing an occlusion plane, that will cut off anything rendered beneath it.

First, you'll need to copy the TextureWireframe.png file from the MultiImageTargets project. Put it in your ImageTargets/assets folder, and add this code to ImageTargets.java:

private void loadTextures()
{
    mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                                             getAssets()));
    mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                                             getAssets()));
    mTextures.add(Texture.loadTextureFromApk("TextureWireframe.png",
                                             getAssets()));
}

This is simply a transparent texture with a yellow border. You may want to create a similar one without the yellow border.

Now, add this code to ImageTargets.cpp, *before* rendering the teapot:

QCAR::Matrix44F modelViewProjection;

// Draw a plane occluder

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

SampleUtils::scalePoseMatrix(300.0f, 300.0f, 300.0f,
                             &modelViewMatrix.data[0]);

SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                            &modelViewMatrix.data[0] ,
                            &modelViewProjection.data[0]);

float planeVertices[] =
{
    -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0,
};

float planeTexcoords[] =
{
    0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0
};

float planeNormals[] =
{
    0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0
};

unsigned short planeIndices[] =
{
    0, 1, 2, 0, 2, 3
};

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]);

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeTexcoords[0]);

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

glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                   (GLfloat*)&modelViewProjection.data[0]);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
               (const GLvoid*) &planeIndices[0]);

modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

As you can see, I haven't quite scaled the plane large enough to cover the entire ground plane. Adjust the scale to meet your needs.

Let me know if you have any questions!

- Kim

Re: OpenGLES question

January 20, 2011 - 12:47am #5

Hellkero,

it's very simple (depending on your model):

I used a model generated from a "special" software; the problem was, that this model used more than one mesh and therefore more than one texture.
I imported the model in 3DSMAX (use "Merge to one mesh") and exported the model again (without any further modifications) as "*.obj". Bute there were again more than one texture. I used then DAZ Studio 3D to import the model.
There is a plugin "Texture Atlas" (29 $), which merges the textures to one.
Exported again as Wavefront .obj.

These steps are only necessary if the model has more than one mesh and/or more than one texture.

Now the part for QCAR: (assuming jour model has the name "model.obj" and the texture has the name "texture.png" - OK ?)

use the script "obj2opengl.pl" (I'm using a Mac w. Snow Leo):

Invoke "perl obj2opengl.pl model.obj".
This will generate a file "model.h". Save this to your "ImageTargets/jni" Folder.

Now edit "ImageTargets.cpp":

include this line
#include "model.h"
right after
#include "teapot.h".

Now replace the lines from

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

to

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);

with these:

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

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

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &modelTexCoords[0]);

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

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );

glDrawArrays(GL_TRIANGLES, 0, modelNumVerts);

Save it and invoke "ndk-build" in the folder "ImageTargets". If everything is fine the you should "Clean" your project in Eclipse and then "Build Project" and run it on your device.

If your model looks too small, you should set the scaling like this (factor 3.0):

SampleUtils::scalePoseMatrix(3.0f, 3.0f, 3.0f, &modelViewMatrix.data[0]);

If you want to replace the texture (assuming your target is "stones") the you should copy the file "texture.png" (by draggin' into the "assets" folder).

Now include this line

mTextures.add(Texture.loadTextureFromApk("model.png", getAssets()));

BEFORE the line

mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));

in "ImageTargets.java" in the procedure "private void loadTextures()"

This will load the texture "model.png" as Texture with the index 0;

I hope this helps you (and others).

Frank

Re: OpenGLES question

January 19, 2011 - 11:12pm #4

Hey Frank

Could you tell me how to replace a new model instead of teapot?
I'm already try this method
http://ar.qualcomm.at/node/2000231
but it doesn't work.

thx.

Re: OpenGLES question

January 19, 2011 - 9:58pm #3

Kim,

please see the code below;

eventually you could try the code (I'm using the teapot from "ImageTargets").

The "goal" is to put the object (Teapot) a half into the target (not sitting on top)...

QCAR::Matrix44F modelViewProjection;

SampleUtils::scalePoseMatrix(3.0f, 3.0f, 3.0f,
&modelViewMatrix.data[0]);

// THIS WORKS AS EXPECTED !!
// MOVES THE TEAPOT TO THE LEFT AND UP TO THE OBSERVER
// SampleUtils::translatePoseMatrix(-50.0f, 0.0f, 20.0f, &modelViewMatrix.data[0]);

// THIS WORKS NOT AS EXPECTED !!
SampleUtils::translatePoseMatrix(-50.0f, 0.0f, -20.0f,&modelViewMatrix.data[0]);

SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
&modelViewMatrix.data[0] ,
&modelViewProjection.data[0]);

glUseProgram(shaderProgramID);

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

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

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotTexCoords[0]);

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

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);

Re: OpenGLES question

January 19, 2011 - 6:03am #2

Could you give us the full sample of the transformations you are trying to apply? Remember that these happen in reverse order. Also note that the size of your target is defined in the config.xml file, and you should take this into account when translating.

Remember that X is to the right, Y is to the top of the target, and Z points upwards, perpendicular to the target.

- Kim

Log in or register to post comments