Results 1 to 4 of 4

Thread: Color Interpolation Not working [Help required]

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2015
    Posts
    13

    Color Interpolation Not working [Help required]

    I have implemented a simple triangle program but somehow triangle is drawn in a single color which is color of first vertex.

    Code is like this

    GLfloat positions[] = {

    0.0f, 0.0f,0.0f,
    1.0f, 1.0f,0.0f,
    -1.0f, 1.0f,0.0f,
    };

    GLfloat colors[] = {

    0.0f,1.0f,0.0f, // Color
    0.0f,1.0f,0.0f, // Color
    0.0f,0.0f,1.0f, // Color
    };


    glGenBuffers(1,&vertexBufferId);
    glBindBuffer(GL_ARRAY_BUFFER,vertexBufferId);
    glBufferData(GL_ARRAY_BUFFER,sizeof(positions),pos itions,GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0);

    glGenBuffers(1,&colorBufferId);
    glBindBuffer(GL_ARRAY_BUFFER,colorBufferId);
    glBufferData(GL_ARRAY_BUFFER,sizeof(colors),colors ,GL_STATIC_DRAW);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,0);


    These are my shaders
    ------------------------------------

    #version 330
    layout(location = 0)in vec3 vert;
    layout(location = 1)in vec3 color;

    out vec3 frag_color;
    void main()
    {
    gl_Position = vec4(vert,0.0);
    frag_color = color;
    }


    #version 330

    out vec4 fragColor;
    in vec3 frag_color;
    void main()
    {
    fragColor = vec4(frag_color,1.0);
    }

    I just see a triangle in green color. Need some help !!!!

  2. #2
    Member Contributor
    Join Date
    Oct 2014
    Posts
    55
    Don't see any error, show full code please.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2015
    Posts
    13
    Quote Originally Posted by Betrayal View Post
    Don't see any error, show full code please.
    I have found the issue in vertex shader....a small typo wasted 4 hours

    Replaced
    gl_Position = vec4(vert,0.0);
    with
    gl_Position = vec4(vert,1.0);

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2015
    Posts
    13
    Found the issue. Posted on forum. Surprised to see such behavior due to small typo in the vertex shader.

Similar Threads

  1. Color of fragment interpolation
    By 313230 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-07-2018, 06:10 AM
  2. Color Interpolation
    By shezad in forum OpenGL: GLSL
    Replies: 0
    Last Post: 08-30-2012, 05:41 AM
  3. OpenGL color interpolation
    By plover in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 03-11-2011, 06:28 AM
  4. color interpolation
    By ugluk in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-14-2010, 12:26 AM
  5. color interpolation
    By jyoung77 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-12-2007, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean