help GLES20

Hello everyone, I start to write render on android OPEN GL ES 2.0

Advice please! gp == false, then drawn. If gp == true, it is not drawn, where there may be a bug???




   //true - used memory GPU otherwise. false - the application memory
    private boolean gp=true;
    
    //in constructor
    private void jobCreate(){
    	
        final short[] inde={0,1,2,1,2,3};
    	
    	bufInd=ByteBuffer.allocateDirect(inde.length*2)
                .order(ByteOrder.nativeOrder()).asShortBuffer();
    	bufInd.put(inde);
    	bufInd.position(0);
    	
    	this.bytesTry=mTriangleVerticesData.length
                * FLOAT_SIZE_BYTES;
        mTriangleVertices = ByteBuffer.allocateDirect(this.bytesTry).order(ByteOrder.nativeOrder()).asFloatBuffer();
   
        mTriangleVertices.put(mTriangleVerticesData).position(0);
        
     
        //----vertex
        vertexBufferId=new int[1];
        GLES20.glGenBuffers(1,this.vertexBufferId, 0);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.vertexBufferId[0]);
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,this.bytesTry,this.mTriangleVertices,GLES20.GL_STATIC_DRAW);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
   
    	
    }
    
    //in onDrawFrame
    private void jobPaint(){
    	

        if(!gp){
        	//=============================apps
        	
        //---------v
        mTriangleVertices.position(0);
        GLES20.glVertexAttribPointer(maPositionHandle,
        		3,
        		GLES20.GL_FLOAT,
        		false,
                        20,
                        mTriangleVertices);
        
        checkGlError("vertex");
        GLES20.glEnableVertexAttribArray(maPositionHandle);
        
        
        //---------------------UV
        
        mTriangleVertices.position(3);
        GLES20.glVertexAttribPointer(maTextureHandle, 
        		2,
        		GLES20.GL_FLOAT,
        		false,
        		20,
        		mTriangleVertices);
        
        checkGlError("uv");
        GLES20.glEnableVertexAttribArray(maTextureHandle);
        
 
        
        }else{
        	//================================gpu
        	GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.vertexBufferId[0]);
        	//--------v
        	GLES20.glVertexAttribPointer(maPositionHandle, 
            		3, 
            		GLES20.GL_FLOAT, 
            		false,
            		20,
            		0);
        	
        	checkGlError("vertex");
            GLES20.glEnableVertexAttribArray(maPositionHandle);
        	
            //------------uv
            GLES20.glVertexAttribPointer(maTextureHandle, 
            		2, 
            		GLES20.GL_FLOAT, 
            		false,
            		20,
            	            12);
        	
        	checkGlError("uv");
            GLES20.glEnableVertexAttribArray(maTextureHandle);
            
        }
        
        
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
        
        
        
        if(gp){
        	GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
        }
        

        GLES20.glDisableVertexAttribArray(maPositionHandle);
        GLES20.glDisableVertexAttribArray(maTextureHandle);
     
        
    	
    	
    }













We don’t see all the code, but I notice a hint in your comment:


    //in constructor
    private void jobCreate(){

If this is really called from the constructor, that’s most likely your problem. You need to create those buffers in onSurfaceCreated(). This needs to happen in the rendering thread, after the context and surface have all been set up, and the context is current. If you do this in the constructor, it gets called in the UI thread, long before you have an OpenGL context for your calls.

[QUOTE=reto.koradi;1259146]We don’t see all the code, but I notice a hint in your comment:


    //in constructor
    private void jobCreate(){

If this is really called from the constructor, that’s most likely your problem. You need to create those buffers in onSurfaceCreated(). This needs to happen in the rendering thread, after the context and surface have all been set up, and the context is current. If you do this in the constructor, it gets called in the UI thread, long before you have an OpenGL context for your calls.[/QUOTE]

Thank you, works:D