2010-07-27 79 views
2

以下是給我三角形不是正方形,任何人都知道爲什麼?渲染一個正方形

//Defining as... 
     addcube(2,-2, 1, -1, 10); 
     addcube(float lx, float hx, float ly, float hy, floathz){ 
      final float array1[] = new float[] { 
      //Front face 
      lx, ly, hz, 
      lx, hy, hz, 
      hx, hy, hz, 
      hx, ly, hz 
    }; 
} 

    //Drawing as... 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 

我試圖加入gl.glDisable(GL10.GL_CULL_FACE);但這只是把剩下的正方形放在前臺。我已經包括了繪畫方法...

public void onDrawFrame(GL10 gl) { 
    onDrawFrameCounter++; 
    gl.glEnable(GL10.GL_TEXTURE_2D); 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 

    bindCameraTexture(gl); 
    System.out.println(Global.bearing); 
    float bear = Global.bearing; 
    gl.glLoadIdentity(); 
    gl.glNormal3f(0,0,1); 
    System.out.println("ARRAY!: " + GLCamTest.array.length); 
    p = 0; 
    gl.glRotatef(bear, 1, 0, 0); 

    int e = 0; 
    for(int q=0; q < Global.cubes;q++){ 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, e, 4); 
    e = e+4; 
    } 
} 

public void onSurfaceChanged(GL10 gl, int width, int height) { 
    gl.glViewport(0, 0, width, height); 

    float ratio = (float) width/height; 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 20); 

    gl.glMatrixMode(GL10.GL_MODELVIEW); 
} 

public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 
    gl.glClearColor(0, 0, 0, 0); 
    gl.glDisable(GL10.GL_CULL_FACE); 
    gl.glShadeModel(GL10.GL_SMOOTH); 
    gl.glEnable(GL10.GL_DEPTH_TEST); 
    cubeBuff = makeFloatBuffer(GLCamTest.array); 
    texBuff = makeFloatBuffer(camTexCoords);     
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff); 
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff); 
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 
} 

回答

2

在「Z字形順序」使用點嘗試 即

xl,yl 
xl,yh 
xh,yl // this is hypotenuse of first triangle 
xh,yh // this is endpoint of last triangle, so previous line is hypotenuse 

你可能得到某種兩破三角形形狀。

你看,這個正方形是由三角形組成的,它們是按照點的順序繪製的!

0

沒有測試過,但我想你應該傳遞,而不是GL_TRIANGLE_STRIP GL_QUAD_STRIP:

gl.glDrawArrays(GL10.GL_QUAD_STRIP, e, 4); 
+1

沒有這樣的東西'在它出現的OpenGL-ES GL_QUAD_STRIP'。 – Skizit 2010-07-27 13:03:30

+0

試試GL_QUADS。如果這不起作用GL_POLYGON應該是因爲你告訴它計算4個頂點。此刻你告訴它嘗試繪製三角形。 – AaronM 2010-07-27 13:10:40

+0

既不是那些工作。沒有表現 – Skizit 2010-07-27 13:14:56

0

嘗試到位e = e + 4e = e + 3您drawarrays之間的通話