improved webcam.c
authorhackbard <hackbard>
Wed, 6 Nov 2002 23:33:40 +0000 (23:33 +0000)
committerhackbard <hackbard>
Wed, 6 Nov 2002 23:33:40 +0000 (23:33 +0000)
Makefile
webcam.c

index 0924a8b..2c4f89a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,9 @@
 
 INCLUDEDIR = /usr/include
 
-CFLAGS = -DDEBUG -O3 -Wall
+CFLAGS = -DDEBUG -O3 -Wall -I/usr/X11/include -L/usr/X11/lib -lX11
 
-OBJS = stream receive datagram dgramrcv
+OBJS = stream receive datagram dgramrcv webcam
 
 all: $(OBJS)
 
index 3c5e7a8..7b4be7e 100644 (file)
--- a/webcam.c
+++ b/webcam.c
@@ -5,30 +5,68 @@
  *
  */
 
-include <stdio.h>
-include <stdlib.h>
-include <string.h>
-
-include <X11/Xlib.h>
-
-include "minirgb.h"
+/* includes */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include "minirgb.h"
 
+/* variables */
 Display *display;
 
+/* main routine */
 int main(int argc,char **argv) {
- XEvent xevent;
- char *image, *device=VIDEO_DEV;
 
+ /* local variables */
+ int screen_id,screen_width,screen_height;
+ Window root_window,win;
+ unsigned long white_pixel,black_pixel;
 
- display=XOpenDisplay(NULL);
- if(!display) {
-  printf("cannot open display\n");
-  exit(1);
+ /* opening display */
+ display=XOpenDisplay(NULL); /* connect on local display :0 */
+ if(display==NULL) {
+  printf("cannot connect to xserver!\n");
+  exit(EXIT_FAILURE);
  }
 
- if (minirg_init(display)) {
-  printf("minirg init process failed\n");
-  exit(1);
- }
+ /* getting basic xserver information */
+ // our screen id
+ screen_id=DefaultScreen(display);
+ // dimensions of screen
+ screen_width=DisplayWidth(display,screen_id);
+ screen_height=DisplayHeight(display,screen_id);
+ // how to draw white/black pixels */
+ white_pixel=WhitePixel(display,screen_id);
+ black_pixel=BlackPixel(display,screen_id);
+ // the screen's root window id 
+ root_window=RootWindow(display,screen_id);
+
+ /* print basic xserver settings */
+ printf("screen ID: %d\n",screen_id);
+ printf("dimensions: %d x %d\n",screen_width,screen_height);
+ printf("white color -> %d\n",white_pixel);
+ printf("black color -> %d\n",black_pixel);
 
+ /* open a window */
+ win=XCreateSimpleWindow(display,
+                        root_window,
+                        0,0, // coordinates
+                        screen_width/3,screen_height/3,
+                        500,black_pixel,white_pixel);
  
+ /* map the window */
+ XMapWindow(display,win);
+
+ /* flush */
+ XFlush(display);
+
+ /* wait a bit */
+ sleep(5);
+ printf("blabla ....\n");
+
+ /* close display */
+ XCloseDisplay(display);
+
+}