2011-02-14 16 views
23

मैं एंड्रॉइड के लिए एक सूचना विजुअलाइजेशन एपीआई लिख रहा हूं और कस्टम GLSurfaceView की दो इकाइयों को लेआउट में रखने की कोशिश करने में एक समस्या में भाग गया। इस बिंदु पर कस्टम GLSurfaceView कस्टम तरीकों के कारण संभावित दोषों को खत्म करने के लिए बस GLSurfaceView का विस्तार है।मैं एक ही लेआउट में एकाधिक GLSurfaceView घटकों का उपयोग कैसे कर सकता हूं?

जब मेरे पास दोनों घटक लेआउट में जोड़े जाते हैं और एप्लिकेशन को चलाते हैं तो यह चलता है। लेकिन कुछ भी नहीं खींचा गया है, ऐसा लगता है जैसे यह एक अनंत लूप में प्रवेश करता है। क्योंकि प्रस्तुतकर्ताओं के अंदर डीबग संदेश लॉगकैट में मुद्रित होते हैं। हालांकि, यह पूरी तरह से ठीक काम करता है अगर मैं केवल कस्टम GLSurfaceView घटकों में से एक का उपयोग करता हूं।

मैंने पढ़ा है कि कई क्रियाओं में GLSurfaceView का उपयोग करने में कोई समस्या है और मुझे लगता है कि यह एक ही समय में उन दो घटकों का उपयोग करते समय भी लागू होता है। मैंने here पोस्ट किए गए वर्कअराउंड की कोशिश की है लेकिन ऐसा लगता है कि यह काम करने के लिए प्रतीत नहीं होता है।

मैं किसी भी मदद की सराहना करता हूं। मैं बेहतर प्रदर्शन के लिए ओपनजीएल का उपयोग करना चुनता हूं, लेकिन अगर मैं एक बार में कई घटकों का उपयोग नहीं कर सकता तो मुझे लगता है कि मुझे इसके बजाय कैनवास का उपयोग करना होगा।

प्रकट रूप में निम्न प्रकार है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:text="@string/hello" android:id="@+id/TextView01" 
     android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview" 
     android:layout_width="fill_parent" android:layout_height="300px" /> 


    <TextView android:text="@string/hello" android:id="@+id/TextView02" 
     android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    <LinearLayout 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview2" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

    </LinearLayout> 

</LinearLayout> 

गतिविधि से कोड इस तरह है:

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 

    mSurfaceView = (VisualizationView) findViewById(R.id.glview); 
    mSurfaceView2 = (VisualizationView) findViewById(R.id.glview2); 

    //Enables debug flags for Errors 
    //mSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR); 
    //mSurfaceView2.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR); 

    mSurfaceView.setRenderer(new CoordinateSystemRenderer()); 
    mSurfaceView2.setRenderer(new CoordinateSystemRenderer()); 

} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    mSurfaceView.onPause(); 
    mSurfaceView2.onPause(); 
} 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 
    mSurfaceView.onResume(); 
    mSurfaceView2.onResume(); 
} 

मैं कुछ स्पष्ट याद आ रही है? या कोई बता सकता है कि यह क्यों काम नहीं करता है?

+1

पहली बात यह है कि मुझ पर बाहर कूदता है कि आपके नेस्टेड LinearLayout fill_parent पर सेट किया जाता है। मैं यह सुनिश्चित करने के लिए जांच करूंगा कि आपके दोनों GLSurfaceViews को शून्य-शून्य ऊंचाई के साथ रखा जा रहा है। यह मामला हो सकता है कि वे दोनों चित्रकारी हैं, लेकिन एक की 0 पिक्सेल की ऊंचाई है और इसलिए अदृश्य है। दो 'GLSurfaceViews' के बजाय –

+0

, अपने आप को बनाने के लिए/एक जीएल धागा और संदर्भ का प्रबंधन, दो' SurfaceViews' (नहीं 'GLSurfaceViews') के लिए आवेदन है कि बेहतर हो सकता है। [फ्रेडन की चर्चा और ग्राफिका से लिंक] देखें (http://stackoverflow.com/a/22746240/199364)। – ToolmakerSteve

उत्तर

0

जीएलएसफ़ेसटेक्स्ट के प्रबंधन के साथ जीएलएसयूफेस व्यू के पीछे बहुत कुछ चल रहा है, मुझे पूरा यकीन है कि आप इसे काम नहीं कर पाएंगे, भले ही आप सफल हों तो आपको बाद में अधिक अप्रत्याशित समस्याएं मिल सकती हैं। तो मुझे सच में विश्वास है कि यह सही अनुप्रयोग वास्तुकला नहीं है।

8

[अद्यतन: यह उत्तर अब एंड्रॉइड 5.0 (लॉलीपॉप) के रूप में सही नहीं है। चर्चा के लिए fadden's answer देखें, और लिंक। It was also incorrect as of Android 2.0, and apparently was only an issue for OVERLAPPING surfaces even before then.]

आप एक गतिविधि में 2 SurfaceViews (एसवी) नहीं लगा सकेंगे। समझने के लिए कि आपको क्यों पता होना चाहिए कि एसवी कैसे काम करता है।

जब आप इसे और गतिविधि यह वास्तव में does not पर जगह बनाने के लिए, गतिविधि (या इसके ऊपर) में रखा जाएगा बजाय यह है कि गतिविधि में बनाए गए "पारदर्शी" दृश्य के साथ वर्तमान गतिविधि का पीछे बनाया जाएगा।

एंड्रॉइड 4.0 (एपीआई 14) में TextureView नामक नया दृश्य है पुराने प्लेटफॉर्म पर ऐसा कुछ बनाने का कोई तरीका नहीं है।

+1

क्या आप इसके बारे में निश्चित हैं? मैंने केवल सोचा कि सीमा है, कि आप उन्हें एक-दूसरे से ऊपर या ओवरलैपिंग नहीं कर सकते हैं। कहा जा रहा है कि आप एक सतही दृश्य पर videoview नहीं दिखा सकते हैं क्योंकि videoview सतहदृश्य बढ़ाता है ... – WarrenFaith

+0

हाँ, मुझे यकीन है। आप समय पर एसवी के केवल एक उदाहरण का उपयोग कर सकते हैं। – pepyakin

+0

यदि आपके पास कोई स्रोत है तो क्या आप एक स्रोत प्रदान कर सकते हैं? मुझे पूर्ण एसवी विषय में बहुत दिलचस्पी है। धन्यवाद! – WarrenFaith

0

आप डालने/के तहत बिछाने एक पूर्ण स्क्रीन GLSurfaceView का उपयोग कर स्क्रीन के 'सही' क्षेत्र में अपने मॉडल की जाँच करना चाहते हो सकता है। आप इस सरल, या शायद पूर्ण स्क्रीन GLSurfaceView पर एकाधिक व्यूपोर्ट्स का उपयोग करने के लिए कुछ प्रकार के लेआउट ढांचे को एक साथ रखना चाह सकते हैं। ओपनजीएल ईएस में इन्हें आजमाया नहीं है, लेकिन आम तौर पर इनमें से किसी भी विधि का उपयोग एकाधिक जीएलसीएन्टेक्सट्स (यदि ऐसा है तो एक डेस्कटॉप सिस्टम पर एक ही एप्लीकेशन में एक ही या कई अलग-अलग मॉडलों के कई दृश्य प्रस्तुत करने के लिए किया जाएगा) यहां दृश्यों के पीछे चल रहा है)।

2

CoordinateSystemRenderer के लिए कार्यान्वयन क्या है?

मैं आज ही आवश्यकता से मुलाकात की और कोशिश की, यह वास्तव में काम करता है कि इसका मतलब है, आप एक ही गतिविधि में 2 GLSurfaceView डाल सकते हैं।

कुछ ध्यान दिया जाने,

  1. GLRender में, जब onSurfaceChanged शुरू हो जाती है, तो आप अपने व्यूपोर्ट
  2. आकार बदलने चाहिए 2 GLSurfaceView के साथ, धागा प्रस्तुत करना 2 हो जाएगा, तो सिंक्रनाइज़ समस्या हुई हो जाएगा की जरूरत है। यह के कार्यान्वयन पर निर्भर करता है।

एसडीके GLSurfaceViewActivity

/* 
* Copyright (C) 2007 The Android Open Source Project 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.example.android.apis.graphics; 

import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.opengles.GL10; 

import android.opengl.GLSurfaceView; 

/** 
* Render a pair of tumbling cubes. 
*/ 

public class CubeRenderer implements GLSurfaceView.Renderer 
{ 
    boolean isReverse = false; 

    public CubeRenderer(boolean useTranslucentBackground, boolean isReverse) 
    { 
     mTranslucentBackground = useTranslucentBackground; 
     mCube = new Cube(); 
     this.isReverse = isReverse; 
    } 

    public CubeRenderer(boolean useTranslucentBackground) 
    { 
     this(useTranslucentBackground, false); 
    } 

    public void onDrawFrame(GL10 gl) 
    { 
     /* 
     * Usually, the first thing one might want to do is to clear the screen. The most efficient way of doing this is 
     * to use glClear(). 
     */ 

     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

     /* 
     * Now we're ready to draw some 3D objects 
     */ 

     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
     gl.glTranslatef(0, 0, -3.0f); 
     gl.glRotatef(mAngle, 0, 1, 0); 
     gl.glRotatef(mAngle * 0.25f, 1, 0, 0); 

     gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
     gl.glEnableClientState(GL10.GL_COLOR_ARRAY); 

     mCube.draw(gl); 

     gl.glRotatef(mAngle * 2.0f, 0, 1, 1); 
     gl.glTranslatef(0.5f, 0.5f, 0.5f); 

     mCube.draw(gl); 

     if (isReverse) 
     { 
      mAngle -= 1.2f; 
     } 
     else 
     { 
      mAngle += 1.2f; 
     } 
    } 

    public void onSurfaceChanged(GL10 gl, int width, int height) 
    { 
     System.out.println("Joey's Log width : " + width + " height : " + height); 
     gl.glViewport(0, 0, width, height); 

     /* 
     * Set our projection matrix. This doesn't have to be done each time we draw, but usually a new projection needs 
     * to be set when the viewport is resized. 
     */ 

     float ratio = (float) width/height; 
     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); 
    } 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) 
    { 
     /* 
     * By default, OpenGL enables features that improve quality but reduce performance. One might want to tweak that 
     * especially on software renderer. 
     */ 
     gl.glDisable(GL10.GL_DITHER); 

     /* 
     * Some one-time OpenGL initialization can be made here probably based on features of this particular context 
     */ 
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 

     if (mTranslucentBackground) 
     { 
      gl.glClearColor(0, 0, 0, 0); 
     } 
     else 
     { 
      gl.glClearColor(1, 1, 1, 1); 
     } 
     gl.glEnable(GL10.GL_CULL_FACE); 
     gl.glShadeModel(GL10.GL_SMOOTH); 
     gl.glEnable(GL10.GL_DEPTH_TEST); 
    } 

    private boolean mTranslucentBackground; 

    private Cube mCube; 

    private float mAngle; 
} 


------------------------------------------------------------------------------------------ 
/* 
* Copyright (C) 2007 The Android Open Source Project 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.example.android.apis.graphics; 

import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.opengles.GL10; 

import android.opengl.GLSurfaceView; 

/** 
* Render a pair of tumbling cubes. 
*/ 

public class CubeRenderer implements GLSurfaceView.Renderer { 
    boolean isReverse = false; 
    public CubeRenderer(boolean useTranslucentBackground,boolean isReverse) { 
     mTranslucentBackground = useTranslucentBackground; 
     mCube = new Cube(); 
     this.isReverse = isReverse; 
    } 

    public CubeRenderer(boolean useTranslucentBackground) 
    { 
     this(useTranslucentBackground, false); 
    } 

    public void onDrawFrame(GL10 gl) { 
     /* 
     * Usually, the first thing one might want to do is to clear 
     * the screen. The most efficient way of doing this is to use 
     * glClear(). 
     */ 

     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

     /* 
     * Now we're ready to draw some 3D objects 
     */ 

     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
     gl.glTranslatef(0, 0, -3.0f); 
     gl.glRotatef(mAngle,  0, 1, 0); 
     gl.glRotatef(mAngle*0.25f, 1, 0, 0); 

     gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
     gl.glEnableClientState(GL10.GL_COLOR_ARRAY); 

     mCube.draw(gl); 

     gl.glRotatef(mAngle*2.0f, 0, 1, 1); 
     gl.glTranslatef(0.5f, 0.5f, 0.5f); 

     mCube.draw(gl); 

     if (isReverse) 
     { 
      mAngle -= 1.2f; 
     } 
     else 
     { 
      mAngle += 1.2f; 
     } 
    } 

    public void onSurfaceChanged(GL10 gl, int width, int height) { 
     System.out.println("Joey's Log width : " + width + " height : " + height); 
     gl.glViewport(0, 0, width, height); 

     /* 
      * Set our projection matrix. This doesn't have to be done 
      * each time we draw, but usually a new projection needs to 
      * be set when the viewport is resized. 
      */ 

     float ratio = (float) width/height; 
     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); 
    } 

    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     /* 
     * By default, OpenGL enables features that improve quality 
     * but reduce performance. One might want to tweak that 
     * especially on software renderer. 
     */ 
     gl.glDisable(GL10.GL_DITHER); 

     /* 
     * Some one-time OpenGL initialization can be made here 
     * probably based on features of this particular context 
     */ 
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, 
       GL10.GL_FASTEST); 

     if (mTranslucentBackground) { 
      gl.glClearColor(0,0,0,0); 
     } else { 
      gl.glClearColor(1,1,1,1); 
     } 
     gl.glEnable(GL10.GL_CULL_FACE); 
     gl.glShadeModel(GL10.GL_SMOOTH); 
     gl.glEnable(GL10.GL_DEPTH_TEST); 
    } 
    private boolean mTranslucentBackground; 
    private Cube mCube; 
    private float mAngle; 
} 
+0

यह कोड कैसे प्रासंगिक है? यह दो GLSurfaceViews का प्रदर्शन नहीं करता है। यह सिर्फ एक दृश्य दिखाता है, दो cubes ड्राइंग। – ToolmakerSteve

-1

में एंड्रॉयड API डेमो उपयोग करने के लिए आप कर सकते हैं एक त्वरित परीक्षण है कई GLSurfaceViews सक्रिय और एक गतिविधि में दिखाई दे। प्रत्येक दृश्य को अपना स्वयं का जीएल संदर्भ मिलता है।

+0

OP ने दो GLSurfaceViews का उपयोग करने के लिए प्रयास किया है, और इसे काम करने में समस्या हो रही है। यह "उत्तर" कैसे मदद करता है? – ToolmakerSteve

0

यहाँ यह ऐसा करने का एक वैकल्पिक तरीका है। यहां एंड्रॉइड दस्तावेज़ों से नमूना डाउनलोड करें: http://developer.android.com/shareables/training/OpenGLES.zip इस ज़िप फ़ाइल में आप 2 परियोजनाएं देखेंगे। प्रोजेक्ट खोलें: HelloOpenGLES20 और नीचे सूचीबद्ध मेरे साथ 'MyGLRenderer' क्लास को प्रतिस्थापित करें और प्रोजेक्ट चलाएं।

package com.example.android.opengl; 

import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.opengles.GL10; 

import android.opengl.GLES20; 
import android.opengl.GLSurfaceView; 
import android.opengl.Matrix; 
import android.util.Log; 

public class MyGLRenderer implements GLSurfaceView.Renderer { 

    private static final String TAG = "MyGLRenderer"; 
    private Triangle[] mTriangle = new Triangle[2]; 
    private final float[] mMVPMatrix = new float[16]; 
    private final float[] mProjectionMatrix = new float[16]; 
    private final float[] mViewMatrix = new float[16]; 
    private final float[] mRotationMatrix = new float[16]; 

    private float mAngle; 

    @Override 
    public void onSurfaceCreated(GL10 unused, EGLConfig config) { 

     GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
     mTriangle[0] = new Triangle(); 
     mTriangle[1] = new Triangle(); 

    } 

    @Override 
    public void onDrawFrame(GL10 unused) { 

     final float[] scratch = new float[16]; 

     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); 

     Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); 

     Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0); 

     for(int i = 0; i < 2; i++) { 

      if(i % 2 == 0) { 

       Matrix.setRotateM(mRotationMatrix, 0, mAngle/2f, 0, 0, 1.0f); 

      } 
      else { 

       Matrix.setRotateM(mRotationMatrix, 0, mAngle/4f, 0, 0, 1.0f); 

      } 

      Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0); 

      mTriangle[i].draw(scratch); 

     }//End for(int i = 0; i < 2; i++) 

    }//End public void onDrawFrame(GL10 unused) 

    @Override 
    public void onSurfaceChanged(GL10 unused, int width, int height) { 

     GLES20.glViewport(0, 0, width, height); 
     float ratio = (float) width/height; 
     Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7); 

    } 

    public static int loadShader(int type, String shaderCode){ 

     int shader = GLES20.glCreateShader(type); 
     GLES20.glShaderSource(shader, shaderCode); 
     GLES20.glCompileShader(shader); 

     return shader; 

    } 

    public static void checkGlError(String glOperation) { 

     int error; 

     while((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { 

      Log.e(TAG, glOperation + ": glError " + error); 
      throw new RuntimeException(glOperation + ": glError " + error); 

     } 

    } 

    public float getAngle() { 
     return mAngle; 
    } 


    public void setAngle(float angle) { 
     mAngle = angle; 
    } 

} 

मैं क्या समझ से, OpenGLES संभवतः कई प्रस्तुत लक्ष्य के साथ है, लेकिन केवल एक राय यह उपयोग करने के लिए बनाया गया है। हालांकि मुझे व्यवस्थापक होना चाहिए, मुझे यकीन नहीं है कि आप जो करने की कोशिश कर रहे हैं वह गलत है या नहीं। मैं खुद को OpenGLES के लिए एक नया हूँ। मेरे पास बिटबकेट में ओपनजीएल ओपन सोर्स लाइब्रेरी है। आप इससे कुछ विचार प्राप्त कर सकते हैं: https://bitbucket.org/warwick/hacergestov2, यह एक इशारा पुस्तकालय है।

+0

कृपया समझाएं - यह "इसे करने का एक वैकल्पिक तरीका" कैसा है? ओपी द्वारा चर्चा की गई "यह" एक लेआउट के भीतर जीएल को दो अलग-अलग विचारों में प्रस्तुत कर रही है। आप वैकल्पिक समाधान के रूप में क्या प्रस्तावित कर रहे हैं? – ToolmakerSteve

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

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