【发布时间】:2015-11-27 04:02:36
【问题描述】:
我需要有关此代码的帮助。 我想使用我已经拥有的文件“grass.bmp”来渲染草纹理。 这是加载图片的代码。
texsurfGrass = pygame.image.load('grass.bmp')
imageGrass = pygame.image.tostring(texsurfGrass, "RGB", 1)
texID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D,texID)
这是绘图模式下的代码(为地板绘制纹理和网格)
# set drawing mode
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # POINT, LINE, FILL
glPushMatrix()
glTranslate(-ground_gridsize/2,ground_gridsize/2,0)
glTexImage2D(GL_TEXTURE_2D, 0, 3, texsurfGrass.get_width(), texsurfGrass.get_height(), 0, GL_RGB, GL_UNSIGNED_BYTE, imageGrass)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) # GL_LINEAR
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glColor3f(0.0, 1.0, 0.0)
for i in range(-ground_size/2, (ground_size/2)+ground_gridsize, ground_gridsize):
for j in range (-ground_size/2, (ground_size/2)+ground_gridsize, ground_gridsize):
glPushMatrix()
glTranslate(i,j,0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D,texID)
glBegin(GL_QUADS)
glColor3f(0.0, 0.5, 0.0)
glVertex3f(0, 0, 0)
glVertex3f(ground_gridsize, 0, 0)
glVertex3f(ground_gridsize, -ground_gridsize, 0)
glVertex3f(0, -ground_gridsize, 0)
glEnd()
glDisable(GL_TEXTURE_2D)
glPopMatrix()
glPopMatrix()
这些代码仍然生成网格地板,而不是纹理渲染的地板。 请帮我展示渲染的地板。 提前致谢。
【问题讨论】:
标签: python opengl textures texture2d pyopengl