以下是代码段(Xlib):
void update_screen()
{
int X,Y;
for (X = 0; X < Wnd_X; X++)
for (Y = 0; Y < Wnd_Y; Y++)
{
XDrawPoint(dsp, win, gc_2, X, Y);
usleep(100);
}
return;
}
但它会是这样的:
然后:
为什么无法使用XDrawPoint 顺利绘制点?
如何用绿色流畅地填充窗户?
完整代码:
#include <X11/Xlib.h> // must precede most other headers!
#include <stdlib.h>
int Wnd_X=500;
int Wnd_Y=500;
void update_screen();
GC gc_2;
Window win;
Display *dsp;
int main()
{
dsp = XOpenDisplay(NULL);
int screen = DefaultScreen(dsp);
win = XCreateWindow(dsp, DefaultRootWindow(dsp), 0, 0, Wnd_X, Wnd_Y, 0, 0, 0, 0, 0, 0);
//XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, Wnd_X, Wnd_Y, 0, 0x000000, 0xFFFFFF);
Atom wmDelete = XInternAtom(dsp, "WM_DELETE_WINDOW", True);
XSetWMProtocols(dsp, win, &wmDelete, 1);
XGCValues gcvalues_2;
gcvalues_2.function = GXcopy;
gcvalues_2.plane_mask = AllPlanes;
gcvalues_2.foreground = 0x00FF00;
gcvalues_2.background = 0xFFFFFF;
gc_2 = XCreateGC(dsp, win, GCFunction|GCPlaneMask|GCForeground|GCBackground, &gcvalues_2);
XEvent evt;
long eventMask = StructureNotifyMask;
eventMask |= ButtonPressMask|ButtonReleaseMask|KeyPressMask|KeyReleaseMask;
XSelectInput(dsp, win, eventMask);
XMapWindow(dsp, win);
// wait until window appears
do { XNextEvent(dsp,&evt); } while (evt.type != MapNotify);
update_screen();
XDestroyWindow(dsp, win);
XCloseDisplay(dsp);
return 0;
}
void update_screen()
{
int X,Y;
for (X = 0; X < Wnd_X; X++)
for (Y = 0; Y < Wnd_Y; Y++)
{
XDrawPoint(dsp, win, gc_2, X, Y);
usleep(100);
}
return;
}
答案 0 :(得分:2)
您需要刷新X服务器的更新。试试这个:
XDrawPoint(dsp, win, gc_2, X, Y);
XFlush(dsp);
usleep(100);