different textures to different faces

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

different textures to different faces

Postby Syco » Mon May 03, 2010 2:55 am

Hi, I'm trying to create a simple square with two different textures, one in front and one behind, I made an array of textures, but the result is not expected, makes the second texture on both sides, where am I wrong?
Thank you.

Main.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Syco.glex;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.opengl.GLSurfaceView;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import android.view.Display;
  12.  
  13. import android.view.Window;
  14.  
  15. import android.view.WindowManager;
  16.  
  17.  
  18.  
  19. public class Main extends Activity {
  20.  
  21.     private Display display;
  22.  
  23.     private int width;
  24.  
  25.     private int height;
  26.  
  27.     @Override
  28.  
  29.     public void onCreate(Bundle savedInstanceState) {
  30.  
  31.         super.onCreate(savedInstanceState);
  32.  
  33.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  34.  
  35.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  36.  
  37.  
  38.  
  39.         display=getWindowManager().getDefaultDisplay();
  40.  
  41.         width=display.getWidth();
  42.  
  43.         height=display.getHeight();
  44.  
  45.  
  46.  
  47.         GLSurfaceView view = new GLSurfaceView(this);
  48.  
  49.         view.setRenderer(new myRenderer(this,width,height));
  50.  
  51.         setContentView(view);
  52.  
  53.     }
  54.  
  55. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


myRenderer.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Syco.glex;
  2.  
  3.  
  4.  
  5. import android.content.Context;
  6.  
  7. import javax.microedition.khronos.egl.EGLConfig;
  8.  
  9. import javax.microedition.khronos.opengles.GL10;
  10.  
  11.  
  12.  
  13. import android.opengl.GLU;
  14.  
  15. import android.opengl.GLSurfaceView.Renderer;
  16.  
  17.  
  18.  
  19. public class myRenderer implements Renderer {
  20.  
  21.     private Square[] square=new Square[5];
  22.  
  23.     private int[] p={-4,-2,0,2,4};
  24.  
  25.     private final Context mc;
  26.  
  27.     private final int w;
  28.  
  29.     private final int h;
  30.  
  31.     private final float ww;
  32.  
  33.     private final float hh;
  34.  
  35.     private float angolo=0;
  36.  
  37.  
  38.  
  39.     public myRenderer(Context mc, int w, int h) {
  40.  
  41.         this.mc=mc;
  42.  
  43.         this.w=w;
  44.  
  45.         this.h=h;
  46.  
  47.         this.ww=((float)w)/10;
  48.  
  49.         this.hh=((float)h)/10;
  50.  
  51.         for(int i=0;i<5;i++) {
  52.  
  53.             square[i]=new Square(ww,hh);
  54.  
  55.         }
  56.  
  57.     }
  58.  
  59.     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  60.  
  61.         for(int i=0;i<5;i++) {
  62.  
  63.             square[i].loadGLTexture(gl, mc);
  64.  
  65.         }
  66.  
  67.         gl.glEnable(GL10.GL_TEXTURE_2D);
  68.  
  69.         gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
  70.  
  71.         gl.glShadeModel(GL10.GL_SMOOTH);
  72.  
  73.         gl.glClearDepthf(1.0f);
  74.  
  75.         gl.glEnable(GL10.GL_DEPTH_TEST);
  76.  
  77.         gl.glDepthFunc(GL10.GL_LEQUAL);
  78.  
  79.         gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
  80.  
  81.     }
  82.  
  83.  
  84.  
  85.     public void onDrawFrame(GL10 gl) {
  86.  
  87.         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  88.  
  89.         gl.glLoadIdentity();
  90.  
  91.  
  92.  
  93.         for(int i=0;i<5;i++) {
  94.  
  95.             gl.glPushMatrix();
  96.  
  97.             gl.glTranslatef((float)(p[i]*ww),(float)(4*hh),-600.0f);
  98.  
  99.             gl.glRotatef(angolo, 0.0f, 1.0f, 0.0f);
  100.  
  101.             square[i].draw(gl);
  102.  
  103.             gl.glPopMatrix();
  104.  
  105.         }
  106.  
  107.         angolo+=2;
  108.  
  109.         angolo%=360;
  110.  
  111.     }
  112.  
  113.  
  114.  
  115.     public void onSurfaceChanged(GL10 gl, int width, int height) {
  116.  
  117.         gl.glViewport(0, 0, width, height);
  118.  
  119.         gl.glMatrixMode(GL10.GL_PROJECTION);
  120.  
  121.         GLU.gluPerspective(gl, 45.0f, (float)width/(float)height, 1.0f, 700.0f);
  122.  
  123.         gl.glMatrixMode(GL10.GL_MODELVIEW);
  124.  
  125.         gl.glLoadIdentity();
  126.  
  127.     }
  128.  
  129. }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Square.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Syco.glex;
  2.  
  3.  
  4.  
  5. import android.content.Context;
  6.  
  7. import android.graphics.Bitmap;
  8.  
  9. import android.graphics.BitmapFactory;
  10.  
  11. import android.opengl.GLUtils;
  12.  
  13. import java.nio.ByteBuffer;
  14.  
  15. import java.nio.ByteOrder;
  16.  
  17. import java.nio.FloatBuffer;
  18.  
  19. import java.nio.ShortBuffer;
  20.  
  21.  
  22.  
  23. import javax.microedition.khronos.opengles.GL10;
  24.  
  25.  
  26.  
  27. public class Square {
  28.  
  29.     private float[] vertices;
  30.  
  31.     private float[] texture;
  32.  
  33.     private int[] textures=new int[2];
  34.  
  35.     private short[] indices = {0, 1, 2, 0, 2, 3,
  36.  
  37.                                0, 2, 1, 0, 3, 2 };
  38.  
  39.     private FloatBuffer vertexBuffer;
  40.  
  41.     private ShortBuffer indexBuffer;
  42.  
  43.     private FloatBuffer textureBuffer;
  44.  
  45.  
  46.  
  47.     public Square(float w, float h) {
  48.  
  49.         vertices=new float[]{
  50.  
  51.             -w, h, 0.0f,  // t l
  52.  
  53.             -w, -h, 0.0f, // b l
  54.  
  55.             w, -h, 0.0f,  // b r
  56.  
  57.             w, h, 0.0f    // t r
  58.  
  59.         };
  60.  
  61.         texture=new float[] {
  62.  
  63.             1.0f, 0.0f,  // b r
  64.  
  65.             1.0f, 1.0f,  // t r
  66.  
  67.             0.0f, 1.0f,  // t l
  68.  
  69.             0.0f, 0.0f,  // b l
  70.  
  71.  
  72.  
  73.             0.0f, 0.0f,  // b l
  74.  
  75.             0.0f, 1.0f,  // t l
  76.  
  77.             1.0f, 1.0f,  // t r
  78.  
  79.             1.0f, 0.0f,  // b r
  80.  
  81.         };
  82.  
  83.  
  84.  
  85.         ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
  86.  
  87.         vbb.order(ByteOrder.nativeOrder());
  88.  
  89.         vertexBuffer = vbb.asFloatBuffer();
  90.  
  91.         vertexBuffer.put(vertices);
  92.  
  93.         vertexBuffer.position(0);
  94.  
  95.        
  96.  
  97.         vbb = ByteBuffer.allocateDirect(texture.length * 4);
  98.  
  99.         vbb.order(ByteOrder.nativeOrder());
  100.  
  101.         textureBuffer = vbb.asFloatBuffer();
  102.  
  103.         textureBuffer.put(texture);
  104.  
  105.         textureBuffer.position(0);
  106.  
  107.  
  108.  
  109.         vbb = ByteBuffer.allocateDirect(indices.length * 2);
  110.  
  111.         vbb.order(ByteOrder.nativeOrder());
  112.  
  113.         indexBuffer = vbb.asShortBuffer();
  114.  
  115.         indexBuffer.put(indices);
  116.  
  117.         indexBuffer.position(0);
  118.  
  119.     }
  120.  
  121.  
  122.  
  123.     public void draw(GL10 gl) {
  124.  
  125.  
  126.  
  127.         gl.glEnable(GL10.GL_CULL_FACE);
  128.  
  129.         gl.glCullFace(GL10.GL_BACK);
  130.  
  131.         gl.glFrontFace(GL10.GL_CCW);
  132.  
  133.  
  134.  
  135.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  136.  
  137.         gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  138.  
  139.  
  140.  
  141.         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
  142.  
  143.         gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
  144.  
  145.         gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
  146.  
  147.  
  148.  
  149.         gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  150.  
  151.         gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  152.  
  153.  
  154.  
  155.         gl.glDisable(GL10.GL_CULL_FACE);
  156.  
  157.     }
  158.  
  159.  
  160.  
  161.     public void loadGLTexture(GL10 gl, Context context) {
  162.  
  163.         gl.glGenTextures(2, textures, 0);
  164.  
  165.  
  166.  
  167.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
  168.  
  169.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
  170.  
  171.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  172.  
  173.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  174.  
  175.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  176.  
  177.  
  178.  
  179.         Bitmap bitmap1=BitmapFactory.decodeResource(context.getResources(), R.drawable.front);
  180.  
  181.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap1, 0);
  182.  
  183.         bitmap1.recycle();
  184.  
  185.        
  186.  
  187.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
  188.  
  189.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
  190.  
  191.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  192.  
  193.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  194.  
  195.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  196.  
  197.  
  198.  
  199.         Bitmap bitmap2=BitmapFactory.decodeResource(context.getResources(), R.drawable.back);
  200.  
  201.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap2, 0);
  202.  
  203.         bitmap2.recycle();
  204.  
  205.     }
  206.  
  207.  
  208.  
  209. }
  210.  
  211.  
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Top

Postby zorro » Mon May 03, 2010 7:10 am

You are calling glBindTexture only when you load the textures, but not in the drawing loop. This way, your active texture is the last one that was loaded, so the first one is never used.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Syco » Mon May 03, 2010 9:37 am

i modified the draw function in this way
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void draw(GL10 gl) {
  2.  
  3.  
  4.  
  5.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
  6.  
  7.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
  8.  
  9.  
  10.  
  11.         gl.glEnable(GL10.GL_CULL_FACE);
  12.  
  13.         gl.glCullFace(GL10.GL_BACK);
  14.  
  15.         . . .
  16.  
  17.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

but it still load only the second texture on both faces.
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Postby zorro » Mon May 03, 2010 9:56 am

It's normal, only the last bind remains active.
You have to:
- bind first texture
- draw one face
- bind second texture
- draw second face

This way will work.. in theory. The 2 quads share the same plane so you could see artifacts (the 2 pictures overlapping). You could draw only the visible face to get rid of any problem.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Syco » Mon May 03, 2010 10:18 am

so it's better if I draw two different square with two textures, no matter if they are drawn at the same position?
I'll let you know if it works this way.
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Postby zorro » Mon May 03, 2010 10:26 am

You can draw 2 textures in a single quad only with multitexturing, but it's not worth it in your case. The simplest solution is to draw 2 quads in the same position, each with it's own texture.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Top

Postby Syco » Mon May 03, 2010 5:39 pm

it's possible to draw 2 quads in the same class?
I've replicated the code of vertices and textures, but it still draw one quad with the second texture on both sides
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Syco.glex;
  2.  
  3.  
  4.  
  5. import android.content.Context;
  6.  
  7. import android.graphics.Bitmap;
  8.  
  9. import android.graphics.BitmapFactory;
  10.  
  11. import android.opengl.GLUtils;
  12.  
  13. import java.nio.ByteBuffer;
  14.  
  15. import java.nio.ByteOrder;
  16.  
  17. import java.nio.FloatBuffer;
  18.  
  19. import java.nio.ShortBuffer;
  20.  
  21.  
  22.  
  23. import javax.microedition.khronos.opengles.GL10;
  24.  
  25.  
  26.  
  27. public class Square {
  28.  
  29.     private float[] vertices1;
  30.  
  31.     private float[] texture1;
  32.  
  33.     private int[] textures1=new int[1];
  34.  
  35.     private short[] indices1 = {0, 1, 2, 0, 2, 3};
  36.  
  37.     private FloatBuffer vertexBuffer1;
  38.  
  39.     private ShortBuffer indexBuffer1;
  40.  
  41.     private FloatBuffer textureBuffer1;
  42.  
  43.  
  44.  
  45.     private float[] vertices2;
  46.  
  47.     private float[] texture2;
  48.  
  49.     private int[] textures2=new int[1];
  50.  
  51.     private short[] indices2 = {0, 2, 1, 0, 3, 2};
  52.  
  53.     private FloatBuffer vertexBuffer2;
  54.  
  55.     private ShortBuffer indexBuffer2;
  56.  
  57.     private FloatBuffer textureBuffer2;
  58.  
  59.  
  60.  
  61.     public Square(float w, float h) {
  62.  
  63.         vertices1=new float[]{
  64.  
  65.             -w, h, 0.0f,  // t l
  66.  
  67.             -w, -h, 0.0f, // b l
  68.  
  69.             w, -h, 0.0f,  // b r
  70.  
  71.             w, h, 0.0f    // t r
  72.  
  73.         };
  74.  
  75.         vertices2=new float[]{
  76.  
  77.             -w, h, 0.0f,  // t l
  78.  
  79.             -w, -h, 0.0f, // b l
  80.  
  81.             w, -h, 0.0f,  // b r
  82.  
  83.             w, h, 0.0f    // t r
  84.  
  85.         };
  86.  
  87.         texture1=new float[] {
  88.  
  89.             1.0f, 0.0f,  // b r
  90.  
  91.             1.0f, 1.0f,  // t r
  92.  
  93.             0.0f, 1.0f,  // t l
  94.  
  95.             0.0f, 0.0f,  // b l
  96.  
  97.         };
  98.  
  99.         texture2=new float[] {
  100.  
  101.             1.0f, 0.0f,  // b r
  102.  
  103.             1.0f, 1.0f,  // t r
  104.  
  105.             0.0f, 1.0f,  // t l
  106.  
  107.             0.0f, 0.0f,  // b l
  108.  
  109.         };
  110.  
  111.  
  112.  
  113.         ByteBuffer vbb;
  114.  
  115.         vbb = ByteBuffer.allocateDirect(vertices1.length * 4);
  116.  
  117.         vbb.order(ByteOrder.nativeOrder());
  118.  
  119.         vertexBuffer1 = vbb.asFloatBuffer();
  120.  
  121.         vertexBuffer1.put(vertices1);
  122.  
  123.         vertexBuffer1.position(0);
  124.  
  125.        
  126.  
  127.         vbb = ByteBuffer.allocateDirect(texture1.length * 4);
  128.  
  129.         vbb.order(ByteOrder.nativeOrder());
  130.  
  131.         textureBuffer1 = vbb.asFloatBuffer();
  132.  
  133.         textureBuffer1.put(texture1);
  134.  
  135.         textureBuffer1.position(0);
  136.  
  137.  
  138.  
  139.         vbb = ByteBuffer.allocateDirect(indices1.length * 2);
  140.  
  141.         vbb.order(ByteOrder.nativeOrder());
  142.  
  143.         indexBuffer1 = vbb.asShortBuffer();
  144.  
  145.         indexBuffer1.put(indices1);
  146.  
  147.         indexBuffer1.position(0);
  148.  
  149.  
  150.  
  151.         vbb = ByteBuffer.allocateDirect(vertices2.length * 4);
  152.  
  153.         vbb.order(ByteOrder.nativeOrder());
  154.  
  155.         vertexBuffer2 = vbb.asFloatBuffer();
  156.  
  157.         vertexBuffer2.put(vertices2);
  158.  
  159.         vertexBuffer2.position(0);
  160.  
  161.  
  162.  
  163.         vbb = ByteBuffer.allocateDirect(texture2.length * 4);
  164.  
  165.         vbb.order(ByteOrder.nativeOrder());
  166.  
  167.         textureBuffer2 = vbb.asFloatBuffer();
  168.  
  169.         textureBuffer2.put(texture2);
  170.  
  171.         textureBuffer2.position(0);
  172.  
  173.  
  174.  
  175.         vbb = ByteBuffer.allocateDirect(indices2.length * 2);
  176.  
  177.         vbb.order(ByteOrder.nativeOrder());
  178.  
  179.         indexBuffer2 = vbb.asShortBuffer();
  180.  
  181.         indexBuffer2.put(indices2);
  182.  
  183.         indexBuffer2.position(0);
  184.  
  185.     }
  186.  
  187.  
  188.  
  189.     public void draw(GL10 gl) {
  190.  
  191.  
  192.  
  193.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures1[0]);
  194.  
  195.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures2[0]);
  196.  
  197.  
  198.  
  199.         gl.glEnable(GL10.GL_CULL_FACE);
  200.  
  201.         gl.glCullFace(GL10.GL_BACK);
  202.  
  203.         gl.glFrontFace(GL10.GL_CCW);
  204.  
  205.  
  206.  
  207.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  208.  
  209.         gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  210.  
  211.  
  212.  
  213.         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer1);
  214.  
  215.         gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer1);
  216.  
  217.         gl.glDrawElements(GL10.GL_TRIANGLES, indices1.length, GL10.GL_UNSIGNED_SHORT, indexBuffer1);
  218.  
  219.  
  220.  
  221.         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer2);
  222.  
  223.         gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer2);
  224.  
  225.         gl.glDrawElements(GL10.GL_TRIANGLES, indices2.length, GL10.GL_UNSIGNED_SHORT, indexBuffer2);
  226.  
  227.  
  228.  
  229.         gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  230.  
  231.         gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  232.  
  233.  
  234.  
  235.         gl.glDisable(GL10.GL_CULL_FACE);
  236.  
  237.     }
  238.  
  239.  
  240.  
  241.     public void loadGLTexture(GL10 gl, Context context) {
  242.  
  243.  
  244.  
  245.         gl.glGenTextures(1, textures1, 0);
  246.  
  247.  
  248.  
  249.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures1[0]);
  250.  
  251.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
  252.  
  253.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  254.  
  255.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  256.  
  257.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  258.  
  259.  
  260.  
  261.         Bitmap bitmap1=BitmapFactory.decodeResource(context.getResources(), R.drawable.front);
  262.  
  263.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap1, 0);
  264.  
  265.         bitmap1.recycle();
  266.  
  267.  
  268.  
  269.         gl.glGenTextures(1, textures2, 0);
  270.  
  271.        
  272.  
  273.         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures2[0]);
  274.  
  275.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
  276.  
  277.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  278.  
  279.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
  280.  
  281.         gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
  282.  
  283.  
  284.  
  285.         Bitmap bitmap2=BitmapFactory.decodeResource(context.getResources(), R.drawable.back);
  286.  
  287.         GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap2, 0);
  288.  
  289.         bitmap2.recycle();
  290.  
  291.     }
  292.  
  293.  
  294.  
  295. }
  296.  
  297.  
Parsed in 0.058 seconds, using GeSHi 1.0.8.4
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Postby Syco » Mon May 03, 2010 5:49 pm

I've just made another test, that code draws two different quads, but they have both the second texture.
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Postby zorro » Tue May 04, 2010 6:54 am

Your drawing loop is:

- bind texture 1
- bind texture 2
- draw quad 1
- draw quad 2

That's not gonna work because the last binded texture is the one that matters, like i told you before. Just draw like this:

- bind texture 1
- draw quad
- bind texture 2
- draw quad
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Syco » Tue May 04, 2010 10:45 am

I modified the draw method as you say, now it works, tnx!
Syco
Freshman
Freshman
 
Posts: 8
Joined: Sun Apr 18, 2010 5:41 pm

Top

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

Who is online

Users browsing this forum: No registered users and 10 guests