1

それで、私はAndroidのOpenGLライブラリなどを使用するプロジェクトに取り組んでいますが、行き詰まっています。その一部は、私の OpenGL の経験不足であり、その一部は、古き良き過労の問題を計画しているだけです。問題は次のとおりです。単純な 2D 正方形にテクスチャとして重ね合わせる必要がある 2 つのビットマップがあります (連鎖三角形を使用)。

さて、両方のテクスチャを GL10.GL_TEXTURE_2D にバインドすると混乱が生じることがわかっているので (IE、機能しません)、これを処理する方法を探しています。現在、次のようにテクスチャをロードしています。

 public void loadGLTexture(GL10 gl, Context context) {
    // loading texture
    Bitmap bitmap;
    Bitmap corn;
    boolean lastBlack = false;
    try{
        FileInputStream fis = context.openFileInput(TEMP_FILE);
        BufferedInputStream buffer = new BufferedInputStream(fis);

        Bitmap immutableBitmap = BitmapFactory.decodeStream(buffer);

        if(!IsPowerOfTwo(immutableBitmap.getWidth()) | !IsPowerOfTwo(immutableBitmap.getHeight())){
            int nearestPowerWidth = pow2(immutableBitmap.getWidth());
            int nearestPowerHeight = pow2(immutableBitmap.getHeight());


            bitmap = Bitmap.createScaledBitmap(immutableBitmap,nearestPowerWidth,nearestPowerHeight,false);
        } else{
            bitmap = immutableBitmap.copy(Bitmap.Config.ARGB_8888, true);
        }

        int [] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
        Bitmap filterer = bitmap.copy(Bitmap.Config.ARGB_8888, true);

        filterer.getPixels(pixels, 0, filterer.getWidth(), 0, 0, filterer.getWidth(), filterer.getHeight());
        //int stepper = 0;

        for( int x = 0; x < pixels.length; x++ ) {
            //Log.v("MEE",String.format("%d",pixels[x]));
            if(pixels[x] == Color.WHITE){

                pixels[x] = Color.BLACK;
                lastBlack = true;
            } else{
                /*if(lastBlack){
                    pixels[x] = Color.rgb(128,153,0);
                    lastBlack = false;
                } else{
                    pixels[x] = Color.rgb(128,153,0);
                }*/
                pixels[x] = Color.TRANSPARENT;


            }
        }
        bitmap = Bitmap.createBitmap( pixels, filterer.getWidth(), filterer.getHeight(), Bitmap.Config.ARGB_8888 );
         corn = BitmapFactory.decodeResource(context.getResources(),R.drawable.corn);
    }catch(Exception e){
        Log.e("Crop Object", e.toString());
         corn = BitmapFactory.decodeResource(context.getResources(),R.drawable.corn);
         bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.corn);
    }




        // generate one texture pointer

        gl.glGenTextures(2, textures,0);

        //Create  Texture and bind it to texture 0
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, corn, 0);



}

そして、それらが描かれます:

public void draw(GL10 gl) {
    // bind the previously generated texture
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    //gl.glBindTexture(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE1);
    // Point to our buffers
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Set the face rotation
    gl.glFrontFace(GL10.GL_CW);

    // Point to our vertex buffer
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

    // Draw the vertices as triangle strip
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    //Disable the client state before leaving
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

}

誰かが私を正しい方向に向けることができますか?

4

0 に答える 0