Thread: [PyOpenGL-Users] converting "object position" to "view position" in (py)opengl
Brought to you by:
mcfletch
From: Astan C. <ast...@al...> - 2009-07-01 04:26:56
Attachments:
sample.jpg
|
Hi, 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. Thanks for any help Astan |
From: Dirk R. <dir...@gm...> - 2009-07-01 20:38:17
|
Hi Astan, Astan Chee wrote: > Hi, > 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). Dirk |
From: Astan C. <ast...@al...> - 2009-07-02 03:20:58
|
Hi, I'm drawing characters using pygame and pyopengl like this: 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) def textView(self): w = self.Screen[0] h = self.Screen[1] glViewport(0,0,w,h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, w - 1.0, 0.0, h - 1.0, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def Print(self,s,x,y): s = str(s) i = 0 lx = 0 length = len(s) self.textView() glPushMatrix() while i < length: glRasterPos2i(x + lx, y) ch = self.char[ ord( s[i] ) ] glDrawPixels(ch[1], ch[2], GL_RGBA, GL_UNSIGNED_BYTE, ch[0]) lx += ch[1] i += 1 glPopMatrix() 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 Cheers Astan Dirk Reiners wrote: > Hi Astan, > > Astan Chee wrote: > >> Hi, >> 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). > > Dirk > > |