IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement 2D, 3D et Jeux Discussion :

Erreur: glerror 1282


Sujet :

Développement 2D, 3D et Jeux

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    560
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 560
    Points : 71
    Points
    71
    Par défaut Erreur: glerror 1282
    Bonjour,

    Je suis bloqué sur mon programme ou je fais afficher une texture sur un carré. Voici ma class:

    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
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
     
    /*
     * Copyright (C) 2011 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.cyclopus.nativecpp;
     
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.opengl.GLES20;
    import android.opengl.GLUtils;
     
    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;
    import java.nio.FloatBuffer;
    import java.nio.ShortBuffer;
     
    /**
     * A two-dimensional square for use as a drawn object in OpenGL ES 2.0.
     */
    public class TexturedSquare {
     
        private static int[] textureHandle;
     
        private final String vertexShaderCode =
        "uniform mat4 uMVPMatrix;\n" +
                "attribute vec2 aPosition;\n" +
                "attribute vec2 aTexPos;\n" +
                "varying vec2 vTexPos;\n" +
                "void main() {\n" +
                "  vTexPos = aTexPos;\n" +
                "  gl_Position = uMVPMatrix * vec4(aPosition.xy, 0.0, 1.0);\n" +
                "}";
     
        private final String fragmentShaderCode =
                "precision mediump float;\n"+
                        "uniform sampler2D uTexture;\n" +
                        "varying vec2 vTexPos;\n" +
                        "void main(void)\n" +
                        "{\n" +
                        "  gl_FragColor = texture2D(uTexture, vTexPos);\n" +
                        "}";
     
        private final FloatBuffer vertexBuffer;
        private final ShortBuffer drawListBuffer;
        private final int mProgram;
        private int mPositionHandle;
        private int mTexturePosHandle;
        private int mColorHandle;
        private int mMVPMatrixHandle;
     
     
        // number of coordinates per vertex in this array
        final int COORDS_PER_VERTEX = 4;
        float squareCoords[] = {
                -1.0f,-1.0f,        0.0f, 0.0f, // vertex 3
                -1.0f, 1.0f,        0.0f, 1.0f, // vertex 1
                1.0f,-1.0f,        1.0f, 0.0f, // vertex 2
                1.0f, 1.0f,        1.0f, 1.0f, // vertex 0
        }; // 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 TexturedSquare() {
            MyGLRenderer.checkGlError("glGetUniformLocation");
            // 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);
     
            MyGLRenderer.checkGlError("glGetUniformLocation");
            // prepare shaders and OpenGL program
            int vertexShader = MyGLRenderer.loadShader(
                    GLES20.GL_VERTEX_SHADER,
                    vertexShaderCode);
            int fragmentShader = MyGLRenderer.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
            String LogInfo = GLES20.glGetProgramInfoLog(mProgram);
     
          /*  //Link the program.
            int isLinked = 0;
            int []i = GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS);
            if(isLinked == GL_FALSE)
            {
     
                //The maxLength includes the NULL character
     
                String LogInfo GLES20.glGetProgramInfoLog(mProgram);
     
                //The program is useless now. So delete it.
                GLES20.glDeleteProgram(program);
     
                //Provide the infolog in whatever manner you deem best.
                //Exit with failure.
                return;
            }*/
     
            MyGLRenderer.checkGlError("glGetUniformLocation");
     
        }
     
     
        public  int loadTexture()
        {
            int uTexture = GLES20.glGetUniformLocation(mProgram, "uTexture");
     
            textureHandle = new int[1];
     
            GLES20.glGenTextures(1, textureHandle, 0);
     
            MyGLRenderer.checkGlError("glGetUniformLocation");
     
                final BitmapFactory.Options options = new BitmapFactory.Options();
                options.inScaled = false;   // No pre-scaling
     
                // Read in the resource
                Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
                Bitmap bitmap = Bitmap.createBitmap(640, 480, conf); // this creates a MUTABLE bitmap
     
                // Bind to the texture in OpenGL
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
     
                // Set filtering
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
     
                // Load the bitmap into the bound texture.
                GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
     
     
     
                GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
     
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
     
            GLES20.glUniform1i(uTexture, 0);
            MyGLRenderer.checkGlError("glGetUniformLocation");
    //
    //
    //            // Recycle the bitmap, since its data has been loaded into OpenGL.
                bitmap.recycle();
     
     
            return textureHandle[0];
        }
     
     
        /**
         * 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);
     
            // get handle to vertex shader's vPosition member
            mPositionHandle     = GLES20.glGetAttribLocation(mProgram, "aPosition");
            MyGLRenderer.checkGlError("glGetUniformLocation");
            mTexturePosHandle   = GLES20.glGetAttribLocation(mProgram, "aTexPos");
            MyGLRenderer.checkGlError("glGetUniformLocation");
            // Enable a handle to the triangle vertices
     
            // Prepare the triangle coordinate data
            GLES20.glVertexAttribPointer(
                    mPositionHandle, 2,
                    GLES20.GL_FLOAT, false,
                    vertexStride, vertexBuffer);
     
            GLES20.glEnableVertexAttribArray(mPositionHandle);
            MyGLRenderer.checkGlError("glGetUniformLocation");
     
     
            GLES20.glVertexAttribPointer(
                    mTexturePosHandle, 2,
                    GLES20.GL_FLOAT, false,
                    vertexStride, (vertexBuffer.position(2)));
     
            GLES20.glEnableVertexAttribArray(mTexturePosHandle);
            MyGLRenderer.checkGlError("glGetUniformLocation");
     
            // get handle to shape's transformation matrix
            mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
            MyGLRenderer.checkGlError("glGetUniformLocation");
     
            // Apply the projection and view transformation
            GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
            MyGLRenderer.checkGlError("glUniformMatrix4fv");
     
            // Draw the square
    //        GLES20.glDrawElements(
    //                GLES20.GL_TRIANGLES, drawOrder.length,
    //                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
     
            GLES20.glDrawElements(
                    GLES20.GL_TRIANGLES, 0,
                    GLES20.GL_UNSIGNED_SHORT, 4);
     
            // Disable vertex array
            GLES20.glDisableVertexAttribArray(mPositionHandle);
        }
     
    }

    Visiblement mon code bug sur cette ligne :
    GLES20.glUniform1i(uTexture, 0);

    Je n'ai visiblement pas d'erreur de linkage la commande suivante ne me renvoie rien:
    LogInfo = GLES20.glGetProgramInfoLog(mProgram);

    Est ec que qu'un pourrait me donner un coup de pousse la dessus?

    D'avance merci.

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    L'erreur 1282 (en décimale et 502 en héxa) correspond à GL_INVALID_OPERATION (il faut regarder le fichier gl.h).
    Ensuite, un tour sur la doc (bien vérifier que l'on prend bien la doc de l'API concernée (c'est à dire, ne pas se tromper entre OpenGL ES et OpenGL)) :
    GL_INVALID_OPERATION is generated if there
    is no current program object.
    GL_INVALID_OPERATION is generated if the
    size of the uniform variable declared in the shader does not
    match the size indicated by the glUniform
    command.
    GL_INVALID_OPERATION is generated if one of
    the integer variants of this function is used to load a uniform
    variable of type float, vec2, vec3, vec4, or an array of these,
    or if one of the floating-point variants of this function is
    used to load a uniform variable of type int, ivec2, ivec3, or
    ivec4, or an array of these.
    GL_INVALID_OPERATION is generated if
    location is an invalid uniform location
    for the current program object and
    location is not equal to -1.
    Du coup, il y a quatre possibilités. Il suffit de vérifier dans laquelle vous tombez et de corriger. Je pense que vous devriez vous en sortir aisément, sinon, venez nous dire jusqu'où vous êtes aller
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur fréquente avec ASP et IIS
    Par Community Management dans le forum ASP
    Réponses: 2
    Dernier message: 11/02/2004, 22h20
  2. Check Url pour savoir si erreur 404 ou si le site existe
    Par Clément[Delphi] dans le forum Composants VCL
    Réponses: 2
    Dernier message: 07/08/2002, 13h49
  3. Réponses: 2
    Dernier message: 27/05/2002, 19h46
  4. erreur IDL:omg.org/CORBA/MARSHAL:1.0
    Par Pinggui dans le forum CORBA
    Réponses: 3
    Dernier message: 13/05/2002, 15h05
  5. [Kylix] Erreur objet
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo