OpenGL (C Language) : Make the shapes to be moved with keyboard (distortion issue) : <p>Well, we have the following C (GLUT Project) for OpenGL. I use CodeBlocks to compile it (with removed the extra main() function file).
I have based in some examples, sorry if the way I wrote OpenGL is bad. The main thing is to make it work fine.</p>

<p>The result I need is: all the shapes (head, body, hands, legs) of "Mr Robot", to be moved via the keyboard arrow keys. It works as expected but from some points and then, some of the shapes are distorted. I don't know why and how to fix it.</p>

<pre><code>    #include &lt;GL/glut.h&gt;

GLuint kefali_x1=5, kefali_y1=30, kefali_x2=15, kefali_y2=30, kefali_x3=15, kefali_y3=40, kefali_x4=5,kefali_y4=40;
GLuint soma_x1=0, soma_y1=10, soma_x2=20, soma_y2=10, soma_x3=20, soma_y3=30, soma_x4=0, soma_y4=30;
GLuint podia_x1=10, podia_y1=10, podia_x2=20, podia_y2=0, podia_x3=10, podia_y3=-5, podia_x4=0, podia_y4=0;
GLuint dexi_xeri_x1=20, dexi_xeri_y1=30, dexi_xeri_x2=30, dexi_xeri_y2=27.5, dexi_xeri_x3=20, dexi_xeri_y3=25;
GLuint aristero_xeri_x1=-10, aristero_xeri_y1=27.5, aristero_xeri_x2=0, aristero_xeri_y2=30, aristero_xeri_x3=0, aristero_xeri_y3=25;


// σύνθετο σχήμα
GLuint listID;

void MrRobot(GLsizei displayListID)
{
    glNewList(displayListID,GL_COMPILE);

    //Save current colour state
    glPushAttrib(GL_CURRENT_BIT);

    // σώμα
    glColor3f(0.5,0.5,0.5);
    glBegin(GL_POLYGON);
    glVertex2f(soma_x1,soma_y1);
    glVertex2f(soma_x2,soma_y2);
    glVertex2f(soma_x3,soma_y3);
    glVertex2f(soma_x4,soma_y4);
    glEnd();

    // κεφάλι
    glColor3f(0,0,1);
    glBegin(GL_POLYGON);
    glVertex2f(kefali_x1,kefali_y1);
    glVertex2f(kefali_x2,kefali_y2);
    glVertex2f(kefali_x3,kefali_y3);
    glVertex2f(kefali_x4,kefali_y4);
    glEnd();

    // πόδια
    glColor3f(1,0,0);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(podia_x1,podia_y1);
    glVertex2f(podia_x2,podia_y2);
    glVertex2f(podia_x3,podia_y3);
    glVertex2f(podia_x4,podia_y4);
    glEnd();

    // δεξί χέρι
    glColor3f(0,1,0);
    glBegin(GL_TRIANGLES);
    glVertex2f(dexi_xeri_x1,dexi_xeri_y1);
    glVertex2f(dexi_xeri_x2,dexi_xeri_y2);
    glVertex2f(dexi_xeri_x3,dexi_xeri_y3);
    glEnd();

    // αριστερό χέρι
    glColor3f(0,1,0);
    glBegin(GL_TRIANGLES);
    glVertex2f(aristero_xeri_x1,aristero_xeri_y1);
    glVertex2f(aristero_xeri_x2,aristero_xeri_y2);
    glVertex2f(aristero_xeri_x3,aristero_xeri_y3);
    glEnd();

    //Recall saved colour state
    glPopAttrib();

    glEndList();
}

void display()
{
    glClearColor(0,0,0,0);

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1,0,0);

    listID=glGenLists(1);

    MrRobot(listID);

    //Execute the display list (the modelview matrix will be applied)
    glCallList(listID);

    glFlush();
}

void keyboard(unsigned char key,int x, int y)
{
    printf("\nKeyboard event detected. \nCharacter key: %c\nMouse pointer position: x=%d y=%d",key,x,y);

    if (key==GLUT_KEY_UP)
    {
        kefali_y1++;
        kefali_y2++;
        kefali_y3++;
        kefali_y4++;

        soma_y1++;
        soma_y2++;
        soma_y3++;
        soma_y4++;

        podia_y1++;
        podia_y2++;
        podia_y3++;
        podia_y4++;

        dexi_xeri_y1++;
        dexi_xeri_y2++;
        dexi_xeri_y3++;

        aristero_xeri_y1++;
        aristero_xeri_y2++;
        aristero_xeri_y3++;
    }
    if (key==GLUT_KEY_DOWN)
    {
        kefali_y1--;
        kefali_y2--;
        kefali_y3--;
        kefali_y4--;

        soma_y1--;
        soma_y2--;
        soma_y3--;
        soma_y4--;

        podia_y1--;
        podia_y2--;
        podia_y3--;
        podia_y4--;

        dexi_xeri_y1--;
        dexi_xeri_y2--;
        dexi_xeri_y3--;

        aristero_xeri_y1--;
        aristero_xeri_y2--;
        aristero_xeri_y3--;
    }
    if (key==GLUT_KEY_LEFT)
    {
        kefali_x1--;
        kefali_x2--;
        kefali_x3--;
        kefali_x4--;

        soma_x1--;
        soma_x2--;
        soma_x3--;
        soma_x4--;

        podia_x1--;
        podia_x2--;
        podia_x3--;
        podia_x4--;

        dexi_xeri_x1--;
        dexi_xeri_x2--;
        dexi_xeri_x3--;

        aristero_xeri_x1--;
        aristero_xeri_x2--;
        aristero_xeri_x3--;
    }
    if (key==GLUT_KEY_RIGHT)
    {
        kefali_x1++;
        kefali_x2++;
        kefali_x3++;
        kefali_x4++;

        soma_x1++;
        soma_x2++;
        soma_x3++;
        soma_x4++;

        podia_x1++;
        podia_x2++;
        podia_x3++;
        podia_x4++;

        dexi_xeri_x1++;
        dexi_xeri_x2++;
        dexi_xeri_x3++;

        aristero_xeri_x1++;
        aristero_xeri_x2++;
        aristero_xeri_x3++;
    }

    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&amp;argc,argv);
    glutInitWindowPosition(50,50);
    glutInitWindowSize(800,600);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutCreateWindow("MrROBOT");

    glMatrixMode(GL_MODELVIEW);
    gluOrtho2D(-10,50,-10,50);

    glScalef(0.4,0.4,0.4);

    glutDisplayFunc(display);
    glutSpecialFunc(keyboard);
    glutMainLoop();

    return 0;
}
</code></pre>
