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

  • Home
  • SEARCH
  • 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 701121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:34:28+00:00 2026-05-14T03:34:28+00:00

Is it possible to set the color of a single vertex using a GLSL

  • 0

Is it possible to set the color of a single vertex using a GLSL vertex shader program, in the same way that gl_Position changes the position of a vertex ?

  • 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-05-14T03:34:28+00:00Added an answer on May 14, 2026 at 3:34 am

    For versions of GLSL prior version 1.30, you want to write to the gl_FrontColor or gl_BackColor built-ins, which are varyings accessible in the vertex shader. Read about varyings in the GLSL 1.10 specification (http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.10.59.pdf) to learn more about them, or the GL_ARB_vertex_shader extension specification.

    gl_FrontColor and gl_BackColor are 4D RGBA vectors which take normalized floating point scalars.

    But this will set all the vertices to red, not just one vertex. This is because the same vertex shader is run for all the vertices. If you want to set individual colours, use glColorPointer together with glDrawArrays, glDrawElements, glDrawRangeElements or glMultiDrawElements. The vertex color set by glColorPointer can be read as gl_Color in the vertex shader. gl_Color in the vertex shader is a per-vertex attribute.

    To read the color you wrote in the vertex shader, in the fragment shader, read the built-in varying gl_Color. Finished fragments should be written to gl_FragColor.

    Vertex shader example:

    void main()
    {
        gl_FrontColor = gl_Color;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }
    

    Fragment shader example:

    void main()
    {
        gl_FragColor = gl_Color;
    }
    

    Also, to make the vertex shader set the varyings just like the OpenGL fixed-function pipeline, call the function ftransform().

    void main()
    {
        ftransform();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is that possible to set the color of placeholder text ? <textarea placeholder=Write your
Is it possible to set a color of a specific input field using jquery?
Is it possible to set the fill color of a CALayer that has already
In Java SE it is possible set the cause of an exception using initCause
Is it possible to set up a cron job that will execute a php
Is it possible to set env vars in pom.xml that junit tests uses? Netbeans
Is it possible to set the value behind a two-way binding directly, without knowing
Is it possible to set z-index that only applies to a certain 'scope', such
Using C# Winforms (3.5). Is it possible to set the row colors to automatically
When I set style color, it changes both the text color for the selected

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.