2012-09-29 13 views
12

में काम कर रहा है क्या ओपनजीएल ऐप्स चलाने के लिए कोई विशेष एमुलेटर सेटिंग्स आवश्यक है?जीएल वॉलपेपर उदाहरण केवल एमुलेटर में हरे रंग की स्क्रीन दिखाता है, लेकिन यह डिवाइस

मैंने पहले ही "जीपीयू इम्यूलेशन" संपत्ति को "हां" में सेट किया है।

मैं this link से प्राप्त नमूना स्रोत का उपयोग करके एक एंड्रॉइड नमूना लाइव वॉलपेपर चलाने की कोशिश कर रहा हूं, वांछित आउटपुट एक घूर्णन त्रिकोण है।

थोड़ा प्रयास करने के बाद मुझे ऐप चल रहा था लेकिन यह एमुलेटर में कुछ भी नहीं खींचता है, लेकिन जब मैं डिवाइस में परीक्षण करता हूं तो यह काम करता है, लेकिन एम्यूलेटर में यह अभी भी एक हरे रंग की स्क्रीन दिखाता है, मुझे इसमें एक चर्चा मिली Google groups here। मैंने दृश्य पोर्ट को सेट करने की कोशिश की जैसा कि इसमें कहा गया था। लेकिन फिर भी यह कोई परिणाम नहीं दिखाता है, सतह पर बदल गया है मैंने इस लाइन को

gl.glViewport (0, 0, चौड़ाई, ऊंचाई) जोड़ा था;

क्या यह दृश्य पोर्ट सेट करने का सही तरीका है?

यह मेरी कक्षा प्रस्तुत करना,

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); 
    } 
} 

Herse 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; 
    } 
} 

गलत यहाँ क्या हो रहा है? क्या ओपन जीएल लाइव वॉलपेपर के लिए एक बेहतर नमूना कोड है?

+1

अपने एम्यूलेटर AVD सेटिंग्स में, आप "GPU अनुकरण" गुण सेट करने के लिए "हाँ" ? एवीडी कॉन्फ़िगरेशन में भी 'hw.gpu.enabled' प्रॉपर्टी है। – kelnos

+0

हां मैंने पहले ही "जीपीयू इम्यूलेशन" प्रॉपर्टी को "हां" पर सेट किया है, लेकिन सोरी मुझे यह नहीं लगता कि "एवीडी कॉन्फ़िगरेशन में यह भी है hw.gpu.enabled प्रॉपर्टी" –

उत्तर

2

आख़िरकार मुझे मिल गया ..

मैं क्या करने की जरूरत सिर्फ जोड़ने है में onSurfaceCreated

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 

को विधि कोड लाइन के साथ-साथ

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

ऑनसफेस चेंजमें विधि MyRenderer Cl गधा

मैं stack itself में एक समान प्रश्न पाया [लेकिन समाधान मेरे लिए काम किया के रूप में सही चिह्नित नहीं है :(]

संबंधित मुद्दे