implement own OpenGL code in script

I want to implement my own OpenGL code into a script as a busy loading screen of type
How can I do that?
is it possible?

this would be the code without window stuff etc…

glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_STENCIL_BUFFER_BIT);

        glBegin(GL_POLYGON);

        glColor3f(1, 1, 1);
        glVertex2f(-1.0,-1.0);
        glColor3f(1, 1, 1);
        glVertex2f(-1.0,10.0);

        glColor3f(0, 0, 50.0);
        glVertex2f(10.0,10.0);
        glColor3f(0, 0, 50.0);
        glVertex2f(10.0, -1.0);

        glEnd();
        
        glPushMatrix();
        glRotatef(theta, 0.0f, 0.0f, 0.0f); 

        glBegin (GL_QUADS);
        glColor3f (1, 0, 2); glVertex2f (0,0);
        glColor3f (1, 0, 2); glVertex2f (0,1);
        glColor3f (1, 0, 2); glVertex2f (1,1);
        glColor3f (1, 0, 2); glVertex2f (1,0);
        glEnd ();

        glBegin (GL_QUADS);
        glColor3f (0, 1, 0); glVertex2f (0,0);
        glColor3f (0, 1, 0); glVertex2f (0,-1);
        glColor3f (0, 1, 0); glVertex2f (-1,-1);
        glColor3f (0, 1, 0); glVertex2f (-1,0);
        glEnd ();

        glPopMatrix();

        SwapBuffers(hDC);

        theta += 2.3f;
        Sleep (1);

You can use the GL class.