And, for the benefit of future Googlers, the texel/vertex color
combining that Tristam describes above is described in loving detail
under the documentation for

  glTexEnvi(GLenum target, GLenum pname, GLint param)

(and its type-clones).

I have no perceptible performance problems even if I don't put these
Textures into my application's atlas, at least not compared to my n^2
collision detection, so unless anyone has any bright ideas they are
just bursting to tell, I'm not going to worry about that any more.

In the twisted world I live in, a screenshot like the following serves
as some sort of compensation for putting up with my silly questions
all day and all night.

A mild stress test of my 'floating / fading numbers' now that I sort
of half understand what's going on:
http://brokenspell.googlecode.com/svn/trunk/docs/screenshots/screenshot05-performance-test-hudpoints.jpg

For what it's worth, I would like it if people would post most
screenshots of works in progress to pyglet-users.

Best,

  Jonathan


On Nov 20, 11:01 am, Jonathan Hartley <[email protected]> wrote:
> I'm slowly getting it. Sorry for all the traffic.
>
> I just understood the significance of creating the texture above using
> the GL_ALPHA flag. The texture I am creating only has an alpha channel
> - no RGB. That explains the behaviour I'm seeing perfectly.
>
> So my only outstanding question is, how do I get the texture regions
> generated by label2texture into my application's texture atlas? I
> thought that an atlas must copy the textures it is given into its own
> internal texture, so I don't get why it cares about the type of the
> image which is added.
>
> I'm only using this atlas because, up until now, everything visible in
> my application (background, sprites, hud images, etc,) has gone into
> the atlas, to be rendered with a single batch.draw(). So I figured I'd
> stick with that pattern if I could.
>
> On Nov 20, 10:23 am, Jonathan Hartley <[email protected]> wrote:
>
> > I should be going back to re-read my opengl books shouldn't I? Alright
> > I'll do that.
>
> > Also: I don't usually spell 'vertex' like that. I need my morning
> > coffee.
>
> > On Nov 20, 10:21 am, Jonathan Hartley <[email protected]> wrote:
>
> > > I have made some progress figuring this out. Minimal code repro below.
>
> > > The text unexpectedly appears black only when I convert my Texture
> > > into an ImageData, by calling get_image_data() on it.
>
> > > I did this conversion because I add the image to a texture atlas for
> > > rendering speed, and when adding the original Texture, I got:
>
> > >   File "C:\Python26\lib\site-packages\pyglet\image\__init__.py", line
> > > 482, in
> > > blit_to_texture
> > >     raise ImageException('Cannot blit %r to a texture.' %
> > > self)
> > > pyglet.image.ImageException: Cannot blit <TextureRegion 12x28> to a
> > > texture.
>
> > > So, I think my only absolutely critical question is: How should I be
> > > adding the Textures returned from label2texture() to my texture atlas?
>
> > > Howevever, I clearly still have minstunderstood lots.
>
> > > If I remove all usage of a Texture atlas (as in the minimal repro
> > > below) and leave the Texture as a Texture, then the text is not
> > > rendered black. It is rendered exactly as the current vertex color.
> > > This still surprises me. Tristam, you say that the vertex color
> > > multiplies the texture color, which I interpret to mean:
>
> > >     color visible on screen = pixel color in the texture * current
> > > vertext color
>
> > > (where all these are three component rgb values, with each component
> > > normalised to lie within range 0.0 to 1.0, and the multiply operator
> > > works like this:
>
> > >    Rout = Rtexture * Rvert
> > >    Gout = Gtexture * Gvert
> > >    Bout = Btexture * Bvert
>
> > > But that isn't precisely what I'm seeing. As visible in the repro
> > > below, it looks like:
>
> > >     color visible on screen = current vertext color
>
> > > i.e. the drawing the label yellow (255, 255, 0), and setting the
> > > current pixel color to blue (0, 0, 255), I see blue text on screen.
> > > How does Bout get a non-zero value, if Btexture = 0?
>
> > > Thanks for any understanding anyone can bequeath me with.
>
> > >   - Jonathan aka tartley
>
> > > import code
> > > import pyglet
> > > from pyglet.text import Label
> > > from pyglet.gl import *
>
> > > def label2texture(label):
> > >     vertex_list = label._vertex_lists[0].vertices[:]
> > >     xpos = map(int, vertex_list[::8])
> > >     ypos = map(int, vertex_list[1::8])
> > >     glyphs = label._get_glyphs()
>
> > >     xstart = xpos[0]
> > >     xend = xpos[-1] + glyphs[-1].width
> > >     width = xend - xstart
>
> > >     ystart = min(ypos)
> > >     yend = max(ystart+glyph.height for glyph in glyphs)
> > >     height = yend - ystart
>
> > >     texture = pyglet.image.Texture.create(width, height,
> > > pyglet.gl.GL_ALPHA)
>
> > >     for glyph, x, y in zip(glyphs, xpos, ypos):
> > >         data = glyph.get_image_data()
> > >         x = x - xstart
> > >         y =  height - glyph.height - y + ystart
> > >         texture.blit_into(data, x, y, 0)
>
> > >     return texture
>
> > > class Render(object):
>
> > >     def create_image(self):
> > >         label = pyglet.text.Label(
> > >           text='yellow text',
> > >           font_name = 'Times New Roman',
> > >           font_size = 48,
> > >           bold = True,
> > >           x = 20,
> > >           y = 5,
> > >           color = (255, 255, 0, 255), # YELLOW
> > >         )
> > >         image = label2texture(label)
>
> > >         # converting the Texture to an ImageData turns the text black
> > >         # so don't do that
> > >         # but then how can we add this texture to a texture atlas?
> > >         # image = image.get_image_data()
>
> > >         image.anchor_x = image.width / 2
> > >         image.anchor_y = image.height / 2
> > >         return image
>
> > >     def init(self):
> > >         self.win = pyglet.window.Window()
> > >         self.win.on_draw = self.draw
>
> > >         glEnable(GL_BLEND)
> > >         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
> > >         glClearColor(0.9, 0.5, 0.7, 0.0)
>
> > >         self.image = self.create_image()
>
> > >         pyglet.app.run()
>
> > >     def draw(self):
> > >         glClear(GL_COLOR_BUFFER_BIT)
> > >         glColor3f(0.0, 0.0, 1.0) # current vertex color = blue
>
> > >         # image displays text in the current vertex color?
> > >         self.image.blit(self.win.width / 2, self.win.height / 2)
>
> > > if __name__ == '__main__':
> > >     r = Render()
> > >     r.init()
>
> > > On Nov 19, 10:54 pm, Jonathan Hartley <[email protected]> wrote:
>
> > > > The texture's transparent pixels (around the text) come out as the
> > > > screen background color, they are perfect.
> > > > The problem is with the pixels which make up the text - they are
> > > > black, I expected the text baked into the texture to be the same color
> > > > that I created the text Label as.
>
> > > > I just got home, I'll do more tests now... ta!
>
> > > > On Nov 19, 10:16 pm, Tristam MacDonald <[email protected]> wrote:
>
> > > > > On Thu, Nov 19, 2009 at 4:58 PM, Jonathan Hartley 
> > > > > <[email protected]>wrote:
>
> > > > > > Ahar! Thanks - so it does. Thanks very much for the pointer.
>
> > > > > > I shall interpret that as a clue as I look for why the text looks
> > > > > > black in my own application. Obviously I made sure that vertex color
> > > > > > is set to something non-black, but that hasn't fixed it.
>
> > > > > Are the pixels in your texture black (since 0*x == 0)? A common 
> > > > > problem is
> > > > > that someone manages to encode an opaque, black texture in an RGBA 
> > > > > format...
>
> > > > > --
> > > > > Tristam MacDonaldhttp://swiftcoder.wordpress.com/

--

You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=.


Reply via email to