All colors in rabbyt (and pyglet) are in the range 0..1. That's how
they are with OpenGL. You get used to it pretty quick :-)
> while not window.has_exit:
> clock.tick()
> window.dispatch_events()
> rabbyt.clear((1,0,0,1))
> pyglet.gl.glColor4f(0, 0, 0, 1.0)
> pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, 0,
> 800, 600)))
> mySprite.render()
> clockDisplay.draw()
> window.flip()
>
> When I run it I see (very briefly) a white screen - then I see (for an
> instant) my black line) and then everything is covered over with the
> (now red) background (counter visible at bottom left).
>
> I think I'm missing something Pyglet related to get the lines to
> 'stay' on the screen.
Disable texturing before drawing your lines:
glDisable(GL_TEXTURE_2D)
Rendering the sprite enables texturing, which causes your line to be
drawn using the star texture. But since you don't specify texture
coordinates, only the last texture coordinate is used. This ends up
being one of the texture corners, which is 100% transparent.
MWM
They *are* "actual" RGB values, they're just not
assuming you've got 8-bit pixels. :-)
Floats in the range 0.0-1.0 are fairly common
practice when dealing with colours in a device
independent way.
--
Greg
> (In fact, maybe this possibility of alpha == 1/255 should be listed in
> the FAQ as another reason your window can be blank.
It would be better to fix the API to remove this
inconsistency, I think.
--
Greg
The statement "that's how they are in OpenGL" isn't the whole truth.
In fact OpenGL lets you specify color values as bytes, short ints,
long ints or floats. The most popular of those options is bytes and
floats. The former for vertex lists because they are compact and the
latter for immediate mode. Though you can in fact use any
representation you choose for either.
In the case of integer types, their most positive representation is
mapped to 1.0, and to further confuse the issue, it supports both
signed and unsigned integers of various sizes. Thus the answer to the
question: "what is the range for color values in OpenGL", the true
answer is "it depends" or perhaps even "what range do you want to
use?" ;^)
Pyglet chooses unsigned bytes for labels probably because under the
covers it creates vertex lists to represent text and byte values are
commonly used for vertex lists. However the choice is arbitrary and
it's easy to see how some apis might use float values instead equally
arbitrarily, though it is not ideal.
Pyglet doesn't insulate you all that much from OpenGL itself, though
it does provide some extremely useful facilities for you. So, it would
be wise for you to pick up the OpenGL Red Book so you can figure out
what's really going on.
-Casey
The statement "that's how they are in OpenGL" isn't the whole truth.
On Wed, Mar 25, 2009 at 6:18 PM, Bruce Smith <ore...@gmail.com> wrote:
>
> On Mar 25, 7:49 am, Matthew Marshall <matt...@matthewmarshall.org>
> wrote:
>> All colors in rabbyt (and pyglet) are in the range 0..1. That's how
>> they are with OpenGL. You get used to it pretty quick :-)
>
> Actually, some pyglet colors are from 0..1 and others are from 0..255,
> depending on the API -- for example:
In fact OpenGL lets you specify color values as bytes, short ints,
long ints or floats. The most popular of those options is bytes and
floats. The former for vertex lists because they are compact and the
latter for immediate mode. Though you can in fact use any
representation you choose for either.
By default framebuffers have 8 bits per colour per pixel, and the
"floating point" representation you see in shaders is really a fixed
point representation of that (0 bits before the decimal point, 8 bits
after it). Newer cards can give floating point buffers for
compositing with HDR, but this is the exception.
In reply to the earlier post asking if it would be better for pyglet
to use the same colour format consistently -- yes it would. The
current setup (where pyglet.graphics uses unsigned bytes and
everything else more or less uses floats) was a design mistake. FWIW,
using unsigned bytes for colour in vertex arrays gives a measurable
performance benefit over floats (YMMV).
Alex.
Of course pyglet could simply map floating point input values to their
corresponding unsigned byte values, to keep the performance benefit
without exposing that implementation detail. Certainly not convenient
to change in the b/w compatible way now though...
-Casey
Yes, you can send the data as unsigned bytes, and the implementation
might store them as unsigned bytes, but the range 0..1 is still how
colors are worked with. You can't set the blend mode to
GL_TWO_FIFTY_FIVE_MINUS_SRC. Lighting and fog work by multiplying
colors. Etc.
In my mind, colors in unsigned bytes are still 0..1, just stored in a
tighter representation for practical implementation.
But my mind's a strange place :-)
> Thus the answer to the
> question: "what is the range for color values in OpenGL", the true
> answer is "it depends" or perhaps even "what range do you want to
> use?" ;^)
IMHO, answering "0..1" is still an accurate answer, and it's far more
useful of an answer than "it depends". :-)
MWM