Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:52:01+00:00 2026-05-27T04:52:01+00:00

Would anyone share an example on how to implement GradienRectangle that would have different

  • 0

Would anyone share an example on how to implement GradienRectangle that would have different colors for each vertex?

I’ve tried to call glColorPointer from GL10 passing float buffer and GL11 using similar to vertices selectOnHardware approach but both methods failed for me…

On AndEngine forum I found this code, but it does not work, however maby it will help someone to find a better solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:52:01+00:00Added an answer on May 27, 2026 at 4:52 am

    that example does not work for you because author have not shown piece of code responsible for setting vertexes.

    Here is my example(it is long, but that’s opengl…)
    NOTE – remember to setUp viewport correctly.

    public static void drawGradientRectangle(GL10 gl, float centerX, float centerY,
                float width, float height) {
            gl.glPushMatrix();
            gl.glDisable(GL10.GL_TEXTURE_2D);
            gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //just in case if you have not done that before
            gl.glFrontFace(GL10.GL_CCW); //Set the face
    
            gl.glTranslatef(centerX, centerY, 0);
            if (width != 1 || height != 1) {
                gl.glScalef(width, height, 1);
            }
            gl.glVertexPointer(2, GL10.GL_FLOAT, 0, GLDrawConstants.vertexBuffer0_5);
            gl.glColorPointer(4, GL10.GL_FLOAT, 0, GLDrawConstants.gradOrangeWhiteBuffer);
    
            // Draw the vertices as triangle strip
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
    
            gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glPopMatrix();
        }
    

    GLDrawConstants class:

    public class GLDrawConstants {
    
        public static final FloatBuffer gradOrangeWhiteBuffer;
        public static final FloatBuffer vertexBuffer0_5;
    
    private static final float vertices0_5[] = { 
            -0.5f, -0.5f,// Bottom Left
            0.5f, -0.5f,// Bottom right
            -0.5f, 0.5f,// Top Left
            0.5f, 0.5f// Top Right
        };
    
    private static final float gradOrangeWhiteColor[] = {
            255/255f, 239/255f, 196/255f, 0f, // Bottom Left 
            255/255f, 239/255f, 196/255f, 0f, // Bottom right
            250/255f, 200/255f, 62/255f, 0.3f, // Top Left
            250/255f, 200/255f, 62/255f, 0.3f  // Top Right
        };
    
    static {
            gradOrangeWhiteBuffer = WDUtils.floatBuffer(gradOrangeWhiteColor);
            vertexBuffer0_5 = WDUtils.floatBuffer(vertices0_5);
    }
    
    }
    

    WDUtils class:

    public class WDUtils {
        /**
         * Make a direct NIO FloatBuffer from an array of floats
         * 
         * @param arr
         *            The array
         * @return The newly created FloatBuffer
         */
        public static final FloatBuffer floatBuffer(float[] arr) {
            ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
            bb.order(ByteOrder.nativeOrder());
            FloatBuffer fb = bb.asFloatBuffer();
            fb.put(arr);
            fb.position(0);
            return fb;
        }
    }
    

    example on my phone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi brothers and sisters, I am wondering if anyone would share their experience on
Would anyone happen to know a trick that will keep this MSBuild task from
Why would anyone declare a constructor protected? I know that constructors are declared private
Anyone understand why in the CoreDataBooks example code that: (a) method for controller swapping
I was wondering if anyone would like to share with me how do you
We have two websites that share some business processes and UI elements. Lets focus
Would anyone know if there are plans or extensions to Visual Studio to allow
Would anyone happen to know how to convert type LPTSTR to char * in
Would anyone know what the Win32 equivalent of opendir is (or if it even
Would anyone be able to tell me how to pull the server name out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.