Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

#ActualBrother Bob

Posted 22 July 2013 - 12:23 PM

  Alright, let's see if we can get your color uniform up and running.  I'm only going to use code fragments so you can identify proper positioning without me making a big mess here.



GLfloat AdjustColor[] = {1.0, 1.0, 1.0, 1.0}; //


GLint mMVPMatrixHandle; GLint mMVMatrixHandle; GLint mLightPosHandle;

GLint mAdjustColorUniformHandle;         //<--------Add the shader handle



  final String fragmentShader = "precision mediump float;\n" + "uniform vec3 u_LightPos;\n" + "uniform sampler2D u_Texture;\n"   + "uniform vec4 u_Color ;\n"   //<----make sure to uncomment this again



  + "void main()\n" + "{\n" + " gl_FragColor = u_Color * (v_Color * texture2D(u_Texture, v_TexCoordinate));\n" //<----Then add it back into the formula + "}\n";




  mMVPMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVPMatrix"); mMVMatrixHandle = GLES20.glGetUniformLocation(programHandle, "u_MVMatrix"); mLightPosHandle = GLES20.glGetUniformLocation(programHandle, "u_LightPos"); mTextureUniformHandle = GLES20.glGetUniformLocation(programHandle, "u_Texture");

mAdjustColorUniformHandle = GLES20.glGetUniformLocation(programHandle, "u_Color"); //<----now initialize the color uniform here

mPositionHandle = GLES20.glGetAttribLocation(programHandle, "a_Position"); mColorHandle = GLES20.glGetAttribLocation(programHandle, "a_Color"); mNormalHandle = GLES20.glGetAttribLocation(programHandle, "a_Normal"); mTextureCoordinateHandle = GLES20.glGetAttribLocation(programHandle, "a_TexCoordinate");



private void drawQuad() {   AdjustColor[3] -= 0.01;  //<----fade transparency


mCubePositions.position(0);   //...   //...   GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);


  GLES20.glUniform4f(mAdjustColorUniformHandleAdjustColor[0], AdjustColor[1], AdjustColor[2], AdjustColor[3]); //<----now update the shader

  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); }



And also, check to make sure blending is enabled.


Posted 22 July 2013 - 03:21 AM

There is far too much arrogance and out right abuse by site moderators, they are teaching other people to behave this way.  The posts I've made will all be shorty removed and replaced with this notice.  Game development is not the only thing being taught here, bad behavior is being taught as well.