How to Access a GL10 object for texture loading

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

How to Access a GL10 object for texture loading

Postby merwin2 » Tue Apr 27, 2010 4:13 pm

My problem is that I want to load this object and texture when the application starts (since it takes a few seconds). The GLSurfaceView is not the initial view. So how do I access the GL10 instance in Renderer in order to call this routine?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void loadGLTexture(GL10 gl, Context context) {
  3.  
  4.         //Get the texture from the Android resource directory
  5.  
  6.         InputStream is = context.getResources().openRawResource(R.drawable.wheel);
  7.  
  8.         Bitmap bitmap = null;
  9.  
  10.         try {
  11.  
  12.                 bitmap = BitmapFactory.decodeStream(is);
  13.  
  14.         } finally {
  15.  
  16.                 try {
  17.  
  18.                         is.close();
  19.  
  20.                         is = null;
  21.  
  22.                 } catch (IOException e) {
  23.  
  24.                 }
  25.  
  26.         }
  27.  
  28.  
  29.  
  30.         gl.glGenTextures(1, textures, 0);
  31.  
  32.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
  33.  
  34.                        
  35.  
  36.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
  37.  
  38.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  39.  
  40.  
  41.  
  42.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  43.  
  44.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  45.  
  46.                        
  47.  
  48.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
  49.  
  50.                        
  51.  
  52.         bitmap.recycle();
  53.  
  54. }
  55.  
  56.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
merwin2
Freshman
Freshman
 
Posts: 6
Joined: Mon Apr 26, 2010 4:00 pm

Top

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

Who is online

Users browsing this forum: No registered users and 3 guests