OpenGL with PyOpenGL tutorial Python and PyGame p.1 - Making a rotating Cube Example
Why Stack Overflow recommends it
Stack Overflow users link it as a beginner entry point to OpenGL in Python, and both answerers and people debugging cube-rotation code point back to it.
Recommended by 2 people across 2 different months, 2017 to 2019.
What it is
A 27-minute sentdex tutorial that introduces OpenGL from Python using PyOpenGL with PyGame for the window and event loop. It walks through defining a cube's vertices and edges, drawing it, and moving and rotating it. Sample code is linked from the author's site.
What people said
Recommends uhoh · 2017-10 · Stack Overflow · on “Using OpenGL with Python”
I found this ssentdex.com [LINK] YouTube tutorial very helpful as an entry point to OpenGL from a python perspective; [this video]
Recommends Rabbid76 · 2019-02 · Stack Overflow · on “PyOpenGl Pygame window freezes when run”
As shown in the tutorial video [this video] , the rotation matrix has to be applied inside the main loop . glTranslatef(0.0, 0.0, -5) while True: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glRotatef(1, 3, 1, 1) Note, glRotatef [LINK] does not only generate a rotation matrix. It also multiplies the current matrix by the new rotation matrix. This causes that the cube is continuously and progressively rotated by 1 degree in every frame. If the glRotatef is done outside the loop, then only a single rotation is applied to the cube. After that the scene appears to be frozen. See the example, where I applied the changes to your original application
Cites Moses Wescombe · 2018-05 · Stack Overflow · on “Pygame OpenGL 3D Cube Lag”
I am following a tutorial series that is rather old on pyOpenGL and I am doing exactly as he does. However I am experiencing lag - I have AMD FX-6300 with 8gb ram, GTX-1050ti and files are stored on a flashdrive. I have read some places that using glBegin and glEnd cause issues? What should I use instead and how would I do it in this code: import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * import random """ - A Cube has 8 Nodes/Verticies - 12 Lines/connections - 6 Sides """ vertices = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1) ) edges = ( #Contains vertexes/nodes (0, 1), (0, 3), (0, 4), (2, 1),
Cites SplatM4n · 2019-02 · Stack Overflow · on “PyOpenGl Pygame window freezes when run”
I am using PyOpenGl for the first time and watched this YouTube tutorial about it. Here is the video: [this video] When I try the code however, pygame opens up and moves one frame and then it freezes and does not stop loading. I am not sure if this is because of the system that I am using or the version of python that I am using. I have a 11-6 inch 2012 MacBook Air and am using python 2.7.15. The reason that I am using python 2 instead of python 3 is because when I try and pip3 install PyOpenGl, it gives me an error. import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-