title: Rendering 3D Models With Textures That Have Alpha In OpenGL
body: <p>So Im trying to figure out the best way to render a 3D model in OpenGL when some of the textures applied to it have alpha channels.</p>
  
  <p>When I have the depth buffer enabled, and start drawing all the triangles in a 3D model, if it draws a triangle that is in front of another triangle in the model, it will simply not render the back triangle when it gets to it. The problem is when the front triangle has alpha transparency, and should be able to be seen through to the triangle behind it, but the triangle behind is still not rendered.</p>
  
  <p>Disabling the depth buffer eliminates that problem, but creates the obvious issue that if the triangle IS opaque, then it will still render triangles behind it on top if rendered after.</p>
  
  <p>For example, I am trying to render a pine tree that is basically some cones stacked on top of each other that have a transparent base. The following picture shows the problem that arises when the depth buffer is enabled:</p>
  
  <p><img src="https://i.stack.imgur.com/Buu6r.jpg" alt="Depth Buffer Enabled"></p>
  
  <p>You can see how you can still see the outline of the transparent triangles.</p>
  
  <p>The next picture shows what it looks like when the depth buffer is disabled.</p>
  
  <p><img src="https://i.stack.imgur.com/Fkpxl.jpg" alt="Depth Buffer Disabled"></p>
  
  <p>Here you can see how some of the triangles on the back of the tree are being rendered in front of the rest of the tree.</p>
  
  <p>Any ideas how to address this issue, and render the pine tree properly?</p>
  
  <p>P.S. I am using shaders to render everything.</p>