title: Drawing a 3D cube in C programming
body: <p>I am currently practicing how to draw a 3D cube in C but during my compilation i am getting this errors. </p>
  
  <pre><code>/tmp/ccAuvH6Y.o: In function `DrawCube':
  cube3D.c:(.text+0x1e4): undefined reference to `XGetWindowAttributes'
  cube3D.c:(.text+0x203): undefined reference to `glViewport'
  cube3D.c:(.text+0x223): undefined reference to `glClearColor'
  cube3D.c:(.text+0x22d): undefined reference to `glClear'
  cube3D.c:(.text+0x245): undefined reference to `glColor3f'
  cube3D.c:(.text+0x24a): undefined reference to `glPushMatrix'
  cube3D.c:(.text+0x26c): undefined reference to `glRotatef'
  cube3D.c:(.text+0x276): undefined reference to `glEnableClientState'
  cube3D.c:(.text+0x280): undefined reference to `glEnableClientState'
  cube3D.c:(.text+0x29b): undefined reference to `glColorPointer'
  cube3D.c:(.text+0x2b9): undefined reference to `glVertexPointer'
  cube3D.c:(.text+0x2d4): undefined reference to `glDrawElements'
  cube3D.c:(.text+0x2d9): undefined reference to `glPopMatrix'
  cube3D.c:(.text+0x2f2): undefined reference to `glXSwapBuffers'
  /tmp/ccAuvH6Y.o: In function `main':
  cube3D.c:(.text+0x385): undefined reference to `XOpenDisplay'
  cube3D.c:(.text+0x441): undefined reference to `glXChooseVisual'
  cube3D.c:(.text+0x4c9): undefined reference to `XCreateColormap'
  cube3D.c:(.text+0x548): undefined reference to `XCreateWindow'
  cube3D.c:(.text+0x568): undefined reference to `XMapWindow'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>My Code is as follows.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;X11/Xlib.h&gt;
  #include &lt;X11/Xutil.h&gt;
  #include &lt;X11/Xos.h&gt;
  #include &lt;X11/Xatom.h&gt;
  
  #include &lt;GL/gl.h&gt;
  #include &lt;GL/glx.h&gt;
  #include &lt;GL/glu.h&gt;
  
  
  
  Display *dpy;
  XWindowAttributes winattr;
  Window win;
  
  
  void DrawCube(void){
  
  float  vertsCoords[] = {
           0.5f, 0.5f, 0.5f,
          -0.5f, 0.5f, 0.5f,
          -0.5f,-0.5f,0.5f,
          0.5f,-0.5f,0.5f,
          0.5f,-0.5f,-0.5f,
          0.5f,0.5f,-0.5f,
          -0.5f,0.5f,-0.5f,
          -0.5f,-0.5f,-0.5f,
  };
  
  GLubyte indices [] = {
          0,1,2,3,
          5,0,3,4,
          5,6,7,4,
          5,6,1,0,
          1,6,7,2,
          7,4,3,2,
  
  
  };
  GLubyte colors[]={
          255,0,0,
          0,255,0,
          0,0,255,
          255,255,0,
          0,255,255,
          255,0,255,
          255,255,255,
          0,0,0,
  
  
  };
  
  
  static int angle = 0;
          XGetWindowAttributes(dpy,win, &amp;winattr);
          glViewport(0,0,winattr.width,winattr.height);
  
          glClearColor(0.7f,0.7f,0.7f,0.0f);
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          glColor3f(0.0f,0.9f,1.0f);
  
          glPushMatrix();
          glRotatef(angle,0.5,1.0,0.0);
  #if 0
  
          glBegin(GL_TRIANGLES);
          glVertex3f(0.0f,-0.2f,0.5f);
          glVertex3f(-0.5f,0.3f,0.5f);
          glVertex3f(0.5f,0.6f,0.5f);
          glEnd();
  
  #endif
  
          glEnableClientState(GL_VERTEX_ARRAY);
          glEnableClientState(GL_COLOR_ARRAY);
          glColorPointer(3,GL_UNSIGNED_BYTE,0,colors);
          glVertexPointer(3,GL_FLOAT,0,vertsCoords);
  
          glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,indices);
          glPopMatrix();
          glXSwapBuffers(dpy,win);
          usleep(5000);
          angle += 1;
  
          }
  int main(int argc, char *agrv[])
  {
      int screen;
      Window root_win;
      XEvent event;
      unsigned depth;
      XSetWindowAttributes attrs;
  
      GLint att [] = {GLX_RGBA, GLX_DEPTH_SIZE,24,GLX_DOUBLEBUFFER,None};
  
      XVisualInfo *visual;
      GLXContext glc;
  
      if ((dpy = XOpenDisplay(NULL)) == NULL) {
          fprintf(stderr,"Can't Open Display\n");
          exit(1);
      }
  
      screen = DefaultScreen(dpy);
      depth = DefaultDepth(dpy,screen);
      root_win = RootWindow(dpy,screen);
  
      visual = glXChooseVisual(dpy,screen,att);
  
      attrs.border_pixel = BlackPixel(dpy,screen);
      attrs.background_pixel = WhitePixel(dpy,screen);
      attrs.override_redirect = True;
      attrs.colormap = XCreateColormap(dpy,root_win,visual-&gt;visual,AllocNone);
      attrs.event_mask = ExposureMask | KeyPressMask;
  
      win = XCreateWindow(dpy, root_win, 200, 200, 600, 500, 0,
                          visual-&gt;depth, InputOutput,
                          visual-&gt;visual,
                          CWBackPixel|CWColormap|CWBorderPixel|CWEventMask, 
                          &amp;attrs);
  
      XMapWindow(dpy,win);
  }
  </code></pre>