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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:45:20+00:00 2026-06-08T04:45:20+00:00

When I bind my buffers to attributes for my shaders, they seem to be

  • 0

When I bind my buffers to attributes for my shaders, they seem to be getting flipped.

So, I’ve got a vertex shader:

precision highp float;

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 in_position;
in vec3 in_color;

out vec3 ex_Color;

void main(void)
{ 
  gl_Position = projection_matrix * modelview_matrix * vec4(in_position, 1);
  ex_Color = in_color;
}

and a fragment shader

precision highp float;

in vec3 ex_Color;

out vec4 out_frag_color;

void main(void)
{
  out_frag_color = vec4(ex_Color, 1.0);
}

Nothing too complicated. There are two inputs: one for vertex locations, and one for colors. (As a newb, I didn’t want to deal with textures or light yet.)

Now, in my client code, I put data into two arrays of vectors, positionVboData and colorVboData, and I create the VBOs…

GL.GenBuffers(1, out positionVboHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
                       new IntPtr(positionVboData.Length * Vector3.SizeInBytes),
                       positionVboData, BufferUsageHint.StaticDraw);

GL.GenBuffers(1, out colorVboHandle);
GL.BindBuffer(BufferTarget.ArrayBuffer, colorVboHandle);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
                new IntPtr(colorVboData.Length * Vector3.SizeInBytes),
                colorVboData, BufferUsageHint.StaticDraw);

and then, I would expect the following code to work to bind the vbos to the attributes for the shaders:

    GL.EnableVertexAttribArray(0);
    GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle);
    GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, Vector3.SizeInBytes, 0);
    GL.BindAttribLocation(shaderProgramHandle, 0, "in_position");

    GL.EnableVertexAttribArray(1);
    GL.BindBuffer(BufferTarget.ArrayBuffer, colorVboHandle);
    GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, true, Vector3.SizeInBytes, 0);
    GL.BindAttribLocation(shaderProgramHandle, 1, "in_color");

But, in fact I have to swap positionVboHandle and colorVboHandle in the last code sample and then it works perfectly. But that seems backwards to me. What am I missing?


Update

Something weird is going on. If I change the vertex shader to this:

precision highp float;

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 in_position;
in vec3 in_color;

out vec3 ex_Color;

void main(void)
{
  gl_Position = projection_matrix * modelview_matrix * vec4(in_position, 1);
  //ex_Color = in_color;
  ex_Color = vec3(1.0, 1.0, 1.0);
}"

And make no other changes (other than the fix suggested to move the program link after all the set up, it loads the correct attribute, the vertex positions, into in_position rather than into in_color.

  • 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-08T04:45:22+00:00Added an answer on June 8, 2026 at 4:45 am

    So, with Mārtiņš Možeiko’s help, I was able to figure this out. I was calling BindAttribLocation before LinkProgram correctly. However, I wasn’t calling GL.CreateProgram() BEFORE I was binding any of the attribute locations.

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

Sidebar

Related Questions

Is it possible to store different vertex attributes in different vertex buffers? All the
I want a vertex array object in OpenGL ES 2.0 to hold two attributes
In the fancy new versions of OpenGL (3.0 and 4.0 up), built-in vertex attributes
I was certain that if you bind a buffer via glBindBuffer() , you can
boost::bind overloads several operators for its placeholders: For convenience, the function objects produced by
I bind a list<> to a datagrid. Then, in the code behind, I change
Is BIND DNS + DLZ reliable? scalable? Is it a better solution than writing
To bind to the current DataContext in XAML you can use: <TextBlock Text={Binding} />
I bind the ItemsSource of a ComboBox to an ObservableCollection<MyClass> . In code I
I bind keyDown , keyPress and keyUp events to a text input. I need

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.