I am learning PyOpenGL and my first animation test is trying to make a blinking rectangle, but I could not get it to animate, It only blinks when I move the cursor on a window. I guess I am missing a while loop but I could not figure out where to put it. Here is a short of my code.
In fragment shader:
#version 410 core
in Data
{
vec2 uv;
vec4 rgb;
} fs_in;
layout ( location = 0 ) out vec4 fragColor;
uniform float alpha;
void main(){
fragColor = vec4(1.0, 1.0, 1.0, alpha);
}
In main code: I am only using QOpenGLWindow of PyQt5 to draw the scene.
class Rect(QOpenGLWindow):
def __init__(self):
super(Rect, self).__init__()
...
self.queued = 0.0
self.angle = 0.0
def initializeGL(self):
...
def blinking(self):
x = mapX(sin(self.angle), -1, 1, 0, 1 )
self.rect.shader.uniformf('alpha', x)
self.angle += 0.16
def paintGL(self):
glClearColor( 0.0, 0.0, 0.0, 1.0 )
glClear( GL_COLOR_BUFFER_BIT )
...
#Draw a rectangle
...
#Animate the rectangle
self.blinking()
....
And I try this in paintGL but still not working
start = time.time()
time.sleep(0.01)
done = time.time()
timeDifference = done - start
self.queued += timeDifference
while self.queued >= 0.01:
self.blinking()
self.queued -= 0.01
Any suggestions?