Revision 2dacdeb2
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/library/Distorted.java | ||
|---|---|---|
| 86 | 86 |
private static boolean mInitialized = false; |
| 87 | 87 |
|
| 88 | 88 |
static int mPositionH; // pass in model position information |
| 89 |
static int mColorH; // pass in model color information |
|
| 90 | 89 |
static int mTextureUniformH;// pass in the texture. |
| 91 | 90 |
static int mNormalH; // pass in model normal information. |
| 92 | 91 |
static int mTextureCoordH; // pass in model texture coordinate information. |
| ... | ... | |
| 352 | 351 |
mTextureUniformH = GLES20.glGetUniformLocation(mProgramH, "u_Texture"); |
| 353 | 352 |
|
| 354 | 353 |
mPositionH = GLES20.glGetAttribLocation( mProgramH, "a_Position"); |
| 355 |
mColorH = GLES20.glGetAttribLocation( mProgramH, "a_Color"); |
|
| 356 |
mNormalH = GLES20.glGetAttribLocation( mProgramH, "a_Normal"); |
|
| 354 |
mNormalH = GLES20.glGetAttribLocation( mProgramH, "a_Normal"); |
|
| 357 | 355 |
mTextureCoordH = GLES20.glGetAttribLocation( mProgramH, "a_TexCoordinate"); |
| 358 | 356 |
|
| 359 | 357 |
EffectQueueFragment.getUniforms(mProgramH); |
| ... | ... | |
| 361 | 359 |
EffectQueueMatrix.getUniforms(mProgramH); |
| 362 | 360 |
|
| 363 | 361 |
GLES20.glEnableVertexAttribArray(mPositionH); |
| 364 |
GLES20.glEnableVertexAttribArray(mColorH); |
|
| 365 | 362 |
GLES20.glEnableVertexAttribArray(mNormalH); |
| 366 | 363 |
GLES20.glEnableVertexAttribArray(mTextureCoordH); |
| 367 | 364 |
|
| src/main/java/org/distorted/library/DistortedBitmapGrid.java | ||
|---|---|---|
| 50 | 50 |
|
| 51 | 51 |
// for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "index["+g+"]="+indexData[g]); |
| 52 | 52 |
|
| 53 |
float[] bufferData= new float[COLOR_DATA_SIZE*dataLength]; |
|
| 54 |
|
|
| 55 |
offset=0; |
|
| 56 |
for(int i=0; i<dataLength; i++) |
|
| 57 |
{
|
|
| 58 |
bufferData[offset++] = 1.0f; // r |
|
| 59 |
bufferData[offset++] = 1.0f; // g |
|
| 60 |
bufferData[offset++] = 1.0f; // b |
|
| 61 |
bufferData[offset++] = 1.0f; // a |
|
| 62 |
} |
|
| 63 |
mGridColors = ByteBuffer.allocateDirect(COLOR_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 64 |
mGridColors.put(bufferData).position(0); |
|
| 65 |
|
|
| 66 |
bufferData = new float[NORMAL_DATA_SIZE*dataLength]; |
|
| 53 |
float[] bufferData = new float[NORMAL_DATA_SIZE*dataLength]; |
|
| 67 | 54 |
|
| 68 | 55 |
offset=0; |
| 69 | 56 |
for(int i=0; i<dataLength; i++) |
| src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
|---|---|---|
| 713 | 713 |
buildGrid(cols,desc,frontOnly); |
| 714 | 714 |
|
| 715 | 715 |
int numVertices=0; |
| 716 |
float[] colorData = new float[COLOR_DATA_SIZE *dataLength]; |
|
| 717 | 716 |
float[] positionData= new float[POSITION_DATA_SIZE*dataLength]; |
| 718 | 717 |
float[] normalData = new float[NORMAL_DATA_SIZE *dataLength]; |
| 719 | 718 |
float[] textureData = new float[TEX_DATA_SIZE *dataLength]; |
| 720 |
|
|
| 721 |
for(int i=0; i<dataLength; i++) |
|
| 722 |
{
|
|
| 723 |
colorData[COLOR_DATA_SIZE*i ] = 1.0f; // r |
|
| 724 |
colorData[COLOR_DATA_SIZE*i+1] = 1.0f; // g |
|
| 725 |
colorData[COLOR_DATA_SIZE*i+2] = 1.0f; // b |
|
| 726 |
colorData[COLOR_DATA_SIZE*i+3] = 1.0f; // a |
|
| 727 |
} |
|
| 728 | 719 |
|
| 729 | 720 |
numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData); |
| 730 | 721 |
|
| ... | ... | |
| 741 | 732 |
android.util.Log.d("CUBES", "normal: " +debug( normalData,3) );
|
| 742 | 733 |
android.util.Log.d("CUBES", "texture: " +debug( textureData,2) );
|
| 743 | 734 |
*/ |
| 744 |
mGridColors = ByteBuffer.allocateDirect(COLOR_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 745 |
mGridColors.put(colorData).position(0); |
|
| 746 | 735 |
|
| 747 | 736 |
mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
| 748 | 737 |
mGridPositions.put(positionData).position(0); |
| src/main/java/org/distorted/library/DistortedObjectGrid.java | ||
|---|---|---|
| 29 | 29 |
{
|
| 30 | 30 |
protected static final int BYTES_PER_FLOAT = 4; // |
| 31 | 31 |
protected static final int POSITION_DATA_SIZE= 3; // Size of the position data in elements |
| 32 |
protected static final int COLOR_DATA_SIZE = 4; // Size of the color data in elements |
|
| 33 | 32 |
protected static final int NORMAL_DATA_SIZE = 3; // Size of the normal data in elements. |
| 34 | 33 |
protected static final int TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements. |
| 35 | 34 |
|
| ... | ... | |
| 42 | 41 |
void draw() |
| 43 | 42 |
{
|
| 44 | 43 |
GLES20.glVertexAttribPointer(Distorted.mPositionH , POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mGridPositions); |
| 45 |
GLES20.glVertexAttribPointer(Distorted.mColorH , COLOR_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mGridColors ); |
|
| 46 | 44 |
GLES20.glVertexAttribPointer(Distorted.mNormalH , NORMAL_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mGridNormals ); |
| 47 | 45 |
GLES20.glVertexAttribPointer(Distorted.mTextureCoordH, TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mGridTexture ); |
| 48 | 46 |
|
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 93 | 93 |
void main() |
| 94 | 94 |
{
|
| 95 | 95 |
vec2 tex = v_TexCoordinate; |
| 96 |
vec4 col = v_Color;
|
|
| 96 |
vec4 col = vec4(1.0,1.0,1.0,1.0);
|
|
| 97 | 97 |
vec2 diff; |
| 98 | 98 |
float pointDegree; |
| 99 | 99 |
|
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 29 | 29 |
uniform mat4 u_MVMatrix; // A constant representing the combined model/view matrix. |
| 30 | 30 |
|
| 31 | 31 |
attribute vec3 a_Position; // Per-vertex position information we will pass in. |
| 32 |
attribute vec4 a_Color; // Per-vertex color information we will pass in. |
|
| 33 |
attribute vec3 a_Normal; // Per-vertex normal information we will pass in. |
|
| 32 |
attribute vec3 a_Normal; // Per-vertex normal information we will pass in. |
|
| 34 | 33 |
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in. |
| 35 | 34 |
|
| 36 | 35 |
varying vec3 v_Position; // |
| 37 |
varying vec4 v_Color; // Those will be passed into the fragment shader. |
|
| 38 |
varying vec3 v_Normal; // |
|
| 36 |
varying vec3 v_Normal; // |
|
| 39 | 37 |
varying vec2 v_TexCoordinate; // |
| 40 | 38 |
|
| 41 | 39 |
uniform int vNumEffects; // total number of vertex effects |
| ... | ... | |
| 351 | 349 |
#endif |
| 352 | 350 |
|
| 353 | 351 |
v_Position = vec3(u_MVMatrix*v); |
| 354 |
v_Color = a_Color; |
|
| 355 |
v_TexCoordinate = a_TexCoordinate; |
|
| 352 |
v_TexCoordinate = a_TexCoordinate; |
|
| 356 | 353 |
v_Normal = normalize(vec3(u_MVMatrix*n)); |
| 357 | 354 |
gl_Position = u_MVPMatrix*v; |
| 358 | 355 |
} |
Also available in: Unified diff
remove the 'Color' vertex attribute.