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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:29:54+00:00 2026-06-08T08:29:54+00:00

How would I create a line (possibly colored) with shaders? I’m using programmable pipeline

  • 0

How would I create a line (possibly colored) with shaders? I’m using programmable pipeline and I’m a beginner with openGL. I can’t find an example on how to draw lines with shaders.. I suppose I have to load a VAO (vertices array object) into the shader, but then what? What functions should I use and how?

  • 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-08T08:29:56+00:00Added an answer on June 8, 2026 at 8:29 am

    First, set use the shaderprogram. Then draw lines using glDrawArrays (or Elements if your data is indexed) with mode=GL_LINES or one of the other line drawing modes.

    Here’s a code example for 2D lines with different color in each end. If shading mode is set to smooth, OpenGL will interpolate the colors along the line.

    struct LineSegment_t
    {
      float x1, y1;
      float r1,g1,b1,a1;
      float x2, y2;
      float r2,g2,b2,a2;
    };
    
    int num_verts = lines.size()*2;
    glBindVertexArray( line_vao ); // setup for the layout of LineSegment_t
    glBindBuffer(GL_ARRAY_BUFFER, LineBufferObject);
    glBufferData(GL_ARRAY_BUFFER, sizeof(LineSegment_t)/2 * num_verts, &lines[0], GL_DYNAMIC_DRAW);
    glDrawArrays(GL_LINES, 0, num_verts );
    

    If you need more flexibility, you can draw lines using triangles by creating a rectangle (4 points) from the line endpoints. In 2D you can create the 4 points by translating the endpoints using the line normal / perpendicular (-y,x) by the desired line with. In 3D you need to make sure the triangles are aligned to the camera as in billboarding.

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

Sidebar

Related Questions

How would I create the following scenario that rails can provide for carrierwave, using
What would be a equivalent example in perl of the bellow code to create
I'm using VS2008 and would like to create a compile time warning / error
I created a command line application. Then I realized it would be handy to
I'm currently writing a function what would create a zip file, which will be
Versioning If your events changes you would create a new version of that event,
I have a class which would create a bean and the bean has few
I need to have script.sh , that would create files f1.txt and f2.txt with
How would I create a Mongoid model that has the ability to be saved
How would I create a DecimalFormat that would only have seven digits total and

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.