I'm drawing characters using pygame and pyopengl like this:
self.font = pygame.font.Font(FONT,18)
self.char = 
for c in range(256):
self.char = tuple(self.char)
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()
letter = None
letter_w = letter_h= 0
w = self.Screen
h = self.Screen
glOrtho(0.0, w - 1.0, 0.0, h - 1.0, -1.0, 1.0)
s = str(s)
i = 0
lx = 0
length = len(s)
while i < length:
glRasterPos2i(x + lx, y)
ch = self.char[ ord( s[i] ) ]
glDrawPixels(ch, ch, GL_RGBA, GL_UNSIGNED_BYTE, ch)
lx += ch
i += 1
and then when I need to print in a certain part of the screen, I do a
self.Print("text",0,0) which will do a print on the bottom left corner.
I don't think i'm using glBitmap
Dirk Reiners wrote:
Astan Chee wrote:
Im relatively new to opengl and I'm not familiat with its jargon but
what I have is objects in a 3D world in various positions and a camera
that can "move" around. What I'm trying to do is if the distance between
object and camera is close enough, display some information on the
screen on the object.
I know how to calculate distance and I know how to print/display text in
opengl (I'm using glOrtho and glRasterPos2i to map out the characters
one at a time).
Anyway, what I'm having problems with is how do I calculate where to
display these information on the screen so that it overlaps the object
(assuming I know the distance and the angle of the camera and the object
relative to the camera). Does this make sense? I've attached an image
that I photoshopped to look like what I'm trying to do.
What are you using to draw the characters? glBitmap? Your use of glRasterPos2i
hints at that.
In that case you can just ignore the glOrtho and use glRasterPos3f to position
your text in the 3D scene (e.g. in the center of the object). The main
difficulty is putting the chacaters next to each other, and glBitmap takes care
of that nicely.
If you're using a different method things get a little more complicated (but not
too much, really).