opengl es only support texture of 2^n in HTC hero?

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

opengl es only support texture of 2^n in HTC hero?

Postby lemondev » Mon Oct 12, 2009 9:03 am

in simulator ,it really support texture of 2^n , but when i upload my application into HTC hero, the texture can not display correctly(face has no texture). if i use texture of 2^n ,it display well on both simulator and HTC Hero.

anyone can help ? thanks.
lemondev
Freshman
Freshman
 
Posts: 7
Joined: Thu Feb 12, 2009 3:32 pm

Top

Re: opengl es only support texture of 2^n in HTC hero?

Postby Shaka » Tue Oct 13, 2009 7:02 am

lemondev wrote:in simulator ,it really support texture of 2^n , but when i upload my application into HTC hero, the texture can not display correctly(face has no texture). if i use texture of 2^n ,it display well on both simulator and HTC Hero.

anyone can help ? thanks.


Hmm, this might be true, I've also faced the same problem. I just got my Hero recently and got the same result. Anyone have any clues?
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Postby zorro » Wed Dec 16, 2009 8:45 am

The OpenGL legacy support for textures were sizes of 2^N, so this limitation remained in OpenGL ES too. There are extensions which allow the use of "non power of two" textures, but you must explicitly use them to obtain the desired result.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Patton » Wed Dec 16, 2009 10:38 am

Same here... tested on a HTC Hero - it won't display 480x320 textures. The same problem I had 5-6 years ago when I was developing OpenGL applications on PC with older graphic cards. I think I've read somewhere that textures rendered 2^n are much faster to draw than non 2^n. For example 512x512 is much faster than 480x320, or even 512x256. Never tested that theory though.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby zorro » Wed Dec 16, 2009 10:41 am

You can use 320x480 images in canvas mode (non-OpenGL). For OpenGL you can have a 512x512 texture and display only the 320x480 part of it, using the appropriate texture coordinates. Works nice.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Patton » Wed Dec 16, 2009 11:08 am

Yup, I'm using now 512x512...

By the way, has anyone noticed any problems with GL_LIGHTING on HTC Hero. On the simulator all works fine, but on this device, objects are rendered without lights? I can post my code later during the day...
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Top

Postby zorro » Wed Dec 16, 2009 11:18 am

The differences in programs behaviour between simulator and devices usually are coming from the fact that the device uses the hardware, unlike the simulator (which uses the google Pixel Flinger software emulator). With light you must ensure that you did enable both GL_LIGHTING and GL_LIGHT0. Also if you use more lights you must be careful about the maximum number of light sources enabled at a given time.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Patton » Wed Dec 16, 2009 11:22 am

Both GL_LIGHT0, GL_LIGHTING are enabled, offcourse :)
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby Shaka » Wed Dec 16, 2009 12:45 pm

zorro wrote:The OpenGL legacy support for textures were sizes of 2^N, so this limitation remained in OpenGL ES too. There are extensions which allow the use of "non power of two" textures, but you must explicitly use them to obtain the desired result.


Thanks for clearing that up :)
Shaka
Developer
Developer
 
Posts: 44
Joined: Fri Aug 28, 2009 3:01 pm

Postby Patton » Wed Dec 16, 2009 9:59 pm

This is the LIGHT code that works on simulator and not on HTC Hero:

Code: Select all
   private float lightAmbient[] = new float[]   {1.0f, 1.0f, 1.0f, 1.0f};
   private float lightDiffuse[] = new float[]   {1.0f, 1.0f, 1.0f, 1.0f};
   private float lightPosition[] = new float[]   {-1.0f, 2.0f, -10.0f, 6.0f};
   private FloatBuffer lightAmbientBuffer;
   private FloatBuffer lightDiffuseBuffer;
   private FloatBuffer lightPositionBuffer;
   this.lightAmbientBuffer = glCommon.initFloatBuffer(this.lightAmbient);
   this.lightDiffuseBuffer = glCommon.initFloatBuffer(this.lightDiffuse);
   this.lightPositionBuffer = glCommon.initFloatBuffer(this.lightPosition);
   gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, this.lightAmbientBuffer);
   gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, this.lightDiffuseBuffer);
   gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, this.lightPositionBuffer);
   gl.glEnable(GL10.GL_LIGHT0);
   gl.glEnable(GL10.GL_LIGHTING);


glCommon.initFloatBuffer returns a initialized floatbuffer.

The objects has normals offcourse.

Don't know whats the problem :(
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby zorro » Wed Dec 16, 2009 10:10 pm

I don't see anything wrong in your code. To be sure, you can try setting all the light properties, to override the default values. The components which you must set are GL_SPECULAR and GL_SHININESS. This way you control 100% of the light.

You can also try a directional light, with the 4th position value set to 0.0f. This way the light is at infinite distance from the scene and the first 3 values now define the directional vector. This type of light is more common because it's easier to be computed on the graphic chip.

Be sure not to call glEnable(GL_COLOR_MATERIAL) because this overrides the light output and you have no light at all on the object.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests