Sponsored Content
Full Discussion: xlib blues (XFree86 - Linux)
Top Forums Programming xlib blues (XFree86 - Linux) Post 91334 by Alux on Thursday 1st of December 2005 06:44:56 AM
Old 12-01-2005
Well...I'm Smilie almost there...

For some reason I cannot access any other color than blue. I would also like to apologise for posting a Linux question in the Unix forum. :/

However, my code has advanced and I would like to share the program I wanted to write.

Code:
/*--------------------------------------------------*
*Open a window on the XFree86 system and draw to it.*
*Created by Robbie Dave after learning about Xlib.h *
*---------------------------------------------------*
Compile with: gcc -o dave dave.c -L/usr/X11R6/lib -lX11
*/

// Include the Xlib.h file so as to use X functions.
#include <X11/Xlib.h>
#define NIL (0)       // A name for the void pointer
//This is the 'main' function in c programs.
int main(void) { 

// Initialise the variables.
Window win;
int win_width = 640;
int win_height = 480;
int win_x;
int win_y;
int screen_num;
GC gc;
XImage *xi=NULL; 
XColor system_color_1; 
XColor exact_color;
Colormap davescol;
int x; 
int y; 
int c;

// Get a pointer (*display) to the X display.
Display *display = XOpenDisplay(NIL);

/*
Obtain the screen number using our *display pointer.
The display pointer does not need the asterisk (*).
*/
screen_num = DefaultScreen(display);

/*
Now we have the screen number and display pointer,
we get the GC (graphics context) of the X system.
*/
gc = DefaultGC(display, screen_num); 

// I assume these are the window offsets set to 0.
win_x = win_y = 0;

// Create the window
win = XCreateSimpleWindow(display, RootWindow(display, screen_num), win_x, win_y, win_width, win_height, 0, BlackPixel(display, screen_num), BlackPixel(display, screen_num));

//Make the screen appear and flush events.
XMapWindow(display, win); 
XFlush(display); 

// Capture the screen for drawing.
xi = XGetImage(display, win, 0,0, win_width, win_height, AllPlanes, ZPixmap); 

//Obtain a colormap to get colors.
davescol = DefaultColormap(display, screen_num); 

// Enter a color into the colormap to use later.
Status rc = XAllocNamedColor(display, davescol, "red", &system_color_1, &exact_color);

	//These two x, y for loops used to plot pixels to window.
	for (x = 0; x < win_width; x++) 
		{ 
		for(y = 0; y < win_height; y++) 
			{
			//Plot a pixel. 
			XPutPixel(xi, x, y, exact_color.pixel);
			/*Experiement with the x, y formula
			for different animations.
			*/
			exact_color.pixel = ((x*x)+(y*y))*0.05;

			if (exact_color.pixel > 65535) 
			{exact_color.pixel=65535;}
			}
	
	}

//This for loop is used for animation.
for(c = 8; c < 64; c++) 
	{ 
	//Animate the colors
	XAddPixel(xi, c);
	//Try to control the animation.
	XFlush(display);
	XSync(display, 1);

	/*
	After plotting to every pixel in the window,
	actually display what you've drawn.
	*/
XPutImage(display, win, gc, xi, 0, 0, 0, 0, win_width, win_height); 
	}

//Clean up the memory a bit, but not much.
XDestroyImage(xi);
XCloseDisplay(display); 
return (0);
}

This program is a simple animatiion that compiles without error with gcc. I am really proud of my work, I just wish I had access to more than one color. For some reason, I can only use blue.

EDIT: After reading yet another Xlib tutorial I discovered how to allocate colors. I still do not understand how to utilize these colors for above animation, but I am getting there...

Ah vell...

Last edited by Alux; 12-03-2005 at 03:41 AM..
 

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
XReparentWindow(3X11)						  XLIB FUNCTIONS					     XReparentWindow(3X11)

NAME
XReparentWindow - reparent windows SYNTAX
int XReparentWindow(Display *display, Window w, Window parent, int x, int y); ARGUMENTS
display Specifies the connection to the X server. parent Specifies the parent window. w Specifies the window. x y Specify the x and y coordinatesof the position in the new parent window. DESCRIPTION
If the specified window is mapped, XReparentWindow automatically performs an UnmapWindow request on it, removes it from its current posi- tion in the hierarchy, and inserts it as the child of the specified parent. The window is placed in the stacking order on top with respect to sibling windows. After reparenting the specified window, XReparentWindow causes the X server to generate a ReparentNotify event. The override_redirect mem- ber returned in this event is set to the window's corresponding attribute. Window manager clients usually should ignore this window if this member is set to True. Finally, if the specified window was originally mapped, the X server automatically performs a MapWindow request on it. The X server performs normal exposure processing on formerly obscured windows. The X server might not generate Expose events for regions from the initial UnmapWindow request that are immediately obscured by the final MapWindow request. A BadMatch error results if: o The new parent window is not on the same screen as the old parent window. o The new parent window is the specified window or an inferior of the specified window. o The new parent is InputOnly, and the window is not. o The specified window has a ParentRelative background, and the new parent window is not the same depth as the specified window. XReparentWindow can generate BadMatch and BadWindow errors. DIAGNOSTICS
BadWindow A value for a Window argument does not name a defined Window. SEE ALSO
XChangeSaveSet(3X11) Xlib - C Language X Interface XFree86 Version 4.7.0 XReparentWindow(3X11)
All times are GMT -4. The time now is 12:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy