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

  • Home
  • SEARCH
  • 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 8491681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:29:57+00:00 2026-06-10T22:29:57+00:00

So im having problems rendering using 2 different shaders. Im currently rendering shapes that

  • 0

So im having problems rendering using 2 different shaders. Im currently rendering shapes that represent dice, what i want is if the dice is selected by the user, it draws an outline by drawing the dice completely red and slightly scaled up, then render the proper dice over it. At the moment some of the dice, for some reason, render the wrong dice for the outline, but the right one for the proper foreground dice.

Im wondering if they aren’t getting their vertex data mixed up somehow. Im not sure if doing something like this is even allowed in openGL:

glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray(effect->vertCoord);        
glVertexAttribPointer(effect->vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);

glEnableVertexAttribArray(effect->toon_vertCoord);        
glVertexAttribPointer(effect->toon_vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);

im trying to bind the vertex data to 2 different shaders here
when i load my first shader i have:

vertCoord = glGetAttribLocation(TexAndLighting, "position");

and the other shader has:

toon_vertCoord = glGetAttribLocation(Toon, "position");

if I use the shaders independently of each other they work fine, but when i try to render both one on top of the other they get the model mixed up some times. here is how my draw function looks:

- (void) draw {
[EAGLContext setCurrentContext:context];

glBindVertexArrayOES(_vertexArray); 

effect->modelViewMatrix = mvm;
effect->numberColour = GLKVector4Make(numbers[colorSelected].r, numbers[colorSelected].g, numbers[colorSelected].b, 1);
effect->faceColour = GLKVector4Make(faceColors[colorSelected].r, faceColors[colorSelected].g, faceColors[colorSelected].b, 1);

if(selected){
    [effect drawOutline]; //this function prepares the shader
    glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
}

[effect prepareToDraw]; //same with this one
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
}

this is what it looks like, as you can see most of the outlines are using the wrong dice, or none at all:
picture of dice

links to full code:
http://pastebin.com/yDKb3wrD Dice.mm //rendering stuff
http://pastebin.com/eBK0pzrK Effects.mm //shader stuff
http://pastebin.com/5LtDAk8J //my shaders, shouldn’t be anything to do with them though

TL;DR: trying to use 2 different shaders that use the same vertex data, but its getting the models mixed up when rendering using both at the same time, well thats what i think is going wrong, quite stumped actually.

  • 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-10T22:29:58+00:00Added an answer on June 10, 2026 at 10:29 pm

    You’re correct, in that this is not allowed (or rather it doesn’t do what you think):

    glEnableVertexAttribArray(effect->vertCoord);        
    glVertexAttribPointer(effect->vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    glEnableVertexAttribArray(effect->toon_vertCoord);        
    glVertexAttribPointer(effect->toon_vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    

    Attributes have no particular linkage to shaders. You can’t tell OpenGL “attribute N is for this shader, and attribute M is for this other shader.”

    Attributes simply bind to indexes, and any shader that happens to have an input at that index will slurp the data that was last bound to that particular index.

    So if you have two shaders, lets call them “toon” and “normal”, which have the following inputs (this is hypothetical):

    normal
      input vertCoord (index = 0)
      input texCoord (index = 1)
    
    toon
      input toon_vertCoord (index = 0)
      input toon_somethingElse (index = 1)
    

    Then when you run this code:

    glEnableVertexAttribArray(effect->vertCoord);        
    glVertexAttribPointer(effect->vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    glEnableVertexAttribArray(effect->toon_vertCoord);        
    glVertexAttribPointer(effect->toon_vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    draw_normal_object();
    

    Your effect->vertCoord is no longer bound to anything, because toon_vertCoord has the same index, and you’ve overwritten the input pointer. So here your normal shader will be sampling from the toon_vertCoord, and everything will be all messed up.

    What you want to do is to enable/pointer all of the attributes for “normal shader”, draw the normal objects, then switch to the toon shader, enable/pointer all of the toon attributes, and then draw the toon objects.

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

Sidebar

Related Questions

Good day. I'm using plenty of CSS3 effects and I'm having problems rendering the
im having problems starting a codeigniter project, the problem is that when i do
I am having a problem rendering my view in the layout page using mvc
Seems Safari is having some problems rendering my SVG, while other browsers does it
I'm having problems in rendering custom textblock with custom font resource on liveTile ?
I am having trouble using the link_to_remote method while rendering a layout. For example
I'm using Devise to set up user authentication, but I'm having difficulty getting users
I'm having problems using {% ifequal s1 some text %} to compare strings with
I'm having trouble rendering my form's fields with WTForms. I'm using it with the
We are having some weird problems using Java3D over a Windows' remote desktop. The

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.