• 鍍金池/ 教程/ Android/ 材質(zhì)及光照示例
    繪制線(xiàn)段 Line Segment
    投影變換 Projection
    繪制迷你太陽(yáng)系
    繪制一個(gè)球體
    繪制三角形 Triangle
    OpenGL 光照模型
    三維坐標系及坐標變換初步
    定義 3D 模型的前面和后面
    繪制一個(gè) 20 面體
    顏色 Color
    Depth Buffer
    材質(zhì)及光照示例
    基本幾何圖形定義
    關(guān)于EGL
    導言
    Viewing 和 Modeling(MODELVIEW) 變換
    FrameBuffer
    設置光照效果 Set Lighting
    Viewport 變換
    階段小結
    繪制點(diǎn) Point
    OpenGL ES API 命名習慣
    通用的矩陣變換指令
    關(guān)于 OpenGL ES
    創(chuàng )建實(shí)例應用 OpenGLDemos 程序框架
    OpenGL ES 管道(Pipeline)
    GLSurfaceView

    材質(zhì)及光照示例

    設置物體表面材料(Material)的反光屬性(顏色和材質(zhì))的方法如下:

    public void glMaterialf(int face,int pname,float param)
    public void glMaterialfv(int face,int pname,float[] params,int offset)
    public void glMaterialfv(int face,int pname,FloatBuffer params)
    • face : 在OpenGL ES中只能使用GL_FRONT_AND_BACK,表示修改物體的前面和后面的材質(zhì)光線(xiàn)屬性。
    • pname: 參數類(lèi)型,可以有GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_SHININESS。這些參數用在光照方程。
    • param:參數的值。

    其中 GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR ,GL_EMISSION 為顏色 RGBA 值,GL_SHININESS 值可以從0到128,值越大,光的散射越?。?

    http://wiki.jikexueyuan.com/project/opengl-es-guide/images/103.png" alt="" />

    此外,方法 glLightModleXX 給出了光照模型的參數

    public void glLightModelf(int pname,float param)
    public void glLightModelfv(int pname,float[] params,int offset)
    public void glLightModelfv(int pname,FloatBuffer params)
    • pname:參數類(lèi)型,可以為GL_LIGHT_MODEL_AMBIENT和GL_LIGHT_MODEL_TWO_SIDE
    • params:參數的值。

    最終頂點(diǎn)的顏色由這些參數(光源,材質(zhì)光學(xué)屬性,光照模型)綜合決定(光照方程計算出)。

    下面例子在場(chǎng)景中設置一個(gè)白色光源:

    public void initScene(GL10 gl){
     float[] amb = { 1.0f, 1.0f, 1.0f, 1.0f, };
     float[] diff = { 1.0f, 1.0f, 1.0f, 1.0f, };
     float[] spec = { 1.0f, 1.0f, 1.0f, 1.0f, };
     float[] pos = { 0.0f, 5.0f, 5.0f, 1.0f, };
     float[] spot_dir = { 0.0f, -1.0f, 0.0f, };
     gl.glEnable(GL10.GL\_DEPTH\_TEST);
     gl.glEnable(GL10.GL\_CULL\_FACE);
     gl.glEnable(GL10.GL\_LIGHTING);
     gl.glEnable(GL10.GL\_LIGHT0);
     ByteBuffer abb
     = ByteBuffer.allocateDirect(amb.length\*4);
     abb.order(ByteOrder.nativeOrder());
     FloatBuffer ambBuf = abb.asFloatBuffer();
     ambBuf.put(amb);
     ambBuf.position(0);
     ByteBuffer dbb
     = ByteBuffer.allocateDirect(diff.length\*4);
     dbb.order(ByteOrder.nativeOrder());
     FloatBuffer diffBuf = dbb.asFloatBuffer();
     diffBuf.put(diff);
     diffBuf.position(0);
     ByteBuffer sbb
     = ByteBuffer.allocateDirect(spec.length\*4);
     sbb.order(ByteOrder.nativeOrder());
     FloatBuffer specBuf = sbb.asFloatBuffer();
     specBuf.put(spec);
     specBuf.position(0);
     ByteBuffer pbb
     = ByteBuffer.allocateDirect(pos.length\*4);
     pbb.order(ByteOrder.nativeOrder());
     FloatBuffer posBuf = pbb.asFloatBuffer();
     posBuf.put(pos);
     posBuf.position(0);
     ByteBuffer spbb
     = ByteBuffer.allocateDirect(spot_dir.length\*4);
     spbb.order(ByteOrder.nativeOrder());
     FloatBuffer spot_dirBuf = spbb.asFloatBuffer();
     spot_dirBuf.put(spot_dir);
     spot_dirBuf.position(0);
     gl.glLightfv(GL10.GL\_LIGHT0, GL10.GL\_AMBIENT, ambBuf);
     gl.glLightfv(GL10.GL\_LIGHT0, GL10.GL\_DIFFUSE, diffBuf);
     gl.glLightfv(GL10.GL\_LIGHT0, GL10.GL\_SPECULAR, specBuf);
     gl.glLightfv(GL10.GL\_LIGHT0, GL10.GL\_POSITION, posBuf);
     gl.glLightfv(GL10.GL\_LIGHT0, GL10.GL\_SPOT\_DIRECTION,
     spot_dirBuf);
     gl.glLightf(GL10.GL\_LIGHT0, GL10.GL\_SPOT_EXPONENT, 0.0f);
     gl.glLightf(GL10.GL\_LIGHT0, GL10.GL\_SPOT\_CUTOFF, 45.0f);
     gl.glLoadIdentity();
     GLU.gluLookAt(gl,0.0f, 4.0f, 4.0f, 0.0f, 0.0f, 0.0f,
     0.0f, 1.0f, 0.0f);
    }  

    繪制一個(gè)球,并使用藍色材質(zhì):

    public void drawScene(GL10 gl) {
     super.drawScene(gl);
     float[] mat_amb = {0.2f \* 0.4f, 0.2f \* 0.4f,
     0.2f \* 1.0f, 1.0f,};
     float[] mat\_diff = {0.4f, 0.4f, 1.0f, 1.0f,};
     float[] mat\_spec = {1.0f, 1.0f, 1.0f, 1.0f,};
     ByteBuffer mabb
     = ByteBuffer.allocateDirect(mat\_amb.length*4);
     mabb.order(ByteOrder.nativeOrder());
     FloatBuffer mat\_ambBuf = mabb.asFloatBuffer();
     mat\_ambBuf.put(mat\_amb);
     mat\_ambBuf.position(0);
     ByteBuffer mdbb
     = ByteBuffer.allocateDirect(mat\_diff.length\*4);
     mdbb.order(ByteOrder.nativeOrder());
     FloatBuffer mat\_diffBuf = mdbb.asFloatBuffer();
     mat\_diffBuf.put(mat\_diff);
     mat\_diffBuf.position(0);
     ByteBuffer msbb
     = ByteBuffer.allocateDirect(mat\_spec.length\*4);
     msbb.order(ByteOrder.nativeOrder());
     FloatBuffer mat\_specBuf = msbb.asFloatBuffer();
     mat\_specBuf.put(mat\_spec);
     mat\_specBuf.position(0);
     gl.glMaterialfv(GL10.GL\_FRONT\_AND\_BACK,
     GL10.GL\_AMBIENT, mat\_ambBuf);
     gl.glMaterialfv(GL10.GL\_FRONT\_AND\_BACK,
     GL10.GL\_DIFFUSE, mat\_diffBuf);
     gl.glMaterialfv(GL10.GL\_FRONT\_AND\_BACK,
     GL10.GL\_SPECULAR, mat\_specBuf);
     gl.glMaterialf(GL10.GL\_FRONT\_AND\_BACK,
     GL10.GL\_SHININESS, 64.0f);
     sphere.draw(gl);
    }  

    http://wiki.jikexueyuan.com/project/opengl-es-guide/images/104.png" alt="" />

    本例下載

    上一篇:GLSurfaceView下一篇:繪制點(diǎn) Point
    草莓视频在线观看视频6_免费草莓视频_草莓视频在线下载免费官网_草莓视频黄色在线观看