Note that there are some explanatory texts on larger screens.

plurals
  1. POGLSL Wrong Color Value
    text
    copied!<p>I seem to have run into a strange situation here, because no-one else seems to have the same problem according to various searches in various places. Most of the questions relate to blending or lighting or any variety of other tasks... in my case, the problem exists as a coloring flaw.</p> <p>I'm wanting the shader to provide an exact color; that is, if I screenshot the thing I'm working on and use a color-picker, I want it to show up with the same color I'm using in code. Seems simple enough, right?</p> <pre><code>void main(void) { gl_FragColor = vec4(0.0, 175.0 / 255.0, 50.0 / 255.0, 1.0); } </code></pre> <p>Also simple enough, right? Now, before someone yells "It's the dividing! It won't get it perfectly at your number!" I've tested with greyscale and found a way to make it 100% accurate with shades of grey, but something strange happens with color... I use this and, when I screenshot and use a color picker, I get: R: 68, G: 166, B: 45</p> <p>Now, I'm not a mathematical genius, but I'm pretty sure 0.0 with no additional editing is flat 0 for red. Before this, I was trying to pass in a uniform color, so I started looking through my code to see if it was something strange I was doing, even though I was 95% sure I wasn't. Then I just replaced everything with this set-in-stone, hardcoded vec4 to see if IT came up with the right information.</p> <p>Anyone have any ideas as to why I'm getting the strange red value, and perhaps why the other two values aren't QUITE there? Sure, they're close... but I'd like to get even closer; exact, if at all possible.</p> <p>EDIT: So... I'm not entirely familiar with glReadPixels, so if I did this wrong, let me know. However, my results are what I expect the output to be.</p> <pre><code>GLfloat *data = new GLfloat[4]; if (data) { glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, data); std::cout &lt;&lt; data[0] &lt;&lt; " " &lt;&lt; data[1] &lt;&lt; " " &lt;&lt; data[2] &lt;&lt; " " &lt;&lt; data[3] &lt;&lt; std::endl; std::cout &lt;&lt; data[0] * 255.0 &lt;&lt; " " &lt;&lt; data[1] * 255.0 &lt;&lt; " " &lt;&lt; data[2] * 255.0 &lt;&lt; " " &lt;&lt; data[3] * 255.0 &lt;&lt; std::endl; delete data; } </code></pre> <p>Shader: 0.0, 0.0, 1.0, 1.0</p> <p>RGBA from ReadPixels: 0, 0, 1, 1</p> <p>Shader: 0.0, 175.0 / 255.0, 50.0 / 255.0, 1</p> <p>RGBA from ReadPixels: 0, 0.686275, 0.196078, 1</p> <p>RGBA from ReadPixels multipled by 255: 0, 175, 50, 255</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload