Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Opengl doesn't render my display like emulator
    primarykey
    data
    text
    <p>I recently i stumbled accross a weird problem(or at least i think so).I made in a little opengl es app for Android.The problem is that on the emulator it run's fine but on the phone it just doesn't render what the emulator showed me! I tested the app on 2 devices:Samsung Ace and Sony Xperia x10 with the same result! I just don't know what is the problem(i don't have too much experience with opengl on android) so please if you have some ideas... point me out Some code:</p> <p>Class that implements Renderer</p> <pre><code>public class GLOrbitor implements Renderer{ OrbitorLayer layer; TexFont text; //this is used to render 1-9 and A-Z TexFont text1; //this one to render a-z int x; int y; private int atomNumber; private int width; private int height; private Context context; private final static float consty = 0.15f; GLOrbitor(Context context){ setContext(context); } @Override public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub gl.glDisable(GL10.GL_DITHER); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, 5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); gl.glPushMatrix(); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnable(GL10.GL_BLEND); // We know this is a 32bit font so set blending to suit gl.glBlendFunc(GL10.GL_SRC_ALPHA,GL10.GL_ONE_MINUS_SRC_ALPHA); drawNumAndLetters(gl); gl.glDisable(GL10.GL_BLEND); gl.glDisable(GL10.GL_TEXTURE_2D); gl.glPopMatrix(); gl.glPushMatrix(); //gl.glTranslatef(-0.8f, 0.8f, 0f); layer.draw(gl,getAtomNumber()); gl.glPopMatrix(); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { // TODO Auto-generated method stub gl.glViewport(0,0, width, height); this.width = width; this.height = height; float ratio = (float)width/height; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, 1, 1, 3, 7); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { layer = new OrbitorLayer(); text = new TexFont(getContext(),gl); text1 = new TexFont(getContext(),gl); try { text.LoadFont("ubunturegular.bff", gl); // 0-9 and A-Z text1.LoadFont("ubunturegular1.bff", gl); //a-z } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TODO Auto-generated method stub gl.glDisable(GL10.GL_DITHER); gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_NICEST); gl.glClearColor(0.0f,0.0f,0.0f, 1f); gl.glEnable(GL10.GL_DEPTH_TEST | GL10.GL_SMOOTH); gl.glShadeModel(GL10.GL_SMOOTH); gl.glFrontFace(GL10.GL_CCW); //gl.glEnable(GL10.GL_CULL_FACE); //gl.glCullFace(GL10.GL_BACK); } </code></pre> <p>}`</p> <p>//this code draw a tiny rectangle</p> <pre><code>public GLRectangle(){ setFilled(false); ByteBuffer vbb = ByteBuffer.allocateDirect(12 * 4); vbb.order(ByteOrder.nativeOrder()); mFVertexBuffer = vbb.asFloatBuffer(); ByteBuffer ibb = ByteBuffer.allocateDirect(6 * 2); ibb.order(ByteOrder.nativeOrder()); mIndexBuffer = ibb.asShortBuffer(); float[] coords = { -poz, -poz, 0, poz, -poz, 0, poz, poz, 0, -poz,poz,0 }; mFVertexBuffer.put(coords); short[] myIndecesArray = {0,1,2,0,2,3}; mIndexBuffer.put(myIndecesArray); mFVertexBuffer.position(0); mIndexBuffer.position(0); } public void draw(GL10 gl) { if(isFilled()) gl.glColor4f(1f, 0f, 0f, 1f); else gl.glColor4f(1f, 1f, 1f, 1f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, 6,GL10.GL_UNSIGNED_SHORT, mIndexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } </code></pre> <p>//and this one draw an array of rectangles</p> <pre><code>public class OrbitorLayer { GLRectangle[] rectangle; GLMargin margin; private final static float consty = 0.15f; OrbitorLayer(){ margin = new GLMargin(); rectangle = new GLRectangle[118]; } public void draw(GL10 gl,int atomNumber){ for(int i = 0;i&lt;118;i++){ rectangle[i] = new GLRectangle(); if((i&gt;=0) &amp;&amp; (i&lt;atomNumber)) rectangle[i].setFilled(true); } //there's some exception for chromium with z = 24 and copper with z=29 //they have 4s1 and 3d5 also 4s1 and 3d10 if(atomNumber == 24){ //4s2 is at 19 and 24 rectangle[19].setFilled(false); rectangle[24].setFilled(true); } else if(atomNumber == 29){ //3d10 is at 29 rectangle[19].setFilled(false); rectangle[29].setFilled(true); } gl.glPushMatrix(); margin.draw(gl); gl.glPopMatrix(); int index = -1; float startx = -0.9f; float starty = 0.8f; //start with 1s layer for(int i=0;i&lt;2;i++){ index++; //rectangle[index] = new GLRectangle(); //translate and draw gl.glPushMatrix(); gl.glTranslatef((float) (startx + (i * 0.05)), starty, 0.0f); rectangle[index].draw(gl); gl.glPopMatrix(); } //2 s layer startx = -0.9f; starty = (float)(0.8f - (1 * consty)); for(int i=0;i&lt;2;i++){ index++; //rectangle[index] = new GLRectangle(); //translate and draw gl.glPushMatrix(); gl.glTranslatef((float) (startx + (i * 0.05)), starty, 0.0f); rectangle[index].draw(gl); gl.glPopMatrix(); } //2 p layer startx = 0.7f; starty = (float)(0.8f - (1 * consty)); for(int i=0;i&lt;6;i++){ index++; //rectangle[index] = new GLRectangle(); //translate and draw gl.glPushMatrix(); gl.glTranslatef((float) (startx + (i * 0.05)), starty, 0.0f); rectangle[index].draw(gl); gl.glPopMatrix(); } </code></pre> <p>}</p> <p>And a screenshot on how it's rendered on emulator<img src="https://i.stack.imgur.com/Ii9oT.png" alt="enter image description here"> On a real android smartphone those filled rectangles and blue rounded shape aren't visible only the letters and number's which are drawn with these code <a href="http://www.codehead.co.uk/cbfg/TexFont.java" rel="nofollow noreferrer">http://www.codehead.co.uk/cbfg/TexFont.java</a></p> <p>If you have some ideas please don't hesitate!</p> <hr> <p><strong>Update:</strong></p> <p>Thank you Craigy and Matthew</p> <p>Craigy:On a real phone i can't see those red and white little rectangles. Everything else work as exepected.By the way :only the the zone that fill the blue rectangle is an GLSurfaceView everything else has no link with opengl!Sorry if i can't provide a screenshot from a real device.My app was tested by 2 friends on their device's.</p> <p>Matthew:the only thing where i use texture is displaying:1,2,3,4,5,6,7 and s,f,d,p.And what's funny is that they are rendered well on a real device.My question is why drawing texture's affects drawing and translating those rectangles.Anyway i will play a little more with the info you suggested me and i will let you guys now!</p> <p>If you have any new intel about these problem...please i beg you..it's driving me nut's just displaying a few rectangles and some text give me so much problem's!!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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