title: How do I make 3D in pyglet?
body: <p>I was trying to create using OpenGL, Python and pyglet, a flat triangle in 3D space, I saw some tutorials on the internet, some videos on YouTube, and in the end I wrote this code down there, the problem is that it did not work as I expected, I thought that if I tried to spin, I would see the triangle turning flat, and when I walked away, the triangle did not have to diminish?</p>
  
  <pre><code>import pyglet
  from pyglet.gl import *
  
  config = Config(sample_buffers=1, samples=8)
  tela = pyglet.window.Window(height=500, width=500, config=config)
  
  glViewport(0,0,500,500)
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  gluPerspective(35,1,0.1,1000)
  glMatrixMode(GL_MODELVIEW)
  
  @tela.event
  def on_draw():
      glBegin(GL_POLYGON)
      glVertex3f(10,10,0)
      glVertex3f(100,10,0)
      glVertex3f(50,100,0)
      glEnd()
      glFlush()
  
  @tela.event
  def on_key_press(s,m):
      tela.clear()
      if s == pyglet.window.key.W:
          glTranslatef(0,0,1)
      if s == pyglet.window.key.S:
          glTranslatef(0,0,-1)
      if s == pyglet.window.key.A:
          glRotatef(1,0,1,0)
      if s == pyglet.window.key.D:
          glRotatef(-1,0,1,0)
  
  pyglet.app.run()
  </code></pre>
  
  <p>When I run the code this appears:</p>
  
  <p><a href="https://i.stack.imgur.com/T4MlL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T4MlL.png" alt="enter image description here"></a></p>
  
  <p>And when I try to spin the scenario it happens:</p>
  
  <p><a href="https://i.stack.imgur.com/K5kBP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K5kBP.png" alt="enter image description here"></a></p>
  
  <p>Does anyone know where I'm going wrong?</p>