Note that there are some explanatory texts on larger screens.

plurals
  1. POopenGL texturing is running on emulator but not on real device
    primarykey
    data
    text
    <p>I'm trying to show textures by openGL. In following code I want to draw simple square with texture. When I run it on android emulator, everything is OK, but when I run it on real device, I can see only white square without any texture.</p> <p><a href="https://stackoverflow.com/questions/8587661/cant-map-textures-with-opengl-es-on-real-devices">There is similar problem</a>, but I don't use NDK. I use only Java.</p> <pre><code>public class MainActivity extends Activity { public static TextView t; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout l = new LinearLayout(this); t = new TextView(this); l.addView(t); l.setOrientation(1); l.addView(new ImageView(this)); setContentView(l); } long last = System.currentTimeMillis(); int FPS = 0; //Show FPS(+ some extraData) public void FPS(final String extraData) { if(System.currentTimeMillis()&lt;last+1000) { FPS++; } else { runOnUiThread(new Runnable(){@Override public void run(){ t.setText((double)FPS/(((double)System.currentTimeMillis()-last)/1000)+";"+extraData); }}); FPS = 0; last = System.currentTimeMillis(); } } public class ImageView extends GLSurfaceView implements GLSurfaceView.Renderer { MainActivity thiz; public ImageView(MainActivity thiz) { super(thiz); this.thiz = thiz; setRenderer(this); } FloatBuffer vertex; ShortBuffer texture; int[] textureID = new int[1]; public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertex); gl.glTexCoordPointer(2, GL10.GL_SHORT, 0, texture); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); thiz.FPS(""); } public void onSurfaceCreated(GL10 gl, EGLConfig arg1) { vertex = FloatBuffer.wrap(new float[]{-0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f}); texture = ShortBuffer.wrap(new short[]{0, 1, 1, 1, 0, 0, 1, 0}); Bitmap b = BitmapFactory.decodeResource(thiz.getResources(), R.drawable.nex2); gl.glGenTextures(1, textureID, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, b, 0); b.recycle(); gl.glClearColor(0.1f, 0.5f, 1f, 1f); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); } public void onSurfaceChanged(GL10 gl, int w, int h) { gl.glViewport(0, 0, w, h); } </code></pre> <p>Can someone look at my code and tell me where is the problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload