Problem with glDrawTexfOES

Problems with Canvas, OpenGL, etc...

Problem with glDrawTexfOES

Postby tttcowan » Tue Oct 05, 2010 8:22 pm

Hi,

I'm having a bit of a problem with glDrawTexfOES, i've got the code below,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. gl.glBindTexture(GL10.GL_TEXTURE_2D, 1);
  2.         int i[] = new int[4];
  3.         i[0] = 0;
  4.         i[1] = 0;
  5.         i[2] = 256;
  6.         i[3] = 256;
  7.        
  8.         ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES,
  9.                 i, 0);
  10.  
  11.                 ((GL11Ext) gl).glDrawTexfOES(0,0,0,256,256);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


It moves the texture to screen fine but it's like the resolution of it is 128x128 rather than 256x256. It's like it's stretched by 2 pixels. The original image is 256x256 and the full image is displayed. I've used the code below to load textures,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private static int newTextureID(GL10 gl) {
  2.             int[] temp = new int[1];
  3.             gl.glGenTextures(1, temp, 0);
  4.             return temp[0];        
  5.         }
  6.  
  7.         // Will load a texture out of a drawable resource file, and return an OpenGL texture ID:
  8.         private int loadTexture(GL10 gl, Context context, int resource) {
  9.            
  10.             // In which ID will we be storing this texture?
  11.             int id = newTextureID(gl);
  12.            
  13.             // We need to flip the textures vertically:
  14.             Matrix flip = new Matrix();
  15.             flip.postScale(1f, -1f);
  16.            
  17.             // This will tell the BitmapFactory to not scale based on the device's pixel density:
  18.             // (Thanks to Matthew Marshall for this bit)
  19.             BitmapFactory.Options opts = new BitmapFactory.Options();
  20.             opts.inScaled = false;
  21.            
  22.             // Load up, and flip the texture:
  23.             Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
  24.             Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
  25.             temp.recycle();
  26.            
  27.             gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
  28.            
  29.             // Set all of our texture parameters:
  30.             gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
  31.             gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
  32.             gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  33.             gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  34.            
  35.             // Generate, and load up all of the mipmaps:
  36.             for(int level=0, height = bmp.getHeight(), width = bmp.getWidth(); true; level++) {
  37.                 // Push the bitmap onto the GPU:
  38.                 GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);
  39.                
  40.                 // We need to stop when the texture is 1x1:
  41.                 if(height==1 && width==1) break;
  42.                
  43.                 // Resize, and let's go again:
  44.                 width >>= 1; height >>= 1;
  45.                 if(width<1)  width = 1;
  46.                 if(height<1) height = 1;
  47.                
  48.                 Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true);
  49.                 bmp.recycle();
  50.                 bmp = bmp2;
  51.             }
  52.            
  53.             bmp.recycle();
  54.            
  55.             return id;
  56.         }
  57.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


From the above which i pinched from a website i can see it keeps resizing by half and pushing them to the gpu at "levels".

It's like it's displaying level 1 rather 0? I could be way off here but don't really understand. Any help would be great!
tttcowan
Developer
Developer
 
Posts: 46
Joined: Mon Jul 19, 2010 11:08 pm

Top

Re: Problem with glDrawTexfOES

Postby tttcowan » Tue Oct 05, 2010 8:30 pm

I've uploaded an image of the emulator and what it looks like in gimp... Does it look ok? I'm not even sure anymore!!!
Attachments
example.png
example.png (114.32 KiB) Viewed 1056 times
tttcowan
Developer
Developer
 
Posts: 46
Joined: Mon Jul 19, 2010 11:08 pm

Re: Problem with glDrawTexfOES

Postby moblcade.com » Tue Oct 05, 2010 8:57 pm

It looks OK to me...
moblcade.com
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Sep 07, 2010 6:31 pm

Top

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

Who is online

Users browsing this forum: No registered users and 2 guests