OpenGL - Show Texture Only
<p>I'm working on a 2D isometric game, using pygame and pyopengl.</p>

<p>I'm drawing sprites as quads, with a texture. I managed to get the alpha transparency to work for the texture, but the quad itself is still filled in a solid color (whatever colour gl pipeline is set with at the time). </p>

<p>How do I hide the quad shape, and just show the texture?</p>

<p>Here is a pic showing the problem (gl pipeline set to pink/purple color):</p>

<p><a href="https://i.stack.imgur.com/mCaU4.png" rel="nofollow"><img src="https://i.stack.imgur.com/mCaU4.png" alt="enter image description here"></a></p>

<p>The code is a bit messy, and I've been blindly copy 'n pasting gl calls hoping it solves the problem so there are bound to be quite a few calls in the wrong place or duplicated (or both).</p>

<p>GL Setup code (called once at start of script)</p>

<pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glViewport(0, 0, screen_size[0], screen_size[1])
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, screen_size[0], 0.0, screen_size[1], 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glDisable(GL_LIGHTING)
glEnable(GL_TEXTURE_2D)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
</code></pre>

<p>Drawing setup code (called once at the start of each frame)</p>

<pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glViewport(0, 0, screen_size[0], screen_size[1])
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, screen_size[0], 0.0, screen_size[1], 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glDisable(GL_LIGHTING)
glEnable(GL_TEXTURE_2D)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
</code></pre>

<p>Quad draw code (called for every sprite draw call):</p>

<pre><code>glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_TEXTURE_2D)
glEnable(GL_ALPHA_TEST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)

# Start new transformation matrix
glPushMatrix()

# Apply translation
glTranslatef(self.rect.centerx, self.rect.centery, 0.0)

# Start gl drawing cursor
glColor4f(1.0, 0.0, 1.0, 1.0)

# Bind the texture to this draw session
glBindTexture(GL_TEXTURE_2D, self.texture.id)

# Start drawing a quad
glBegin(GL_QUADS)

# Grab new copy of rect, and move to the origin
r = self.rect.copy()
r.center = (0, 0)

# Draw top left point
glTexCoord2f(1.0, 0.0)
glVertex2f(*r.topleft)

# Draw top right point
glTexCoord2f(0.0, 0.0)
glVertex2f(*r.topright)

# Draw bottom right point
glTexCoord2f(0.0, 1.0)
glVertex2f(*r.bottomright)

# Draw bottom left point
glTexCoord2f(1.0, 1.0)
glVertex2f(*r.bottomleft)

# End quad
glEnd()

# Apply transformation matrix
glPopMatrix()
</code></pre>

<p>Well, either use <em>blending</em>, so that the alpha value actually has effect on opacity. Or use alpha testing, so that incoming fragments with an alpha below/above a certain threshold are discarded.</p>

<p>Blending requires to sort geometry back to front. And given what you want to do alpha testing may be the easier, more straightforward solution.</p>

<p><strong>Update:</strong></p>

<p>Either way it's imperative that the texture's alpha value makes it through to the fragment. If you were using shaders this would be as simple as making sure that the fragment output alpha would receive its value from the texture. But you're using the fixed function pipeline and the mess that's the texture environment state machine.</p>

<p>Using only a single texture your best bet would be a GL_REPLACE texture mode (completely ignores the vertex color). Or GL_MODULATE that takes the vertex color into account. Right now you're assumingly using GL_DECAL mode.</p>

<p>My suggestion: Drop the fixed function pipeline and use shaders. Much easier to get things related to texturing working. Also you'll hard pressed to find hardware that's not using shaders anyway (unless you're planning to run your program on stuff that's been built before 2004).</p>

python opengl