Guest User

Untitled

a guest
Jun 18th, 2019
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pyglet
  2. from pyglet.gl import *
  3. from OpenGL.GL.shaders import *
  4.  
  5. t = pyglet.window.Window(height=500, width=500, caption="Oi")
  6. glEnable(GL_DEPTH_TEST)
  7. glEnable(GL_LIGHTING)
  8. glEnable(GL_LIGHT0)
  9. rodar = 0
  10.  
  11. v = b"""
  12. #version 330 core
  13. layout (location = 0) in vec3 aPos;
  14.  
  15. out vec4 vertexColor;
  16.  
  17. void main()
  18. {
  19. gl_Position = vec4(aPos, 1.0);
  20. vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
  21. }
  22. """
  23. f = b"""
  24. #version 330 core
  25. out vec4 FragColor;
  26.  
  27. in vec4 vertexColor;
  28.  
  29. void main()
  30. {
  31. FragColor = vertexColor;
  32. }
  33. """
  34.  
  35. shader = compileProgram(compileShader(v, GL_VERTEX_SHADER),compileShader(f, GL_FRAGMENT_SHADER))
  36.  
  37. @t.event
  38. def on_draw():
  39. global rodar
  40. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  41. glMatrixMode(GL_PROJECTION)
  42. glLoadIdentity()
  43. gluPerspective(45, 1, 0.1, 2000)
  44. glMatrixMode(GL_MODELVIEW)
  45. glLoadIdentity()
  46. gluLookAt(0,0,25,0,0,-1,0,1,0)
  47. glPushMatrix()
  48. glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat*4)(.4,.4,.4,1))
  49. glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(1,0,0,1))
  50. glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat*4)(0,0,0,1))
  51. glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(50,0,0,1))
  52. glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat*3)(-40,0,0))
  53. glPopMatrix()
  54. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat*4)(.6,.1,.1,1))
  55. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (GLfloat*4)(.7,.7,.7,1))
  56. glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat*1)(1))
  57. # shader
  58. glUseProgram(shader)
  59. # cubo
  60. rodar+=1
  61. glPushMatrix()
  62. glRotatef(rodar, .8, .5, 0)
  63. glBegin(GL_POLYGON)
  64. glNormal3f(0,1,0)
  65. glVertex3f(2,2,2)
  66. glVertex3f(2,2,-2)
  67. glVertex3f(-2,2,-2)
  68. glVertex3f(-2,2,2)
  69. glEnd()
  70. glBegin(GL_POLYGON)
  71. glNormal3f(0,-1,0)
  72. glVertex3f(2,-2,2)
  73. glVertex3f(2,-2,-2)
  74. glVertex3f(-2,-2,-2)
  75. glVertex3f(-2,-2,2)
  76. glEnd()
  77. glBegin(GL_POLYGON)
  78. glNormal3f(1,0,0)
  79. glVertex3f(2,-2,2)
  80. glVertex3f(2,-2,-2)
  81. glVertex3f(2,2,-2)
  82. glVertex3f(2,2,2)
  83. glEnd()
  84. glBegin(GL_POLYGON)
  85. glNormal3f(-1,0,0)
  86. glVertex3f(-2,-2,2)
  87. glVertex3f(-2,-2,-2)
  88. glVertex3f(-2,2,-2)
  89. glVertex3f(-2,2,2)
  90. glEnd()
  91. glBegin(GL_POLYGON)
  92. glNormal3f(0,0,1)
  93. glVertex3f(2,-2,2)
  94. glVertex3f(-2,-2,2)
  95. glVertex3f(-2,2,2)
  96. glVertex3f(2,2,2)
  97. glEnd()
  98. glBegin(GL_POLYGON)
  99. glNormal3f(0,0,-1)
  100. glVertex3f(2,-2,-2)
  101. glVertex3f(-2,-2,-2)
  102. glVertex3f(-2,2,-2)
  103. glVertex3f(2,2,-2)
  104. glEnd()
  105. glPopMatrix()
  106. # parede do lado
  107. glBegin(GL_POLYGON)
  108. glNormal3f(1,0,0)
  109. glVertex3f(-5,-6,6)
  110. glVertex3f(-5,-6,-6)
  111. glVertex3f(-5,6,-6)
  112. glVertex3f(-5,6,6)
  113. glEnd()
  114.  
  115. def SRO(dt):
  116. on_draw()
  117.  
  118. pyglet.clock.schedule_interval(SRO, 1/60)
  119.  
  120. pyglet.app.run()
RAW Paste Data