Jump to content

  • Log In with Google      Sign In   
  • Create Account

#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.

 

//===========================================================================_GLOBALS

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

 

GLint mMVPMatrixHandle; GLint mMVMatrixHandle; GLint mLightPosHandle;

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

 

//===========================================================================_SHADER

  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");

 

//===========================================================================_RENDER  

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.


#5marcClintDion

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.


#4marcClintDion

Posted 17 June 2013 - 08:12 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.

 

//===========================================================================_GLOBALS

GLfloat AdjustColor[] = {1.0, 1.0, 1.0, 1.0};     //<add the variable to control the shader uniform

 

GLint mMVPMatrixHandle;
GLint mMVMatrixHandle;
GLint mLightPosHandle;

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

 

//===========================================================================_SHADER

    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");

   

//===========================================================================_RENDER   

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.


#3marcClintDion

Posted 17 June 2013 - 08:11 PM

    Alright, so you've mostly removed the code for adding an adjustable color variable which is a good way to go if it's not functioning properly, so let's see if we can get it back in and working this time.  I'm only going to use code fragments so you can identify proper positioning without me making a big mess here.

 

//===========================================================================_GLOBALS

GLfloat AdjustColor[] = {1.0, 1.0, 1.0, 1.0};     //<add the variable to control the shader uniform

 

GLint mMVPMatrixHandle;
GLint mMVMatrixHandle;
GLint mLightPosHandle;

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

 

//===========================================================================_SHADER

    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");

   

//===========================================================================_RENDER   

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.


#2marcClintDion

Posted 17 June 2013 - 08:07 PM

    Alright, so you've mostly removed the code for adding an adjustable color variable which is a good way to go if it's not functioning properly, so let's see if we can get it back in and working this time.  I'm only going to use code fragments so you can identify proper positioning without me making a big mess here.

 

//===========================================================================_GLOBALS

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

GLint mAdjustColorUniformHandle;

 

//===========================================================================_SHADER

    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 it again

       //...................

       

        + "void main()\n"
        + "{\n"
        + " gl_FragColor = u_Color * (v_Color * texture2D(u_Texture, v_TexCoordinate));\n" <----Then add it back in to 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");

   

//===========================================================================_RENDER   

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.


#1marcClintDion

Posted 17 June 2013 - 08:07 PM

    Alright, so you've completely removed the code for adding an adjustable color variable which is a good way to go if it's not functioning properly, so let's see if we can get it in, and working this time.  I'm only going to use code fragments so you can identify proper positioning without me making a big mess here.

 

//===========================================================================_GLOBALS

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

GLint mAdjustColorUniformHandle;

 

//===========================================================================_SHADER

    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 it again

       //...................

       

        + "void main()\n"
        + "{\n"
        + " gl_FragColor = u_Color * (v_Color * texture2D(u_Texture, v_TexCoordinate));\n" <----Then add it back in to 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");

   

//===========================================================================_RENDER   

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.


PARTNERS