2012-09-29 6 views
12

Esistono impostazioni di emulazione speciali necessarie per eseguire le app OpenGL?L'esempio GL Wallpaper mostra solo una schermata verde in Emulator, ma funziona nel dispositivo

Ho già impostato la proprietà "emulazione GPU" su "sì".

Sto provando a eseguire uno sfondo del campione Android, utilizzando la fonte di esempio trovata da this link, l'output desiderato è un triangolo rotante.

Dopo un po 'di sforzo ho avuto l'applicazione in esecuzione, ma non disegna nulla in emulatore, ma quando ho provato a dispositivo funziona, ma nell'emulatore ancora mostra solo uno schermo verde, ho trovato una discussione su di essa nel Google groups here. Ho provato ad impostare la porta di visualizzazione come detto in essa. Ma ancora non mostra alcun risultato, sulla superficie modificata ho aggiunto questa riga

gl.glViewport (0, 0, larghezza, altezza);

Questo è il modo corretto di impostare la porta di visualizzazione?

Questa è la mia classe di rendering,

public class MyRenderer implements GLWallpaperService.Renderer { 
    GLTriangle mTriangle; 

    public void onDrawFrame(GL10 gl) { 


     gl.glClearColor(0.2f, 0.4f, 0.2f, 1f); 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     autoRotate(gl); 
     gl.glColor4f(.2f, 0f, .5f, 1f); 

     mTriangle.draw(gl); 
    } 

    public void onSurfaceChanged(GL10 gl, int width, int height) { 

     gl.glViewport(0, 0, width, height); 
     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 
     GLU.gluPerspective(gl, 60f, (float)width/(float)height, 1f, 100f); 

     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
     gl.glTranslatef(0, 0, -5); 
    } 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     mTriangle = new GLTriangle(); 



     gl.glClearDepthf(1f); 
     gl.glEnable(GL10.GL_DEPTH_TEST); 
     gl.glDepthFunc(GL10.GL_LEQUAL); 
    } 

    /** 
    * Called when the engine is destroyed. Do any necessary clean up because 
    * at this point your renderer instance is now done for. 
    */ 
    public void release() { 

    } 

    private void autoRotate(GL10 gl) { 
     gl.glRotatef(1, 0, 1, 0); 
     gl.glRotatef(0.5f, 1, 0, 0); 
    } 
} 

Erse è di classe GLTriangle

import java.nio.FloatBuffer; 
import java.nio.ShortBuffer; 

import javax.microedition.khronos.opengles.GL10; 

public class GLTriangle { 
    private FloatBuffer _vertexBuffer; 
    private final int _nrOfVertices = 3; 

    private ShortBuffer _indexBuffer; 

    public GLTriangle() { 
     init(); 
    } 

    private void init() { 
     // We use ByteBuffer.allocateDirect() to get memory outside of 
     // the normal, garbage collected heap. I think this is done 
     // because the buffer is subject to native I/O. 
     // See http://download.oracle.com/javase/1.4.2/docs/api/java/nio/ByteBuffer.html#direct 

     // 3 is the number of coordinates to each vertex. 
     _vertexBuffer = BufferFactory.createFloatBuffer(_nrOfVertices * 3); 

     _indexBuffer = BufferFactory.createShortBuffer(_nrOfVertices); 

     // Coordinates for the vertexes of the triangle. 
     float[] coords = { 
       -1f, -1f, 0f, // (x1, y1, z1) 
       1f, -1f, 0f, // (x2, y2, z2) 
       0f, 1f, 0f // (x3, y3, z3) 
     }; 

     short[] _indicesArray = {0, 1, 2}; 

     _vertexBuffer.put(coords); 
     _indexBuffer.put(_indicesArray); 

     _vertexBuffer.position(0); 
     _indexBuffer.position(0); 
    } 

    public void draw(GL10 gl) { 
     // 3 coordinates in each vertex 
     // 0 is the space between each vertex. They are densely packed 
     // in the array, so the value is 0 
     gl.glVertexPointer(3, GL10.GL_FLOAT, 0, getVertexBuffer()); 

     // Draw the primitives, in this case, triangles. 
     gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer); 
    } 

    private FloatBuffer getVertexBuffer() { 
     return _vertexBuffer; 
    } 
} 

cosa sta andando male qui? Esiste un codice di esempio migliore per lo sfondo animato Open GL?

+1

Nelle impostazioni emulatore AVD, ho si imposta la proprietà "emulazione GPU" per "sì" ? Nella configurazione AVD è anche la proprietà 'hw.gpu.enabled'. – kelnos

+0

Sì, ho già impostato la proprietà "Emulazione GPU" su "sì", ma Sory non capisco cosa intendi con "Nella configurazione AVD che è anche la proprietà hw.gpu.enabled" –

risposta

2

FINALMENTE L'ho trovata ..

Che cosa devo fare è semplicemente aggiungere

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 

a onSurfaceCreated metodo insieme alla linea di codice

gl.glViewport(0, 0, width, height); 

nel Metodo OnSurfaceChanged in MyRenderer Cl Ass

ho trovato una domanda simile in stack itself[Ma soluzione ha funzionato per me non è contrassegnato come corretta :(]