Sponsored Content
Full Discussion: xlib blues (XFree86 - Linux)
Top Forums Programming xlib blues (XFree86 - Linux) Post 91321 by Alux on Thursday 1st of December 2005 03:40:49 AM
Old 12-01-2005
xlib blues (XFree86 - Linux)

My goal is to open a window in the X-server and plot a series of pixels. However, I find many examples I have tried to draw to a window fail and the window remains blank. Therefore, I am here requesting information. I do not know c, and am a beginner. Currently, I am using a mix-match of code, running against the gcc compiler finding errors and fixing them as I go along. I have experienced segmentation faults, but the following code produces a minimal amount of error.

Code:
/* window.c --This program opens a window on the display
* Use "gcc -o window window.c -L/usr/X11R6/lib -lX11
* to compile this code.
*/


#include <X11/X.h>
#include <X11/Xlib.h>
#include<stdio.h>
#define width	320
#define height	200

int main(void)
{
Display *display;
Window window, rootwindow;
int screen;
GC gc;
XImage *img=NULL;
int x;
int y;

display = XOpenDisplay(NULL);
screen = DefaultScreen(display);
gc = DefaultGC(display, screen);
rootwindow = RootWindow(display,screen);
window = XCreateSimpleWindow(display, rootwindow,
                0, 0, width, height, 1, 0, 0);
XMapWindow(display, window);
XImage *xi;
unsigned long pixelvalue1;


xi = XCreateImage(display, 0, 8, ZPixmap,
                   0, malloc(width*height), width, height, 
		   8, 0);

pixelvalue1 = 65535;
for (x = 0; x < width/2; x++)
	{
		for(y = 0; y < height/2; y++)
			{
				XPutPixel(xi, x, y, pixelvalue1);
			}
	}
printf("putting image\n");

XPutImage(display, window, gc, xi, 0, 0, 0, 0, width, height);
sleep (5);
return (0);
}

The result of this code, is to open a window (which it does) for 5 seconds/cycles, and also plot a series of pixels half the length of the width and height specified.

However, what actually happens is it opens a window with a black background, plots nothing, and I am left frustrated with little resources. I suspect the problem may lie in either XCreateImage, or XPutPixel commands. I suspect I have not got the right values for either command.

Can anyone here offer a simple solution to my problem of wanting to plot pixels to a window?

Finally - I would like to elabroate on my plans...

I intend to further the pixel plotting using double buffering, for a simple animation routine I written in PHP graphics. As animation is not available in PHP, this is the reason for myself attempting c coding without any prior knowledge of the c language. However, I do have a basic grasp of BASIC (if, for, while etc), and constant/variable declaration (int, long, double etc).

Please can someone enlighten me with a code snippet as to how I can accomplish my goal of plotting individual pixels to the screen.

Much thanks,

Alux.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

NFS Blues

I have a situation where there are two SCO R5 Open Server Unix boxes in a remote location. The two boxes are inter-related via NFS mounts. My problem occurs when one of the boxes goes down, the NFS relationship stops the remaining machine from carrying on, even though it would be able to do so if... (2 Replies)
Discussion started by: pcs7088
2 Replies

2. Filesystems, Disks and Memory

D'oh! Apple Pro Keyboard Blues

My new Pro Keyboard works great, but the power switch on the computer won't turn the computer on! It's an older model, a Revision D iMac (333), but I know I've used the computer-mounted power switch to power the machine down before. Am I missing something? (1 Reply)
Discussion started by: chenly
1 Replies

3. UNIX Desktop Questions & Answers

ATI && XFree86 (Linux)

Anyone who have any ideas how-to make X faster. I have a ATI Rage Mobility P/M AGP 2x card and I wanto get it fast, mostly for movie playback and so. Is there OpenGL and GLX support? regards Esaia (1 Reply)
Discussion started by: Esaia
1 Replies

4. BSD

again XFree86

hi everybody i installed FreeBSD 5.x on a box with a video card Diamond SpeedStar A90 and a Fujitsu Siemens Monitor B772-1 when i do "startx" it gives me something like this: fatal error: no devices detected no screen detected i'm lost...i don't know what to... (3 Replies)
Discussion started by: hmaiida
3 Replies

5. What is on Your Mind?

Career blues!!!

Hi all, Just writing to know how to approach the situation. I am currently with 2+ exp in a support environment in Unix..mostly on the application side..have not done any Sysadmin work.. My interest is to move towards Unix admin or towards Storage/Networking side..But the problem is that my... (1 Reply)
Discussion started by: ranj@chn
1 Replies

6. UNIX Desktop Questions & Answers

kde blues

So I'm pretty much a n00b when it comes to Unix but I've decided to give it a shot. I managed to install FreeBSD 6.2 on one partition of my hard drive on my laptop. During the installation I choose to install KDE, not wanting to deal with a non GUI operating system right away! However, whenever I... (1 Reply)
Discussion started by: rinquisitor
1 Replies

7. UNIX for Dummies Questions & Answers

New account blues !

hi .. I tried to create a new account with useradd leghorn (being in root) Also I gave a password for the same using passwd leghorn. So when I go su legorn, it doesnt prompt for the password. Kindly drop in your valuable comments ~cheers (9 Replies)
Discussion started by: leghorn
9 Replies

8. Programming

Linux (Xlib) Application hangs on GetGeometry()

Hello, I was just wondering why XGetGeometry() would cause a hang in an application. In the xlib book it says any of there "Get" functions don't necessarily return immediately. Is there a way to make a it return immediately or other functions that will give me the same results. I... (1 Reply)
Discussion started by: TMurray77
1 Replies
XClearArea(3X11)						     MIT X11R4							  XClearArea(3X11)

Name
       XClearArea, XClearWindow - clear area or window

Syntax
       XClearArea(display, w, x, y, width, height, exposures)
	  Display *display;
	  Window w;
	  int x, y;
	  unsigned int width, height;
	  Bool exposures;

       XClearWindow(display, w)
	  Display *display;
	  Window w;

Arguments
       display	 Specifies the connection to the X server.

       exposures Specifies a Boolean value that indicates if events are to be generated.

       w	 Specifies the window.

       width
       height	 Specify the width and height, which are the dimensions of the rectangle.

       x
       y	 Specify the x and y coordinates, which are relative to the origin of the window and specify the upper-left corner of the rectan-
		 gle.

Description
       The function paints a rectangular area in the specified window according to the specified dimensions with the window's background pixel or
       pixmap.	The subwindow-mode effectively is If width is zero, it is replaced with the current width of the window minus x.  If height is
       zero, it is replaced with the current height of the window minus y.  If the window has a defined background tile, the rectangle clipped by
       any children is filled with this tile.  If the window has background the contents of the window are not changed.  In either case, if expo-
       sures is one or more events are generated for regions of the rectangle that are either visible or are being retained in a backing store.
       If you specify a window whose class is a error results.

       can generate and errors.

       The function clears the entire area in the specified window and is equivalent to (display, w, 0, 0, 0, 0, If the window has a defined back-
       ground tile, the rectangle is tiled with a plane-mask of all ones and function.	If the window has background the contents of the window
       are not changed.  If you specify a window whose class is a error results.

       can generate and errors.

Diagnostics
       An	 window is used as a Drawable.

       Some numeric value falls outside the range of values accepted by the request.
		 Unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. Any argument
		 defined as a set of alternatives can generate this error.

       A value for a Window argument does not name a defined Window.

See Also
       XCopyArea(3X11)
       X Window System: The Complete Reference, Second Edition, Robert W. Scheifler and James Gettys

																  XClearArea(3X11)
All times are GMT -4. The time now is 10:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy