gpt4 book ai didi

python - 如何渲染同一列表中的多个多边形

转载 作者:行者123 更新时间:2023-12-01 09:14:16 25 4
gpt4 key购买 nike

所以基本上我想做的是用 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 创建一个实例,然后瞧,这也不起作用。

最佳答案

主要问题是您为每个字母存储一个点。但是,您不会为要渲染的文本的每个字母存储一个点,而是为使用的每个字母存储一个点。这会导致,如果一个字母被使用两次,则仅存储该字母最后一次出现的位置。

我建议忽略字母位置的计算并动态渲染文本:

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()

preview

关于python - 如何渲染同一列表中的多个多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51391749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com