2011-12-12 4 views
0

나는 머리카락을 내고있다. 나는이 광장에서 5 시간 동안 프리 자킨 텍스처를 얻으 려 노력해 왔습니다. 이 시점에서 나는이 코드를 작동 시켜서 작동 시키려고 노력했지만, 여기에 내가 가지고있는 것이 있습니다 ...렌더링 할 질감을 얻는 방법

터치 된 좌표에 따라 특정 속도로 회전하는 회전하는 사각형을 만듭니다. 그것들은 모두 정상적으로 작동하지만, 내 인생에서 나는 그것을 얻을 수 없다. 무엇을 바꾸어야합니까?

여기 말 그대로 그냥 롤 일을 만들려고 주위에 물건을 이동 시간을 보냈어요, 내가 물건을 충당 이상한 장소에 넣어 알고 전체 렌더러 클래스

public class VortexRenderer implements GLSurfaceView.Renderer { 
    private static final String LOG_TAG = VortexRenderer.class.getSimpleName(); 

    private float _red = 0.9f; 
    private float _green = 0.2f; 
    private float _blue = 0.2f; 
    public Bitmap bitmap; 

    public VortexRenderer(Context context) { 
     // TODO Auto-generated constructor stub 
     bitmap = BitmapFactory.decodeResource(context.getResources(), 
       R.drawable.texturetest); 

    } 


    private FloatBuffer mTextureBuffer; 
    @Override 
    public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
     gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 
     int[] textures = new int[1]; 
    // Tell OpenGL to generate textures. 
     gl.glGenTextures(1, textures, 0); 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); 
     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); 
     float textureCoordinates[] = {0.0f, 1.0f, 
       1.0f, 1.0f, 
       0.0f, 0.0f, 
       1.0f, 0.0f }; 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, 
       GL10.GL_TEXTURE_WRAP_S, 
       GL10.GL_REPEAT); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, 
       GL10.GL_TEXTURE_WRAP_T, 
       GL10.GL_REPEAT); 
     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 

     ByteBuffer byteBuf = ByteBuffer.allocateDirect(textureCoordinates.length * 4); 
     byteBuf.order(ByteOrder.nativeOrder()); 
     mTextureBuffer = byteBuf.asFloatBuffer(); 
     mTextureBuffer.put(textureCoordinates); 
     mTextureBuffer.position(0); 

      gl.glEnable(GL10.GL_TEXTURE_2D); 
     // Tell OpenGL where our texture is located. 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); 
     // Tell OpenGL to enable the use of UV coordinates. 
     gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 
     // Telling OpenGL where our UV coordinates are. 
     gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer); 

     initTriangle(); 

    } 

    @Override 
    public void onSurfaceChanged(GL10 gl, int w, int h) { 
     gl.glViewport(0, 0, w, h); 
    } 

    @Override 
    public void onDrawFrame(GL10 gl) { 
     // define the color we want to be displayed as the "clipping wall" 
     gl.glClearColor(_red, _green, _blue, 1.0f); 

     // clear the color buffer to show the ClearColor we called above... 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

     gl.glRotatef(_angle, 0f, 1f, 0f); 
     // set the color of our element 
     gl.glColor4f(0.5f, 0f, 0f, 0.5f); 

     // define the vertices we want to draw 
     gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer); 
     gl.glEnable(GL10.GL_TEXTURE_2D); 
     // Enable the texture state 
     gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 

     // Point to our buffers 
     gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer); 



     // finally draw the vertices 
     gl.glDrawElements(GL10.GL_TRIANGLE_FAN, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer); 




    } 


    private float _angle; 

    public void setAngle(float angle) { 
     _angle = angle; 
    } 


    public void setColor(float r, float g, float b) { 
     _red = r; 
     _green = g; 
     _blue = b; 
    } 

    // new object variables we need 
    // a raw buffer to hold indices 
    private ShortBuffer _indexBuffer; 

    // a raw buffer to hold the vertices 
    private FloatBuffer _vertexBuffer; 

    private short[] _indicesArray = {0, 1 ,2,3}; 
    private int _nrOfVertices = 4; 



    private void initTriangle() { 

     // float has 4 bytes 
     ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 4 * 4); 
     vbb.order(ByteOrder.nativeOrder()); 
     _vertexBuffer = vbb.asFloatBuffer(); 

     // short has 2 bytes 
     ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); 
     ibb.order(ByteOrder.nativeOrder()); 
     _indexBuffer = ibb.asShortBuffer(); 

     float[] coords = { 
      -0.5f, -0.5f, 0f, // (x1, y1, z1) 
      0.5f, -0.5f, 0f, // (x2, y2, z2) 
      0.5f, 0.5f, 0f, // (x3, y3, z3) 
      -0.5f, 0.5f, 0f 
     }; 

     _vertexBuffer.put(coords); 
     _indexBuffer.put(_indicesArray); 

     _vertexBuffer.position(0); 
     _indexBuffer.position(0); 
    } 
} 

입니다.

OpenGL ES는이 학습 곡선의 가치가 있어야합니다.

답변

0

보십시오 당신이 당신의 텍스처 매개 변수를 설정 한 후

gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); 

를 호출.
또한 일반적으로 텍스처 크기가 OpenGL에서 작업 할 때 2의 배수 (예 : 32x32, 64x64, 128x128 ...)인지 확인하는 것이 좋습니다.

관련 문제