improved webcam.c
[my-code/ivac.git] / webcam.c
1 /*
2  * webcam.c - fetch data from webcam 
3  *
4  * author: hackbard
5  *
6  */
7
8 /* includes */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <X11/Xlib.h>
14 #include "minirgb.h"
15
16 /* variables */
17 Display *display;
18
19 /* main routine */
20 int main(int argc,char **argv) {
21
22  /* local variables */
23  int screen_id,screen_width,screen_height;
24  Window root_window,win;
25  unsigned long white_pixel,black_pixel;
26
27  /* opening display */
28  display=XOpenDisplay(NULL); /* connect on local display :0 */
29  if(display==NULL) {
30   printf("cannot connect to xserver!\n");
31   exit(EXIT_FAILURE);
32  }
33
34  /* getting basic xserver information */
35  // our screen id
36  screen_id=DefaultScreen(display);
37  // dimensions of screen
38  screen_width=DisplayWidth(display,screen_id);
39  screen_height=DisplayHeight(display,screen_id);
40  // how to draw white/black pixels */
41  white_pixel=WhitePixel(display,screen_id);
42  black_pixel=BlackPixel(display,screen_id);
43  // the screen's root window id 
44  root_window=RootWindow(display,screen_id);
45
46  /* print basic xserver settings */
47  printf("screen ID: %d\n",screen_id);
48  printf("dimensions: %d x %d\n",screen_width,screen_height);
49  printf("white color -> %d\n",white_pixel);
50  printf("black color -> %d\n",black_pixel);
51
52  /* open a window */
53  win=XCreateSimpleWindow(display,
54                          root_window,
55                          0,0, // coordinates
56                          screen_width/3,screen_height/3,
57                          500,black_pixel,white_pixel);
58  
59  /* map the window */
60  XMapWindow(display,win);
61
62  /* flush */
63  XFlush(display);
64
65  /* wait a bit */
66  sleep(5);
67  printf("blabla ....\n");
68
69  /* close display */
70  XCloseDisplay(display);
71
72 }