Make sure that you are loading your textures from the drawable-nodpi
resource directory:
http://www.anddev.org/opengl_textures_-_motorola_droid-t10930.html


On Aug 9, 1:07 pm, Mike <[email protected]> wrote:
> I'm getting white (blank) textures on everything when running on the
> Droid and Galaxy S devices.
> My textures are all power-of-two PNGs and they're in the /res/drawable-
> nodpi folder.
>
> Here's my code:
>
> public GLTextures(GL10 gl, Context context) {
>                 if(gl==null)return;
>                 this.gl = gl;
>                 this.context = context;
>                 this.textureMap = new java.util.HashMap<Integer, Integer>();
>                 sBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
>
>         }
>
>         public void freeTexs(){
>                 gl.glDeleteTextures(textures.length, textures,0);
>                 textureFiles = null;
>         }
>
>         public void loadTextures() {
>                 if(gl==null)return;
>                 int[] tmp_tex = new int[textureFiles.length];
>                 gl.glGenTextures(textureFiles.length, tmp_tex, 0);
>                 textures = tmp_tex;
>                 for (int i = 0; i < textureFiles.length; i++) {
>
>                         this.textureMap.put(new Integer(textureFiles[i]), new 
> Integer(i));
>                         int tex = tmp_tex[i];
>
>             gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
>             gl.glTexParameterf(GL10.GL_TEXTURE_2D,
> GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
>             gl.glTexParameterf(GL10.GL_TEXTURE_2D,
> GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
>
>             gl.glTexParameterf(GL10.GL_TEXTURE_2D,
> GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
>             gl.glTexParameterf(GL10.GL_TEXTURE_2D,
> GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
>             gl.glTexEnvf(GL10.GL_TEXTURE_ENV,
> GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
>
>             InputStream is =
> context.getResources().openRawResource(textureFiles[i]);
>             Bitmap bitmap;
>             try {
>                 bitmap = BitmapFactory.decodeStream(is, null,
> sBitmapOptions);
>             } finally {
>                 try {
>                     is.close();
>                 } catch (IOException e) {
>                     // Ignore.
>                 }
>             }
>
>             buildMipmap(gl, bitmap, tex);
>             bitmap.recycle();
>
>                 }
>         }
>
> private void buildMipmap(GL10 gl, Bitmap bmp, int tex) {
>                 //
>                 int level = 0;
>                 //
>                 int height = bmp.getHeight();
>                 int width = bmp.getWidth();
>
>                 while (height >= 1 || width >= 1) {
>                         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);
>
>                         if (height == 1 || width == 1) {
>                                 break;
>                         }
>                         // Increase the mipmap level
>                         level++;
>                         //
>                         height /= 2;
>                         width /= 2;
>                         Bitmap bitmap2 = Bitmap.createScaledBitmap(bmp, 
> width, height,
> true);
>                         // Clean up
>                         bmp.recycle();
>                         bmp = bitmap2;
>                 }
>         }
>
> Here's my setup code in my renderer's onSurfaceCreated method:
>
>                                 // Define the lighting
>                 float lightAmbient[] = new float[] { 1f, 1f, 1f, 1 };
>                 float lightDiffuse[] = new float[] { 1, 1, 1, 1 };
>                 float[] lightPos = new float[] { 0, 0, 0, 1};
>                 gl.glEnable(GL10.GL_LIGHTING);
>                 gl.glEnable(GL10.GL_LIGHT0);
>                 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 
> 0);
>                 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 
> 0);
>                 gl.glLightf(GL10.GL_LIGHT0, GL10.GL_CONSTANT_ATTENUATION, 
> 1.0f);
>                 gl.glLightf(GL10.GL_LIGHT0, GL10.GL_LINEAR_ATTENUATION, 
> 0.01f);
>                 gl.glLightf(GL10.GL_LIGHT0, GL10.GL_QUADRATIC_ATTENUATION, 
> .1f);
>                 gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
>
>                 // Define the materials
>                 float matAmbient[] = new float[] {1, 1, 1, 1 };
>                 float matDiffuse[] = new float[] {1, 1, 1, 1 };
>                 gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, 
> matAmbient,
> 0);
>                 gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, 
> matDiffuse,
> 0);
>
>                                 gl.glDisable(GL10.GL_DEPTH_TEST);
>                 gl.glEnable(GL10.GL_BLEND);
>                 gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
>                 gl.glDepthFunc(GL10.GL_LEQUAL);
>                 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
>                 gl.glDisable(GL10.GL_DITHER);
>
>                 //Enable textures
>                 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST);
>                 gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
>                 gl.glEnable(GL10.GL_TEXTURE_2D);
>
> Any help is appreciated.
>
> -mike

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to