1

My target is to draw a polyline from a set of vertex. To do so I did some coding below. But the problem is I draw the polyline correctly but I can't assing color into it. I used an array to set my color for each vertex and then draw it using glDrawArrays(). But unfortunately I didn't get my required color(red).

Can anybody please review my code what I am doing wrong here? I am using OpenGL ES 1.1. Below is my sample code-

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    enable_2d();

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnable(GL_LINE_SMOOTH);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    float line_vertex[]=
    {
        250.0f,250.0f,      //vertex 1
        500.0f,500.0f,  //vertex 2
        500.0f,200.0f       //vertex 3
    };
    float line_color[]=
    {
        1.0f,0.0f,0.0f,
        1.0f,0.0f,0.0f,
        1.0f,0.0f,0.0f
    };

//  glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
    glLineWidth(10.0f);
    glVertexPointer(2, GL_FLOAT, 0, line_vertex);
    glColorPointer(3, GL_FLOAT, 0, line_color);
    glDrawArrays(GL_LINE_STRIP, 0, 3);

    glDisable(GL_BLEND);
    glDisable(GL_LINE_SMOOTH);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisable(GL_TEXTURE_2D);

    //Use utility code to update the screen
    bbutil_swap();
dipanjan
  • 85
  • 2
  • 11

0 Answers0