0

I need help for this code. I want to render a grass texture using file "grass.bmp" which I already have. This is the code for load image.

texsurfGrass = pygame.image.load('grass.bmp')
imageGrass = pygame.image.tostring(texsurfGrass, "RGB", 1)
texID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D,texID)

This is the code in drawing mode (Draw texture and grid for the floor)

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

Those codes are still produce grid floor instead of texture-rendered floor. Please help me to show the rendered floor. Thanks in advance.

Leo
  • 3
  • 1

1 Answers1

0

I see a couple of problems. First the glPolygonMode() call is asking for wireframe (you're telling it you want wireframes, you probably want fill, which is the default).

Second, you'll eventually have to put in some texture coordinates somehow. It looks like you are programming OpenGL 1.0 or 2.0, so you can look at glTexCoord2f or the related TexCoord functions.

Ned Zepplin
  • 501
  • 4
  • 9
  • Thanks Ned Zepplin for your help... Now I already change the glPolygonMode() to fill as you said and yes the floor become the green color, but still the grass is not rendered..it just give the green color. and about the glTexCoord2f, where should I put those function my code? can you please point out for me? Because I'm really new in PyOpenGL. Thanks in advance :D – Leo Nov 27 '15 at 06:23
  • Every vertex should have a texture coordinate. The texture coordinate must be given before the glVertex call. So glTexCoord2f(); glVertex3f(); glTexCoord2f(); glVertex3f(); – Ned Zepplin Nov 28 '15 at 17:22