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 8047385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:04:44+00:00 2026-06-05T06:04:44+00:00

Im trying to add two objects, which is created from one part, but since

  • 0

Im trying to add two objects, which is created from one part, but since i need to color each part i have seperated them. I have tried to render one part which works, but i have afterwards tried to render both which renders nothing.

        glGenVertexArraysOES(1, &_boxVAO);
        glBindVertexArrayOES(_boxVAO);

        int sizeOfFaces = myMesh_m.faces.size() * sizeof(ObjMeshFace);
        glGenBuffers(1, &_boxBuffer);
        glBindBuffer(GL_ARRAY_BUFFER, _boxBuffer);
        glBufferData(GL_ARRAY_BUFFER, sizeOfFaces, &(myMesh_m.faces[0]), GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), 0);
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), (void*)(sizeof(Vector3f) + sizeof(Vector2f)));

        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(2);

        sizeOfFaces = myMesh_p.faces.size() * sizeof(ObjMeshFace);
        glGenBuffers(1, &_boxBuffer_sec);
        glBindBuffer(GL_ARRAY_BUFFER, _boxBuffer_sec);
        glBufferData(GL_ARRAY_BUFFER, sizeOfFaces, &(myMesh_p.faces[0]), GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), 0);
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), (void*)(sizeof(Vector3f) + sizeof(Vector2f)));

        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(2);

        glBindVertexArrayOES(0);

Draw:

            glBindVertexArrayOES( _boxVAO);
            glUniform2fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, color);
            glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, GL_FALSE, _modelViewProjectionMatrix.m);
            glDrawArrays(GL_TRIANGLES, 0, pointerSize_m*3);

Shader.vsh

attribute vec4 position;
attribute vec3 normal;

varying lowp vec4 colorVarying;

uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;

void main()
{
    vec3 eyeNormal = normalize(normalMatrix * normal);
    vec3 lightPosition = vec3(1.0, 1.0, 1.0);
    vec4 diffuseColor = vec4(1, 0.4, 1.0, 1.0);

    float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));

    colorVarying = diffuseColor * nDotVP;

    gl_Position = modelViewProjectionMatrix * position;
}

Shader.fsh

//varying lowp vec4 colorVarying;
uniform lowp vec4 color;


void main()
{
//    gl_FragColor = colorVarying;
    gl_FragColor = color;

}

Why does this fail? Furthermore how do i color each object?

  • 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-06-05T06:04:46+00:00Added an answer on June 5, 2026 at 6:04 am

    This goes on the draw method. The color declaration should be outside the drawing method unless you have a variable that changes. (Like I have this inside the drawing loop because I would have “x” instead of 200)

    GLfloat color[4];
    color[0] = 200/255.0;
    color[1] = 0.0/255.0;
    color[2] = 0.0/255.0;
    color[3] = 255.0/255.0;
    
    GLfloat colorOther[4];
    color[0] = 50/255.0;
    color[1] = 0.0/255.0;
    color[2] = 0.0/255.0;
    color[3] = 255.0/255.0;
    
    glUseProgram(_programBorder);
    glBindVertexArrayOES(_vaoBorder);
    glUniform2fv(uniforms[UNIFORM_COLOR_BORDER], 1, color);
    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX_BORDER], 1, GL_FALSE, _modelViewProjectionMatrix.m);
    glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, 0);
    
    //Modify the model projection matrix to change the position of the object
    
    glUniform2fv(uniforms[UNIFORM_COLOR_BORDER], 1, colorOther);
    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX_BORDER], 1, GL_FALSE, _modelViewProjectionMatrix.m);
    glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, 0);
    

    The fragment shader has to have the uniform like this:

    uniform lowp vec4 color;
    
    void main()
    {
        gl_FragColor = color;
    }
    

    And dont forget to link this uniform properly on your program creation methods.

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

Sidebar

Related Questions

I am trying to add two decimal values but the returned sum is pure
We have a situation where we are trying to add two UITableViews inside a
I am trying to do this List<String> stringList = new ArrayList<String>(); stringList.add(one); stringList.add(two); stringList.add(three);
I have a couple of domain objects which I am trying to save using
So I have two comboBoxes (comboBoxFromAccount and comboBoxToAccount). Each has the same datasource, which
I'm trying to add two inputs to a QTCaptureSession in the following: mainSession =
I am trying to add two larger binary numbers (i.e. number of bits are
I am trying to add two values in a byte array. This is my
I'm trying to compare two numbers, and add an HTML class to the large
I have two objects (class, student) in a database with a many to many

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.