Bonjour
Je suis en train de développer une application qui affiche la caméra de mon téléphone et affiche par dessus des formes ous OpenGL sous Android.
Voici mon programme:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
ublic class MainActivity extends AppCompatActivity{
 
 
 
 GLSurfaceView glView;
    CameraView cameraView;
    GLClearRenderer clearRenderer;
    @Override
    public void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
 
        // When working with the camera, it's useful to stick to one orientation.
        setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
 
        // Next, we disable the application's title bar...
        requestWindowFeature( Window.FEATURE_NO_TITLE );
        // ...and the notification bar. That way, we can use the full screen.
        getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN );
 
        // Now let's create an OpenGL surface.
        glView = new GLSurfaceView( this );
        // To see the camera preview, the OpenGL surface has to be created translucently.
        // See link above.
        glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 );
        glView.getHolder().setFormat( PixelFormat.TRANSLUCENT );
        // The renderer will be implemented in a separate class, GLView, which I'll show next.
        clearRenderer = new GLClearRenderer();
        glView.setRenderer( clearRenderer );
        // Now set this as the main view.
        setContentView( glView );
 
        // Now also create a view which contains the camera preview...
        cameraView = new CameraView( this );
        // ...and add it, wrapping the full screen size.
        addContentView( cameraView, new ActionBar.LayoutParams( ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT ) );
    }
 
    public class GLClearRenderer implements GLSurfaceView.Renderer {
 
        private BackgroundTexture mBackgroundTexture;
        private SquareTexture mSquareTexture;
        private Square mSquare;
 
        // mMVPMatrix is an abbreviation for "Model View Projection Matrix"
        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 final float[] mRotationMatrixlX = new float[16];
        private final float[] mRotationMatrixlY = new float[16];
        private final float[] mRotationMatrixX = new float[16];
        private final float[] mRotationMatrixY = new float[16];
        private final float[] mRotationMatrixZ = new float[16];
        private final float[] mRotationMatrix0 = new float[16];
 
        float angleX ,angleY ,angleZ ;
        private float mAngleX;
        private float mAngleY;
 
        public void onDrawFrame( GL10 gl ) {
            // This method is called per frame, as the name suggests.
            // For demonstration purposes, I simply clear the screen with a random translucent gray.
            float c = 1.0f / 256 * ( System.currentTimeMillis() % 256 );
            GLES20.glClearColor( c, c, c, 0.5f );
            GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
 
            // Draw background color
            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
 
 
            // Set the camera position (View matrix)
            Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -10, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
 
            // Calculate the projection and view transformation
            Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
 
            // Draw square
            mSquare.draw(mMVPMatrix);
        }
 
 
        public void onSurfaceChanged( GL10 gl, int width, int height ) {
            // This is called whenever the dimensions of the surface have changed.
            // We need to adapt this change for the GL viewport.
            GLES20.glViewport( 0, 0, width, height );
 
            float ratio = (float) width / height;
 
            // this projection matrix is applied to object coordinates
            // in the onDrawFrame() method
            Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 50);
        }
 
        public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
            // No need to do anything here.
 
            angleX = 0;
            angleY = 0;
            angleZ = 0;
 
            // Set the background frame color
            //GLES20.glClearColor(1.0f, 0.1f, 0.0f, 1.0f);
 
            mSquare = new Square(); %%%%%%% NOT DISPLAY
 
        }
    }
 
    public class CameraView extends SurfaceView implements SurfaceHolder.Callback {
        private Camera camera;
 
        public CameraView( Context context ) {
            super( context );
            // We're implementing the Callback interface and want to get notified
            // about certain surface events.
            getHolder().addCallback( this );
            // We're changing the surface to a PUSH surface, meaning we're receiving
            // all buffer data from another component - the camera, in this case.
            getHolder().setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
        }
 
        public void surfaceCreated( SurfaceHolder holder ) {
            // Once the surface is created, simply open a handle to the camera hardware.
            camera = Camera.open();
        }
 
        public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) {
            // This method is called when the surface changes, e.g. when it's size is set.
            // We use the opportunity to initialize the camera preview display dimensions.
            Camera.Parameters p = camera.getParameters();
            p.setPreviewSize( width, height );
            //camera.setParameters( p );
 
            // We also assign the preview display to this surface...
            try {
                camera.setPreviewDisplay( holder );
            } catch( IOException e ) {
                e.printStackTrace();
            }
            // ...and start previewing. From now on, the camera keeps pushing preview
            // images to the surface.
            camera.startPreview();
        }
 
        public void surfaceDestroyed( SurfaceHolder holder ) {
            // Once the surface gets destroyed, we stop the preview mode and release
            // the whole camera since we no longer need it.
            camera.stopPreview();
            camera.release();
            camera = null;
        }
    }
 
 
}
C'est un code que j'ai trouvé sur internet. Le problème est que le scintillement de l'image effectué dans le rendering, je le vois bien mais le carré que je veux afficher (mSquare) ne s'affiche pas. Voici le programme de mon carré:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
public class Square {
 
    private final String vertexShaderCode =
            // This matrix member variable provides a hook to manipulate
            // the coordinates of the objects that use this vertex shader
            "uniform mat4 uMVPMatrix;" +
            "attribute vec4 vPosition;" +
            "void main() {" +
            // The matrix must be included as a modifier of gl_Position.
            // Note that the uMVPMatrix factor *must be first* in order
            // for the matrix multiplication product to be correct.
            "  gl_Position =  vPosition;" +
            "}";
 
    private final String fragmentShaderCode =
            "precision mediump float;" +
            "uniform vec4 vColor;" +
            "void main() {" +
            "  gl_FragColor = vec4(1,1,1,0.5);" +
            "}";
 
    private final FloatBuffer vertexBuffer;
    private final ShortBuffer drawListBuffer;
    private final int mProgram;
    private int mPositionHandle;
    private int mColorHandle;
    private int mMVPMatrixHandle;
 
    // number of coordinates per vertex in this array
    static final int COORDS_PER_VERTEX = 3;
//    static float squareCoords[] = {
//            -0.5f,  0.5f, -1.0f,   // top left
//            -0.5f, -0.5f, -1.0f,   // bottom left
//            0.5f, -0.5f, -1.0f,   // bottom right
//            0.5f,  0.5f, -1.0f }; // top right
static float squareCoords[] = {
        -0.5f,  0.5f, 1.0f,   // top left
        -0.5f, -0.5f, 1.0f,   // bottom left
        0.5f, -0.5f, 1.0f,   // bottom right
        0.5f,  0.5f, 1.0f }; // top right
    private final short drawOrder[] = { 0, 1, 2, 0, 2, 3 }; // order to draw vertices
 
    private final int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex
 
    float color[] = { 0.2f, 0.709803922f, 0.898039216f, 1.0f };
 
    /**
     * Sets up the drawing object data for use in an OpenGL ES context.
     */
    public Square() {
        // initialize vertex byte buffer for shape coordinates
        ByteBuffer bb = ByteBuffer.allocateDirect(
        // (# of coordinate values * 4 bytes per float)
                squareCoords.length * 4);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(squareCoords);
        vertexBuffer.position(0);
 
        // initialize byte buffer for the draw list
        ByteBuffer dlb = ByteBuffer.allocateDirect(
                // (# of coordinate values * 2 bytes per short)
                drawOrder.length * 2);
        dlb.order(ByteOrder.nativeOrder());
        drawListBuffer = dlb.asShortBuffer();
        drawListBuffer.put(drawOrder);
        drawListBuffer.position(0);
 
        // prepare shaders and OpenGL program
        int vertexShader = AGLRenderer.loadShader(
                GLES20.GL_VERTEX_SHADER,
                vertexShaderCode);
        int fragmentShader = AGLRenderer.loadShader(
                GLES20.GL_FRAGMENT_SHADER,
                fragmentShaderCode);
 
        mProgram = GLES20.glCreateProgram();             // create empty OpenGL Program
        GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
        GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
        GLES20.glLinkProgram(mProgram);                  // create OpenGL program executables
    }
 
    /**
     * Encapsulates the OpenGL ES instructions for drawing this shape.
     *
     * @param mvpMatrix - The Model View Project matrix in which to draw
     * this shape.
     */
    public void draw(float[] mvpMatrix) {
        // Add program to OpenGL environment
        GLES20.glUseProgram(mProgram);
 
        GLES20.glEnable( GLES20.GL_DEPTH_TEST );
        GLES20.glDepthFunc( GLES20.GL_LEQUAL );
        GLES20.glDepthMask( true );
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        GLES20.glEnable(GLES20.GL_BLEND);
 
        // get handle to vertex shader's vPosition member
        mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
 
        // Enable a handle to the triangle vertices
        GLES20.glEnableVertexAttribArray(mPositionHandle);
 
        // Prepare the triangle coordinate data
        GLES20.glVertexAttribPointer(
                mPositionHandle, COORDS_PER_VERTEX,
                GLES20.GL_FLOAT, false,
                vertexStride, vertexBuffer);
 
        // get handle to fragment shader's vColor member
        mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
 
        // Set color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
 
        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
        AGLRenderer.checkGlError("glGetUniformLocation");
 
        // Apply the projection and view transformation
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
        AGLRenderer.checkGlError("glUniformMatrix4fv");
 
        // Draw the square
        GLES20.glDrawElements(
                GLES20.GL_TRIANGLES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
 
        // Disable vertex array
        GLES20.glDisableVertexAttribArray(mPositionHandle);
        GLES20.glDisable(GLES20.GL_BLEND);
    }
 
}
Je ne comprend pas trop d'ou ca peut venir.