繪製流程跟2維圖形繪製一致,只是座標需要自己去計算。
圓柱體、圓錐、球型,其實就是繪製乙個乙個的圓形,將他們無限分割就是乙個乙個的圓
//立方體
public class cube extends shape ";
private final string fragmentshadercode =
"precision mediump float;" +
"varying vec4 vcolor;" +
"void main() ";
final float cubepositions = ;
final short index = ;
float color = ;
static final int coords_per_vertex = 3;
static final int bytes_per_float = 4;
int vertexstride = coords_per_vertex * bytes_per_float;
private int program;
private int vpmatrixhandle;
private int positionhandle;
private int colorhandle;
public cube()
public void draw(float vpmatrix)
}
public class cone extends shape ;
private final string vertexshadercode =
// this matrix member variable provides a hook to manipulate
// the coordinates of the objects that use this vertex shader
"uniform mat4 umvpmatrix;" +
"attribute vec4 vposition;" +
"void main() ";
private final string fragmentshadercode =
"precision mediump float;" +
"uniform vec4 vcolor;" +
"void main() ";
private int program;
private int vpmatrixhandle;
private int positionhandle;
private int colorhandle;
public cone(float radius, float height)
private float circlecoords(float radius)
return coords;
}public void draw(float vpmatrix)
}
public class ball extends shape ;
static final int bytes_per_float = 4;
int vertexstride = coords_per_vertex * bytes_per_float;
private final string vertexshadercode =
// this matrix member variable provides a hook to manipulate
// the coordinates of the objects that use this vertex shader
"uniform mat4 umvpmatrix;" +
"attribute vec4 vposition;" +
"void main() ";
private final string fragmentshadercode =
"precision mediump float;" +
"uniform vec4 vcolor;" +
"void main() ";
private int program;
private int vpmatrixhandle;
private int positionhandle;
private int colorhandle;
private int vertexcount;
private static final string tag = ball.class.get******name();
public ball(float radius, int count)
//赤道處圓心 0,0,0 半徑為r 乙個圓形 40份需要41個點
//0-90°圓錐
//0-> -90°圓錐
private float initballcoords(float radius, int count)
for (int i = 1; i <= 90; i++)
return coords;
}private int getcirclecoords(float coords, float radius, int count, float z, int offset)
return offset;
}public void draw(float vpmatrix)
}
為了看起來方便可以順便加乙個動畫
public class glrender_matrix_4 implements glsu***ceview.renderer
@override
public void onsu***cechanged(gl10 gl, int width, int height)
@override
public void ondrawframe(gl10 gl)
}
矩陣可以疊加,球型實在看不出來是球,所以換成gl_lines 了,為了驗證座標計算的正確性
繪製模式:
OpenGLES兩種方式畫立方體
opengles,終於能把這東西畫出來 其實兩種方法都是畫12個三角形畫出來的,在opengl es中,只支援三角形,所以任何複雜多邊形都是由三角形畫出來的。第一種 頂點法 把乙個四邊形當成乙個面,而乙個面由兩個三角形組成。乙個三角形是不是有3個頂點?所以乙個面就有了3 3個頂點,乙個立方體有6個面...
OpenGLES兩種方式畫立方體
opengles這東西真tm蛋疼,研究了幾天了,終於能把這東西畫出來 其實兩種方法都是畫12個三角形畫出來的,在opengl es中,只支援三角形,所以任何複雜多邊形都是由三角形畫出來的。第一種 頂點法 把乙個四邊形當成乙個面,而乙個面由兩個三角形組成。乙個三角形是不是有3個頂點?所以乙個面就有了3...
QT Opengl ES2 0顯示立方體
好嘞,這一次是乙個不錯的突破。前幾次的文章中已經將點雲用qt結合opengl顯示出來了,但是所用的opengl為固定管線繪製方式。這種方式效率低下,比方說你有一塊100w的點雲,那麼每次paint的時候都要迴圈繪製100w個點在螢幕上,這也就是為什麼傳統opengl顯示800w的點雲就開始卡b了。筆...