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

Android Discussion :

charger une texture avec opengl ES


Sujet :

Android

  1. #1
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    521
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2014
    Messages : 521
    Par défaut charger une texture avec opengl ES
    Bonjour,

    J'aimerais pouvoir charger des textures après la création de la surface mais cela ne fonctionne pas.

    Voilà comment je charge mes textures :

    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
     
        public static int loadTexture(final Context context, final int resourceId)
        {
            final int[] textureHandle = new int[1];
     
            GLES20.glGenTextures(1, textureHandle, 0);
     
            if (textureHandle[0] != 0)
            {
                final BitmapFactory.Options options = new BitmapFactory.Options();
                options.inScaled = false;   // No pre-scaling
     
                // Read in the resource
                final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
     
                // 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);
     
                // Recycle the bitmap, since its data has been loaded into OpenGL.
                bitmap.recycle();
            }
     
            if (textureHandle[0] == 0)
            {
                throw new RuntimeException("Error loading texture.");
            }
     
            return textureHandle[0];
        }
    cela ne plante pas, simplement la texture donnée est une autre texture ( la dernière chargée lors de la création de la surface ).

    Savez vous s'il est possible et si oui comment charger des textures ainsi ?
    Ou même s'il est possible de les modifier ?

    Merci

  2. #2
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    521
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2014
    Messages : 521
    Par défaut
    Une chose étonnante, est que, lorsque ma surface change d'orientation par exemple, avec surfaceChanged(...), la création d'une nouvelle texture fonctionne, mais dans d'autres cas, non.

    ex:

    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
     
     
        @Override
        public void onSurfaceChanged(GL10 glUnused, int width_, int height_) {
     
            width = width_;
            height = height_;
            float screenRatio = (width / height);
            float left = -screenRatio;
            float right = screenRatio;
            float bottom = -1.0f;
            float top = 1.0f;
            float near = 1.0f;
            float far = 10.0f;
     
            if ( width_ > height_ ){
                left*=(height/width) ;
                right*=(height/width) ;
                top*=(height/width) ;
                bottom*=(height/width) ;
                screenRatioW = width/height ;
                screenRatioH = 1 ;
                zmax = 3f ;
                zmin = 0.2f ;
            }else{
                screenRatioW = 1 ;
                screenRatioH = height/width ;
                zmax = 4f ;
                zmin = 0.2f ;
            }
     
            GLES20.glViewport(0, 0, width_, height_);
            Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
     
            mn = Bitmap.createBitmap(Bitmap.createBitmap((int) width / 3, (int) width / 3, Bitmap.Config.ARGB_8888));
            for ( int x = 0 ; x < mn.getWidth() ; x ++ ){
                for ( int y = 0 ; y < mn.getHeight() ; y ++ ){
                    mn.setPixel(x,y, Color.WHITE);
                }
            }
     
            hud.clear();
            minimap = RawResourceReader.loadTexture(mn, false) ;
            if ( width > height ){
                hud.add(new Sprite(minimap,1f,1f,0f,0f,1,1,1,1,-mProjectionMatrix[10]*(width/height)-0.5f ,mProjectionMatrix[10]*screenRatioH +0.5f, true));
                hud.add(new Icon(textures[4],0.7f,0.7f,0f,0f,4,4,0,0,-1f-mProjectionMatrix[10]*(width/height)-0.35f ,mProjectionMatrix[10]*screenRatioH +0.35f, true));
                hud.add(new Icon(textures[4],0.7f,0.7f,0f,0f,4,4,1,1,-mProjectionMatrix[10]*(width/height)-0.35f ,mProjectionMatrix[10]*screenRatioH+1.35f, true));
            }else{
                hud.add(new Sprite(minimap,1f,1f,0f,0f,1,1,1,1,-mProjectionMatrix[10]-0.5f ,mProjectionMatrix[10]*screenRatioH +0.5f, true));
                hud.add(new Icon(textures[4], 0.7f, 0.7f, 0f, 0f, 4, 4, 0, 0, -1f - mProjectionMatrix[10] - 0.35f, mProjectionMatrix[10] * screenRatioH + 0.35f, true));
                hud.add(new Icon(textures[4],0.7f,0.7f,0f,0f,4,4,1,1,-mProjectionMatrix[10]-0.35f ,mProjectionMatrix[10]*screenRatioH+1.35f, true));
            }
        }
    En l’occurrence, ma texture de minimap est bien créer ( en blanc ) puis affiché.
    Si je fais exactement la même chose lors d'un autre type d'évenement, par exemple onTouchEvent(), il ne me crée pas la texture, mais en utilise souvent une autre qui n'a rien avoir ou me met un fond noire.

    Avez une idée de comment éviter cela ?

    Merci si vous pouvez m'éclairer .

Discussions similaires

  1. Comment charger une image avec DevIL et l'afficher avec OpenGL
    Par LittleWhite dans le forum Développement 2D, 3D et Jeux
    Réponses: 0
    Dernier message: 01/03/2013, 08h04
  2. Impossible d'appliquer une texture avec Glut et Opengl
    Par akrogames dans le forum OpenGL
    Réponses: 5
    Dernier message: 29/10/2010, 10h20
  3. Réponses: 6
    Dernier message: 23/06/2008, 08h25

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