title: Rendering textures in pyopengl
body: <p>I am trying to get the basics of how texture rendering work and doing it with pyopengl as I've worked for a time with it.</p>
  
  <p>I have read some documentation, from the red book to tutorials, but my program does not render any texture - it just changes (darkens) the colors on the surfaces of the objects drawn.</p>
  
  <p>Here is the relevant code: the function which reads the image file, sets the texture properties and enables it,</p>
  
  
  
  <pre class="lang-py prettyprint-override"><code>def generateTexture(texPath):
      im = Image.open(texPath)
      texData = im.tostring('raw', 'RGBX', 0, -1)
      texName = [0]
      glGenTextures(1, texName)
      glBindTexture(GL_TEXTURE_2D, texName[0])
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData)
      glEnable(GL_TEXTURE_2D)
      return texName
  </code></pre>
  
  <p>and the function which creates the object's vertex visualization list,</p>
  
  <pre class="lang-py prettyprint-override"><code>def showVertices(obj):
      Vertices_List = glGenLists(1)
      glNewList(Vertices_List,GL_COMPILE)
      texNames = generateTexture('tex_stone.jpg')
      glBindTexture(GL_TEXTURE_2D, texNames[0])
      glColor3f(1.0,1.0,1.0)
      glBegin(GL_POINTS)
      i=0
      while i &lt; obj.nv:
          glNormal3f(obj.vnormals[i].x, obj.vnormals[i].y, obj.vnormals[i].z)
          glTexCoord2f(obj.texcoords[i].x, obj.texcoords[i].y)
          glVertex3f(obj.vertices[i].x,obj.vertices[i].y,obj.vertices[i].z)
          i = i + 1
      glEnd()
      glEndList()
      return Vertices_List
  </code></pre>
  
  <p>I don't think this is the problem, but I am calculating the texture coordinates for each object manually (calculating the intersection of a 'sorrounding sphere' with a vector from the object's center through each vertex).</p>
  
  <p>If you want to see any other part of the code, please ask. Any hint or advice will be much appreciated.</p>
  
  <p>EDIT: Maybe the problem is that I use <code>glTexCoord2f()</code> in combination with <code>glBegin(GL_POINTS)</code> and, in order for it to apply the texture to a surface, should be used with <code>GL_QUADS</code>, <code>GL_TRIANGLES</code> or any other surface? The thing is that my objects' sides are not composed of a determined polygon type: mainly it is triangles, but there are quadrilaters too.</p>