Horde3D http://horde3d.org/forums/ |
|
how to use pyglet.font?[SOLVED] http://horde3d.org/forums/viewtopic.php?f=1&t=1137 |
Page 1 of 1 |
Author: | sellee [ 29.03.2010, 11:47 ] |
Post subject: | how to use pyglet.font?[SOLVED] |
I modified app.py blows. def init(self): ... self.ft = font.load('Arial', 28) self.fps_text = font.Text(self.ft, y=10) def mainloop(self): ... self.fps_text.text = "dddd" self.fps_text.draw() w.flip() h3d.finalizeFrame() but nothing else happens. what is wrong?? |
Author: | Codepoet [ 29.03.2010, 14:17 ] |
Post subject: | Re: how to use pyglet.font? |
Why don't you use h3d.utils.showText? pyglet.font.Text is deprecated. Try pyglet.text.Label. Also make sure the font file was really found. Does a minimal pyglet program work, that is without Horde3D? All raw OpenGL calls must be done after the h3d.finalizeFrame and before w.flip calls. Looking at that code the order of w.flip and h3d.finalizeFrame must be changed. I'm wondering how that worked so good... Anyway now it's fixed in the community repository. |
Author: | sellee [ 30.03.2010, 01:21 ] |
Post subject: | Re: how to use pyglet.font? |
yes. i tried to use pyglet.text.Label , result dosent shown. but basic font,Lable works fine. I want to show 2byte chracters( 가나다... as like hangul, hirakana, kanji). and pyglet.font is easy to use. I glanced http://www.horde3d.org/forums/viewtopic.php?f=6&t=750&hilit=BMFont. but that tool genete paged texture, I dont know how to use it. |
Author: | sellee [ 30.03.2010, 07:33 ] |
Post subject: | Re: how to use pyglet.font? |
I succeed to show mutibyte chracter. the answer is http://www.horde3d.org/forums/viewtopic.php?f=1&t=1027&hilit=primitives. Code: from euclid import Matrix4 self.label = pyglet.text.Label(u'한글Hello, world', font_name='Gulim', # Gulim font is korean (unicode) font_size=20, x=200, y=200, anchor_x='left', anchor_y='center') def mainloop(self): self.domy() w.flip() h3d.finalizeFrame() def domy(self): for w in self._windows: camNode = w.camera projMat = h3d.getCameraProjMat(camNode) glMatrixMode( GL_PROJECTION ) glLoadMatrixf((GLfloat * 16)(*projMat)) glPushMatrix() glLoadIdentity glOrtho(0,640,0,480,0,1) glDisable(GL_DEPTH_TEST) self.label.draw() glPopMatrix() glMatrixMode( GL_MODELVIEW ) glLoadIdentity glEnable(GL_DEPTH_TEST) camera = h3d.getNodeTransMats(camNode) camM = Matrix4() camM[:]=camera[1][:] glLoadMatrixf((GLfloat * 16)(*camM.inverse()[:])) a=h3d.getNodeAABB(self._knight) [minX, minY, minZ], [maxX, maxY, maxZ] = a[0],a[1] glColor3f(1.0, 1.0, 1.0) glBegin(GL_LINE_STRIP) glVertex3f(minX, minY, minZ) glVertex3f(maxX, minY, minZ) glVertex3f(maxX, maxY, minZ) glVertex3f(minX, maxY, minZ) glVertex3f(minX, minY, minZ) glVertex3f(minX, minY, maxZ) glVertex3f(maxX, minY, maxZ) glVertex3f(maxX, maxY, maxZ) glVertex3f(minX, maxY, maxZ) glVertex3f(minX, minY, maxZ) glEnd() glBegin(GL_LINES) glVertex3f(minX, maxY, minZ) glVertex3f(minX, maxY, maxZ) glVertex3f(maxX, minY, minZ) glVertex3f(maxX, minY, maxZ) glVertex3f(maxX, maxY, minZ) glVertex3f(maxX, maxY, maxZ) glEnd() pos = h3d.getNodeTransform(self._knight) glColor3f(1.0, 0.0, 1.0) glBegin(GL_LINES) glVertex3f(pos[0][0],pos[0][1],pos[0][2]) glVertex3f(pos[0][0],pos[0][1]-10,pos[0][2]) glEnd() Attachment:
File comment: hangul is ok hangul.PNG [ 80.15 KiB | Viewed 13633 times ] but it has problem. Attachment:
File comment: invisible hangul_invisi.PNG [ 101.31 KiB | Viewed 13633 times ] The Text is invisible by mesh. How is your think? |
Author: | Codepoet [ 30.03.2010, 09:40 ] |
Post subject: | Re: how to use pyglet.font? |
If you disable z testing the text will be always above the mesh. |
Author: | sellee [ 30.03.2010, 12:02 ] |
Post subject: | Re: how to use pyglet.font? |
ok. now text always on top. thank you. |
Author: | sellee [ 07.04.2010, 08:44 ] |
Post subject: | vector4 |
euclid.py has no vector4. http://www.horde3d.org/wiki/index.php5? ... _the_scene Code: from euclid import Vector3,Matrix4 class Vector4: #Vector3, [x,y,z] def __init__(self, x=0, y=0, z=0, w=0): if isinstance(x, Vector3): self.x = x.x self.y = x.y self.z = x.z self.w = 1. elif isinstance(x, type([])): assert len(x)==3 self.x = x[0] self.y = x[1] self.z = x[2] self.w = y else: self.x = x self.y = y self.z = z self.w = w def __copy__(self): return self.__class__(self.x, self.y, self.z,self.w) copy = __copy__ def __repr__(self): return 'Vector4(%.2f, %.2f, %.2f, %.2f)' % (self.x, self.y, self.z,self.w) def __add__(self, other): assert isinstance(other, Vector4) v4 = Vector4() v4.x = self.x + other.x v4.y = self.y + other.y v4.z = self.z + other.z v4.w = self.w + other.w return v4 def __mul__(self, other): if isinstance(other, Vector4): return Vector4( self.x * other.x, self.y * other.y, self.z * other.z, self.w * other.w) elif isinstance(other, Matrix4): A = other B = self V = Vector4() V.x = A.a * B.x + A.b * B.y + A.c * B.z + A.d * B.w V.y = A.e * B.x + A.f * B.y + A.g * B.z + A.h * B.w V.z = A.i * B.x + A.j * B.y + A.k * B.z + A.l * B.w V.w = A.m * B.x + A.n * B.y + A.o * B.z + A.p * B.w return V else: assert type(other) in (int, long, float) return Vector4( self.x * other, self.y * other, self.z * other, self.w * other) __rmul__ = __mul__ def __imul__(self, other): assert type(other) in (int, long, float) self.x *= other self.y *= other self.z *= other self.w *= other return self now can use vector4. Code: for w in self._windows:
camNode = w.camera # projection ,view matrix camProj = h3d.getCameraProjMat(camNode) projMat = Matrix4() projMat[:] = camProj[:] camTrans = h3d.getNodeTransMats(camNode) viewMat = Matrix4() viewMat[:]=camTrans[1][:] viewMat = viewMat.inverse(); # draw hangul glLoadIdentity() glMatrixMode( GL_PROJECTION ) glLoadIdentity() glOrtho(0,640,0,480,0,1) glDisable(GL_DEPTH_TEST) self.label.draw() #draw player name #nodeMat = h3d.getNodeTransMats(self._knight) #ppos = Vector4(nodeMat[1][12],nodeMat[1][13],nodeMat[1][14],1) nodePos = h3d.getNodeTransform(self._knight) ppos = Vector4(nodePos[0],1) ppos = ppos * (projMat * viewMat) if ppos.w > 0: x = ppos.x/ppos.w y = ppos.y/ppos.w x = int(x * 0.5 * 640 + 320) y = int(y * 0.5 * 480 + 240) self.nmLabel.x = x self.nmLabel.y = y self.nmLabel.draw() glEnable(GL_DEPTH_TEST) glLoadIdentity() |
Author: | Codepoet [ 07.04.2010, 08:50 ] |
Post subject: | Re: how to use pyglet.font?[SOLVED] |
Great! You should submit a patch to http://code.google.com/p/pyeuclid/ for other users. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |