日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何使用OpenGL繪制更復(fù)雜的形狀

原文鏈接:http://docs.eoeandroid.com/training/graphics/OpenGL/shapes.html

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請域名、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、陸良網(wǎng)站維護(hù)、網(wǎng)站推廣。

  在OpenGL ES視圖中定義所要繪制的圖形,是創(chuàng)建高質(zhì)量圖形的第一步。使用OpenGL ES繪制圖形時(shí),如果不了解怎樣基于OpenGL ES定義圖形對象,將會(huì)是一件棘手的事。 這節(jié)課將介紹以Android設(shè)備屏幕為基準(zhǔn)的OpenGL ES坐標(biāo)系統(tǒng),定義圖形的基本方法,圖形輪廓,以及定義三角形、方形。

定義三角形 Define a Triangle


  OpenGL ES允許可以在三維坐標(biāo)上定義你要繪制的對象。所以,在繪制三角形前,你要定義好它的坐標(biāo)。在OpenGL中,定義坐標(biāo)最典型的方法,就是定義坐標(biāo)定點(diǎn)的一組浮點(diǎn)型數(shù)據(jù)。為了提高效率,你可以把這些坐標(biāo)值寫進(jìn)一組ByteBuffer,它將會(huì)傳遞給OpenGL ES圖形管道進(jìn)行處理。

 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
class Triangle {

    private FloatBuffer vertexBuffer;

    // number of coordinates per vertex in this array
    static final int COORDS_PER_VERTEX = 3;
    static float triangleCoords[] = { // in counterclockwise order:
         0.0f,  0.622008459f, 0.0f,   // top
        -0.5f, -0.311004243f, 0.0f,   // bottom left
         0.5f, -0.311004243f, 0.0f    // bottom right
    };

    // Set color with red, green, blue and alpha (opacity) values
    float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };

    public Triangle() {
        // initialize vertex byte buffer for shape coordinates
        ByteBuffer bb = ByteBuffer.allocateDirect(
                // (number of coordinate values *  4 bytes per float)
                triangleCoords.length *  4);
        // use the device hardware's native byte order
        bb.order(ByteOrder.nativeOrder());

        // create a floating point buffer from the ByteBuffer
        vertexBuffer = bb.asFloatBuffer();
        // add the coordinates to the FloatBuffer
        vertexBuffer.put(triangleCoords);
        // set the buffer to read the first coordinate
        vertexBuffer.position(0);
    }
    }

  OpenGL ES定義了以下的默認(rèn)坐標(biāo)系統(tǒng):[0,0,0] (X,Y,Z)作為GLSurfaceView圖像的中點(diǎn),[1,1,0]是圖像的右上角頂點(diǎn),[-1,-1,0]是左下角頂點(diǎn)。如果需要該坐標(biāo)系統(tǒng)的圖片,請移步OpenGL ES開發(fā)指南。 請注意,圖形的坐標(biāo)是按逆時(shí)針方向定義的,繪制的順序是非常重要的,因?yàn)樗x圖形的正面以及反面,正面可以被直接繪制,而反面你可能選擇以O(shè)penGL ES消除面方法使其不被繪制出來。想要獲取更多關(guān)于面與消除的信息,請查看OpenGL ES開發(fā)指南。

定義方形 Define a Square

  在OpenGL中,定義三角形是非常簡單的,但你是否想要來點(diǎn)高難度的?比如,方形?要定義方形,有很多種方法,其中典型的方法就是把兩個(gè)三角形畫在一起:

圖1.使用兩個(gè)三角形繪制方形

  同樣,你需要按照逆時(shí)針方向定義代表方形的兩個(gè)三角形的坐標(biāo)頂點(diǎn),并把值寫到ByteBuffer。為了避免每個(gè)三角形都定義坐標(biāo)產(chǎn)生兩種坐標(biāo)系統(tǒng),使用繪制列表告訴OpenGL ES圖像管道如何繪制這些頂點(diǎn),下面是該種形狀繪制方法的代碼:

 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
class Square {

    private FloatBuffer vertexBuffer;
    private ShortBuffer drawListBuffer;

    // number of coordinates per vertex in this array
    static final int COORDS_PER_VERTEX = 3;
    static float squareCoords[] = { -0.5f,  0.5f, 0.0f,   // top left
                                    -0.5f, -0.5f, 0.0f,   // bottom left
                                     0.5f, -0.5f, 0.0f,   // bottom right
                                     0.5f,  0.5f, 0.0f }; // top right

    private short drawOrder[] = { 0, 1, 2, 0, 2, 3 }; // order to draw vertices

    public Square() {
        // 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);
    }
    }

  這個(gè)例子給你展示如何使用OpenGL繪制更復(fù)雜的形狀。一般來說,都是使用好幾個(gè)三角形來繪制圖形對象。在下節(jié)課,你將學(xué)習(xí)如何把這些圖像畫在屏幕上。


文章標(biāo)題:如何使用OpenGL繪制更復(fù)雜的形狀
文章轉(zhuǎn)載:http://m.5511xx.com/article/dpdjcsc.html