如何渲染同一列表中的多个多边形
How to render more than one polygon from the same list
基本上我想做的是用 OpenGL 添加一个字母包,因为它没有真正的替代品。 (glBitmap 只是在我的屏幕上显示了一些奇怪的东西)
alphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]#refer to the drawings of the shape I made, in list
alphastring = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] #refer to the letter in string, it makes it easier to compare
lettreLiens = [liena, lienb, lienc, liend, liene, lienf, lieng, lienh, lieni, lienj, lienk, lienl,lienm,lienn,lieno,lienp,lienq,lienr,lien_s,lient,lienu,lienv,lienw,lienx,lieny,lienz] #the links for the points I've drawn, note that lien_s is correct
class text:
def __init__(self,texte,bigness,x,y):
self.texte = texte
self.bigness = bigness
self.x = x
self.y = y
self.textPos = 1
self.textList = self.texte.split(',')
print(len(self.textList))
for self.l in range(0,(len(self.textList))):
for self.n in range(0,25):
if self.textList[self.l] == alphastring[self.n]:
for self.point in alphabet[self.n]:
self.point[0]+=int(self.x)
self.point[1]+=int(self.y)
self.point[0] += int(self.textPos)
self.n = 0
self.textPos+=1
def run(self):
for self.l in range(0,(len(self.textList))):
for self.n in range(0,25):
if self.textList[self.l] == alphastring[self.n]:
glBegin(GL_LINES)
for link in (lettreLiens[self.n]):
for vertex in link:
glVertex3fv(alphabet[self.n][vertex])
glEnd()
self.n = 0
问题是 OpenGL 只为每个字母渲染一个形状。如果我为单词 hello 创建一个实例,它只会在屏幕上显示 he lo。我还尝试为 hel 创建一个实例,然后 lo 但这也不起作用。
主要问题是您为每个字母存储一个分数。但是您不会为要呈现的文本的每个字母存储一个点,而是为使用的每个字母存储一个点。
这导致,如果一个字母被使用两次,则只存储该字母最后一次出现的位置。
我建议省略字母位置的计算并动态呈现文本:
class text:
def __init__(self,texte,bigness,x,y):
self.texte = texte
self.bigness = bigness
self.x = x
self.y = y
self.textList = self.texte.split(',')
def run(self):
textPos = 0
for letter in self.textList:
try:
i = alphastring.index(letter)
except:
continue
else:
glBegin(GL_LINES)
for link in lettreLiens[i]:
for vertex in link:
x = alphabet[i][vertex][0] + self.x + textPos
y = alphabet[i][vertex][1] + self.y
z = alphabet[i][vertex][2]
glVertex3fv([x, y, z])
glEnd()
textPos += 1
查看预览:
def main():
pygame.init()
display = (800,800)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(90,(display[0]/display[1]),0.1,50)
glTranslatef(-1,0.0,-5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == K_r:
glRotatef(10,0,1,0)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
textss.run()
pygame.display.flip()
pygame.time.wait(10)
textss = text('h,a,l,l,o',5,-1,0)
main()
基本上我想做的是用 OpenGL 添加一个字母包,因为它没有真正的替代品。 (glBitmap 只是在我的屏幕上显示了一些奇怪的东西)
alphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]#refer to the drawings of the shape I made, in list
alphastring = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] #refer to the letter in string, it makes it easier to compare
lettreLiens = [liena, lienb, lienc, liend, liene, lienf, lieng, lienh, lieni, lienj, lienk, lienl,lienm,lienn,lieno,lienp,lienq,lienr,lien_s,lient,lienu,lienv,lienw,lienx,lieny,lienz] #the links for the points I've drawn, note that lien_s is correct
class text:
def __init__(self,texte,bigness,x,y):
self.texte = texte
self.bigness = bigness
self.x = x
self.y = y
self.textPos = 1
self.textList = self.texte.split(',')
print(len(self.textList))
for self.l in range(0,(len(self.textList))):
for self.n in range(0,25):
if self.textList[self.l] == alphastring[self.n]:
for self.point in alphabet[self.n]:
self.point[0]+=int(self.x)
self.point[1]+=int(self.y)
self.point[0] += int(self.textPos)
self.n = 0
self.textPos+=1
def run(self):
for self.l in range(0,(len(self.textList))):
for self.n in range(0,25):
if self.textList[self.l] == alphastring[self.n]:
glBegin(GL_LINES)
for link in (lettreLiens[self.n]):
for vertex in link:
glVertex3fv(alphabet[self.n][vertex])
glEnd()
self.n = 0
问题是 OpenGL 只为每个字母渲染一个形状。如果我为单词 hello 创建一个实例,它只会在屏幕上显示 he lo。我还尝试为 hel 创建一个实例,然后 lo 但这也不起作用。
主要问题是您为每个字母存储一个分数。但是您不会为要呈现的文本的每个字母存储一个点,而是为使用的每个字母存储一个点。 这导致,如果一个字母被使用两次,则只存储该字母最后一次出现的位置。
我建议省略字母位置的计算并动态呈现文本:
class text:
def __init__(self,texte,bigness,x,y):
self.texte = texte
self.bigness = bigness
self.x = x
self.y = y
self.textList = self.texte.split(',')
def run(self):
textPos = 0
for letter in self.textList:
try:
i = alphastring.index(letter)
except:
continue
else:
glBegin(GL_LINES)
for link in lettreLiens[i]:
for vertex in link:
x = alphabet[i][vertex][0] + self.x + textPos
y = alphabet[i][vertex][1] + self.y
z = alphabet[i][vertex][2]
glVertex3fv([x, y, z])
glEnd()
textPos += 1
查看预览:
def main():
pygame.init()
display = (800,800)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(90,(display[0]/display[1]),0.1,50)
glTranslatef(-1,0.0,-5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == K_r:
glRotatef(10,0,1,0)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
textss.run()
pygame.display.flip()
pygame.time.wait(10)
textss = text('h,a,l,l,o',5,-1,0)
main()