problems with drawing in x using xlib


 
Thread Tools Search this Thread
Top Forums Programming problems with drawing in x using xlib
# 1  
Old 06-13-2009
problems with drawing in x using xlib

Hi all,

I'm currently learning xlib and I've encountered a bizarre mistake: function calls such as XDrawPoint, XDrawLine, etc., don't seem to work; a blank window with nothing in is appears. I believe this has something to do with the window manager I use, fluxbox.

After checking the code and not finding any mistakes, I decided to copy the code here - http://tronche.com/gui/x/xlib-tutorial/prog-2.cc - to see if it would work. Here it is:
Code:
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h>   // I include this to test return values the lazy way
#include <unistd.h>   // So we got the profile for 10 seconds

#define NIL (0)       // A name for the void pointer

main()
{
      // Open the display

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);

      // Get some colors

      int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
      int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

      // Create the window

      Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 
                     200, 100, 0, blackColor, blackColor);

      // We want to get MapNotify events

      XSelectInput(dpy, w, StructureNotifyMask);

      // "Map" the window (that is, make it appear on the screen)

      XMapWindow(dpy, w);

      // Create a "Graphics Context"

      GC gc = XCreateGC(dpy, w, 0, NIL);

      // Tell the GC we draw using the white color

      XSetForeground(dpy, gc, whiteColor);

      // Wait for the MapNotify event

      for(;;) {
        XEvent e;
        XNextEvent(dpy, &e);
        if (e.type == MapNotify)
          break;
      }

      // Draw the line
      
      XDrawLine(dpy, w, gc, 10, 60, 180, 20);

      // Send the "DrawLine" request to the server

      XFlush(dpy);

      // Wait for 10 seconds

      sleep(10);
}

this is indeed completely plagiarized. Funnily though, it works (displays the white line) by starting x without fluxbox, i.e. an .xinitrc file like this:

Code:
"program-name"     #first do the program
startfluxbox           #then start fluxbox

this seems very bizarre and to be honest, I'm a bit lost...are there any settings I've not set?
Any help would be greatly appreciated.

Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Server room drawing software

Hello All, I want to get ride of Excel/word and want some software to draw my server room racks/server and overall topology. Please share you opinion/experience. thanks inadvance (1 Reply)
Discussion started by: Vit0_Corleone
1 Replies

2. Programming

Xlib - Rotation and interpolation of pixmap - Performance problems

I need to rotate a pixmap in XLib with some kind of interpolation to reduce the aliasing. I came up with the following code, which uses bilinear interpolation. It works fine: the rotated image looks perfect, but unfortunately it takes 5 or 6 seconds for each rotation. (in a 300x300, 16 colours... (5 Replies)
Discussion started by: mghis
5 Replies

3. Post Here to Contact Site Administrators and Moderators

Question Regarding Megabits Drawing

Dear Admins / Mods, I have been trying my luck with Megabits Drawing few times ;) but I am not sure how it works! :confused: http://i49.tinypic.com/2ake15f.jpg I have few questions:- Why this page for me is still showing 3 Lotto & 4 SuperForumLotto purchased even after the drawing... (22 Replies)
Discussion started by: Yoda
22 Replies

4. Programming

[ C++ ] Drawing Program.

I made a program that prints dots and lines in a Page. So far that's all i could come up with. When i try to print the lines and the dots it just prints consecutive points,I want it to print the points & lines in the page's coordinates. I have been stuck for a long time now. Please Help. ... (12 Replies)
Discussion started by: Max_Payne
12 Replies

5. Shell Programming and Scripting

Drawing

Hi, Is it possible to draw circle, box and other basic shapes using shell scripts ? If so can anyone please tell as how to do it. Thanks in advance. (3 Replies)
Discussion started by: abrd600
3 Replies

6. Programming

Line-drawing character!

Hi guys, I'm trying to make my program to print out tables usings line-drawing character (alternate char. set) with Curses Library. However, it always prints out control characters (^@) instead of the correct ones. code example: mvwaddch(my_window, 23, 12, ACS_RTEE); appreciate your help,... (5 Replies)
Discussion started by: zecoj
5 Replies
Login or Register to Ask a Question