[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] converting "object position" to "view position" in (py)opengl



When are you doing the gluProject? It should be after the matrices are
set for the frame. Can you paste the code for that?

To billboard text, you'd render it to a texture.

Something like:

surface = self.font.render(s, True, (255, 255, 255))
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, surface.get_width(),
surface.get_height(), GL_RGBA, GL_UNSIGNED_BYTE,
pygame.image.tostring(surface, "RGBA", True)

Then, when rendering, transform the modelview matrix as in that link,
and draw a quad with the correct aspect ratio.

On Wed, Jul 1, 2009 at 10:58 PM, Astan Chee<astan.chee@xxxxxxxxx> wrote:
> Thanks for that, but it doesn't seem to work. Well, it gives coordinates of
> x,y(,z) but when the camera changes angle (but not position), the
> coordinates don't change. What else do I need to be doing in this?
> Anyway, I also forgot to mention this is how I make the text images:
> def __init__(self):
>         pygame.font.init()
>         self.font = pygame.font.Font(FONT,18)
>         self.char = []
>         for c in range(256):
>             self.char.append(self.CreateCharacter(chr(c)))
>         self.char = tuple(self.char)
>
>     def CreateCharacter(self,s):
>         try:
>             letter_render = self.font.render(s,1,(255,255,255), (0,0,0))
>             letter = pygame.image.tostring(letter_render,'RGBA',1)
>             letter_w,letter_h = letter_render.get_size()
>         except:
>             letter = None
>             letter_w = letter_h= 0
>         return (letter,letter_w,letter_h)
> Since I make the text this way, I'm thinking of just doing it billboard but
> I'm not sure how to implement half of this.
> Thanks again for any help.
> Cheers
> Astan
>
>
> Ian Mallett wrote:
>
> Er, the last three arguments return the data in C.  In Python, the syntax is
> different:
>
> C: gluProject(objx,objy,objz,model,proj,view,winx,winy,winz)
> Python: winx,winy,winz = gluProject(objx,objy,objz,model,proj)
>
> And yes, it returns a z-coord, which should take into account the near
> clipping plane.  As long as the plane is ~0, (x,y) should be fairly
> accurate.
>
> Keep in mind that the (x,y) coordinates are *real* coordinates, (i.e., the y
> is not flipped).  (0,0) is the bottom left.  If you rasterize the font as
> you were, it shouldn't be a problem.
>
> Ian
>