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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:18:06+00:00 2026-06-14T04:18:06+00:00

I have created a basic shader program to brush up on my openGL GLSL.

  • 0

I have created a basic shader program to brush up on my openGL GLSL.

on the cpu side i have properly created my shader program .vp and .fp linked properly and error checked

my result when i render is always a black Triangle

Right before i link my program but after i attach both shaders i do this

glBindAttribLocation( program, 0, "vVertexPos" );
glBindAttribLocation( program, 1, "vColor" );

both my position variables and my color variable in the shaders

all of this is just a quick run through so im not worried about ugly code besides the openGL calls and shader setup

struct PosColVertex
{
    float pos[3];
    float color[4];
};

PosColVertex verts[3];
float vPos1[3] = { 0.5f, 0.0f, -1.0f };
float vPos2[3] = { 0.0f, 1.0f, -1.0f };
float vPos3[3] = { -0.5f, 0.0f, -1.0f };
memcpy( verts[0].pos, vPos1, sizeof(float)*3 );
memcpy( verts[1].pos, vPos2, sizeof(float)*3 );
memcpy( verts[2].pos, vPos3, sizeof(float)*3 );

float vColor1[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
float vColor2[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
float vColor3[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
memcpy( verts[0].color, vColor1, sizeof(float)*4 );
memcpy( verts[1].color, vColor2, sizeof(float)*4 );
memcpy( verts[2].color, vColor3, sizeof(float)*4 );

glGenBuffers( 1, &vboHandle );
glBindBuffer( GL_ARRAY_BUFFER, vboHandle );
glBufferData( GL_ARRAY_BUFFER, sizeof(PosColVertex)*3, verts, GL_DYNAMIC_READ );

for my rendering this is what i do

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

//use our shader program
glUseProgram( program );

//set which vertices we will be using
glBindBuffer( GL_ARRAY_BUFFER, vboHandle );

glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 1 );

//specify our vertex attribute
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof( PosColVertex ), (void*)(0) );

//specify our texture attribute
glVertexAttribPointer( 1, 4, GL_FLOAT, GL_FALSE, sizeof( PosColVertex ), (void*)(12) );

glPushMatrix();

//draw our rectangle
glDrawArrays( GL_TRIANGLES, 0, 3 );

glPopMatrix();

glDisableVertexAttribArray( 0 );
glDisableVertexAttribArray( 1 );

did i do something wrong with the glVertexAttribPointer calls? i’ve checked my shader it works and it does change the values since i hard coded values in there before to test it. but im assuming im not telling openGL on the CPU side how to read my verts properly. any help?

tri.vp

#version 330

in vec3 vVertexPos;

void main(void) 
{ 
    gl_Position = vec4( vVertexPos.x, vVertexPos.y, vVertexPos.z, 1 );
}

tri.fp

#version 330

out vec4 vFragColor;
in vec4 vColor;

void main(void)
{ 
   vFragColor = vColor;
}
  • 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-14T04:18:07+00:00Added an answer on June 14, 2026 at 4:18 am

    You can’t access attributes inside of fragment shaders, only inside of vertex shaders. This makes sense because you are specifying a color for each vertex, and not for each fragment. So, I’d recommend changing your code to read in the color in the vertex shader and smoothly output it to your fragment shader:

    Vertex shader:

    in vec3 vVertexPos;
    in vec4 vColor;
    
    smooth out vec4 fColor;
    
    void main(void) 
    { 
        gl_Position = vec4( vVertexPos.x, vVertexPos.y, vVertexPos.z, 1 );
        fColor = vColor;
    }
    

    Fragment shader:

    smooth in vec4 fColor;
    out vec4 vFragColor;
    
    void main(void)
    { 
       vFragColor = fColor;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

     I have created a basic inheritance program using a polymorphic array. From the parent-class,
I'm new to C# and have created a basic program that I'm running through
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I have created a basic shape in HTML canvas element which works fine. The
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I am newbie to Sencha Touch 2 and have created a basic applications using
We have created a simple wix project for a basic windows application. Everything builds
I have basic hello word example of Prime Faces. I have created dynamic web
I have some basic (stupid) questions about AWS EC2 instances or AMIs. I created
I have created a basic example of a falling ball but I am slightly

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.