title: get and set color of pixel
body: <p>I need to set color for pixel.</p>
  
  <p>When I try to set color of a certain pixel(by clicking left mouse button). My mouse function.</p>
  
  <pre><code>void mouse(int button, int state, int x, int y) {
  
  if (button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN) {
      pixel *p = new pixel();
      p-&gt;x = x;
      p-&gt;y = HEIGHT - y;
      stack.push(p);
  
      float arr[3];
      readPixel(p-&gt;x, p-&gt;y, arr);
  
      std::cout&lt;&lt;"pixel color: ";
      std::cout&lt;&lt;arr[0]&lt;&lt;" "&lt;&lt;arr[1]&lt;&lt;" "&lt;&lt;arr[2]&lt;&lt;std::endl;
  
      drawPixel(p-&gt;x, p-&gt;y);
  }
  }
  </code></pre>
  
  <p>Here <code>readPixel</code> method</p>
  
  <pre><code>void readPixel(int x, int y, float (&amp;a)[3]) {
  
  GLubyte arr[3];
  glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, arr);
  
  a[0] = (float)arr[0] / 255.0f;
  a[1] = (float)arr[1] / 255.0f;
  a[2] = (float)arr[2] / 255.0f;
  };
  </code></pre>
  
  <p>The problem is with setting color for pixel.
  I create structure <code>pixel</code> with fields <code>x</code> and <code>y</code>. When I click left button, object <code>pixel</code> is added to stack. 
  When I try to set color for pixel(draw it) - pixel does not change its color in method <code>drawPixel</code></p>
  
  <pre><code>void draw() {
  
  glBegin(GL_POINTS);
  if (!stack.empty()) {
      drawPixel(stack.top()-&gt;x, stack.top()-&gt;y);
      stack.pop();
  }
  glEnd();
  
  glFlush();
  };
  
  void drawPixel(int x, int y) {
  
  glRasterPos2i(x, y); 
  glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, &amp;val);
  
  };
  </code></pre>
  
  <p>Where <code>&amp;val</code> is <code>float val[3] = { 1.0, 1.0, 0.0 };</code>
  So the question is <strong>how to set color for pixel with coordinates x and y?</strong></p>