title: How do I change the color of one vertex instead of all of them?
body: <p>I'm new to OpenGL and GLSL, and am learning it through <a href="http://open.gl/" rel="noreferrer">http://open.gl/</a> .</p>
  
  <p>I've managed to draw a triangle and change the color of all the vertexes using:</p>
  
  <pre><code>glUniform3f(uniColor, red, 0.0, 0.0)
  </code></pre>
  
  <p>Where the value of "red" is constantly changing, but this updates the color value of all the vertexes in the triangle, while I only want to change one or two of the vertexes.</p>
  
  <p>Looking over the code I don't see where I can implement any logic to focus on one vertex instead of them all (the code is almost completely based on <a href="http://open.gl/content/code/c2_triangle_uniform.txt" rel="noreferrer">http://open.gl/content/code/c2_triangle_uniform.txt</a>)</p>
  
  <p>In this code however: <a href="http://open.gl/content/code/c2_color_triangle.txt" rel="noreferrer">http://open.gl/content/code/c2_color_triangle.txt</a> , each vertex gets it's own color, but it seems to be hard coded, I can't dynamically change the colors as the program progresses.</p>
  
  <p>I'm guessing </p>
  
  <pre><code>uniColor = glGetUniformLocation(shader.handle, "triangleColor")
  </code></pre>
  
  <p>gives me the location of a variable I can change and this variable is used to update the color of all the vertexes, and that perhaps what I need to do is create 3 variables, one for each vertex and then access those, but how do I do that?</p>
  
  <p>If I look at the GLSL I have a "uniform vec3 triangleColor;" which is then used in</p>
  
  <pre><code>void main()
  {
      outColor = vec4(triangleColor, 1.0);
  }
  </code></pre>
  
  <p>but even if I create 3 such triangleColor variables how would I tell void main() to distinguish which vertex gets what variable?</p>
  
  <p>The code:</p>
  
  <pre><code>import pyglet
  from pyglet.gl import *
  from shader import Shader
  from ctypes import pointer, sizeof
  import math
  import time
  
  
  window = pyglet.window.Window(800, 600, "OpenGL")
  window.set_location(100, 100)
  
  
  # Vertex Input
  ## Vertex Array Objects
  vao = GLuint()
  glGenVertexArrays(1, pointer(vao))
  glBindVertexArray(vao)
  
  ## Vertex Buffer Object
  vbo = GLuint()
  glGenBuffers(1, pointer(vbo)) # Generate 1 buffer
  
  vertices = [0.0, 0.5,
              0.5, -0.5,
              -0.5, -0.5]
  ## Convert the verteces array to a GLfloat array, usable by glBufferData
  vertices_gl = (GLfloat * len(vertices))(*vertices)
  
  ## Upload data to GPU
  glBindBuffer(GL_ARRAY_BUFFER, vbo)
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_gl), vertices_gl, GL_STATIC_DRAW)
  
  
  # Shaders (Vertex and Fragment shaders)
  vertex = """
  #version 150
  
  in vec2 position;
  
  void main()
  {
      gl_Position = vec4(position, 0.0, 1.0);
  }
  """
  fragment = """
  #version 150
  
  uniform vec3 triangleColor;
  
  out vec4 outColor;
  
  void main()
  {
      outColor = vec4(triangleColor, 1.0);
  }
  """
  ## Compiling shaders and combining them into a program 
  shader = Shader(vertex, fragment)
  shader.bind() #glUseProgram
  
  
  # Making the link between vertex data and attributes
  ## shader.handle holds the value of glCreateProgram()
  posAttrib = glGetAttribLocation(shader.handle, "position")
  glEnableVertexAttribArray(posAttrib)
  glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0)
  
  uniColor = glGetUniformLocation(shader.handle, "triangleColor")
  
  # Set clear color
  glClearColor(0.0, 0.0, 0.0, 1.0)
  
  
  @window.event
  def on_draw():
      # Set the color of the triangle
      red = (math.sin(time.clock() * 4.0) + 1.0) / 2.0
      glUniform3f(uniColor, red, 0.0, 0.0)
  
      # Clear the screen to black
      glClear(GL_COLOR_BUFFER_BIT)
  
      # Draw a triangle from the 3 vertices
      glDrawArrays(GL_TRIANGLES, 0, 3)
  
  @window.event
  def on_key_press(symbol, modifiers):
      pass
  
  @window.event
  def on_key_release(symbol, modifiers):
      pass
  
  def update(dt):
      pass
  pyglet.clock.schedule(update)
  
  
  pyglet.app.run()
  </code></pre>