- Registriert
- 15.11.06
- Beiträge
- 20
moin!
brauche zwecks studium ein x11 window unter c++, sprich ich möchte bestimmte simulationen in c++ über ein x11 window grafisch darstellen. in der vorlesung wurde uns ein c++-programm bereitgestellt, ist aber für linux konzipiert. wenn ich es unter mac (os 10.3.9) laufen lasse (x11 ist installiert und läuft soweit fehlerfrei), gibt er mir folgende fehlermeldung (sonst keine weiteren):
ld: Undefined symbols:
_main
_XCheckTypedEvent
_XClearWindow
_XCloseDisplay
_XCreateGC
_XCreateSimpleWindow
_XDestroyWindow
_XDrawLine
_XDrawPoint
_XFreeGC
_XLookupString
_XMapRaised
_XNextEvent
_XOpenDisplay
_XSelectInput
_XSetBackground
_XSetForeground
_XSetStandardProperties
___gxx_personality_v0
was muss ich ändern, damit es funktioniert?? oder hat jemand einen anderen code??
hier dass uns bereitgestellte programm:
//*****************************************************************************
// Simple graphics interface for X11 Windows, by Haye Hinrichsen
//*****************************************************************************
#ifdef HAYE_WINDOWS
#else
#define HAYE_WINDOWS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
class XWindow
{
private:
Display *display; // Display handler
Window window; // Window handler
GC gc,gc2; // device context
XEvent event; // event flag
KeySym key;
char PressedKey, KeyIsPressed; // keypress flag
XSizeHints hint;
int screen, sizex, sizey, ypos;
unsigned long foreground, background;
public:
XWindow (void); // Konstruktor
// Farbtabelle RGB:
void Red (void) { XSetForeground(display, gc, 0xFF0000L); }
void Yellow (void) { XSetForeground(display, gc, 0xFFFF00L); }
void Green (void) { XSetForeground(display, gc, 0x00FF00L); }
void Blue (void) { XSetForeground(display, gc, 0x0000FFL); }
void Violet (void) { XSetForeground(display, gc, 0xFF00FFL); }
void Black (void) { XSetForeground(display, gc, 0x000000L); }
void White (void) { XSetForeground(display, gc, 0xFFFFFFL); }
void Open (int x=600, int y=400, char* title = "Simulation");
void Close(void);
void Clear (void) { XClearWindow(display, window); ypos=0; }
void Plot (int x, int y);
void Plot (int x, int y, int c);
void DrawLine (int x1, int y1, int x2, int y2);
void SetColor(double c);
void PlotState (int state[], int size, int xshift=0);
void PlotColorState (int state[], int size, int xshift=0);
void DecreaseYcoord (void) { ypos--; }
bool KeyPressed (void);
char GetCharacter (void) { KeyIsPressed=0; return (PressedKey); }
int GetX (void) { return sizex; }
int GetY (void) { return sizey; }
char WaitForKeypress (void) { while (! KeyPressed()); return GetCharacter(); }
void Wait (void) { while (! KeyPressed()); GetCharacter(); }
};
/////////////////// DEFINITION OF VARIOUS FUNCTIONS //////////////////////////
//-------------------------------Constructor---------------------------------
XWindow::XWindow (void)
{ PressedKey=0, KeyIsPressed=0; ypos=0; }
//-------------------------------Open Window---------------------------------
void XWindow::Open (int x, int y, char* title)
{
sizex = x; sizey = y;
display = XOpenDisplay("");
if(! display)
{
printf("### Error: Failed to open display !###\n");
exit(1);
}
screen = DefaultScreen(display);
background = WhitePixel(display, screen);
foreground = BlackPixel(display, screen);
hint.x = 200;
hint.y = 300;
hint.width = x;
hint.height = y;
hint.flags = PPosition | PSize;
window = XCreateSimpleWindow(display, DefaultRootWindow(display),
hint.x, hint.y, hint.width, hint.height,
5, foreground, background);
XSetStandardProperties(display, window, title, title, None, 0, 0,
&hint);
gc=XCreateGC(display, window, 0, 0);
gc2=XCreateGC(display, window, 0, 0);
XSetBackground(display, gc, background);
XSetForeground(display, gc, foreground);
XSetBackground(display, gc2, foreground);
XSetForeground(display, gc2, background);
XSelectInput(display, window, ButtonPressMask | KeyPressMask | ExposureMask);
XMapRaised(display, window);
XNextEvent(display, &event);
}
//-------------------------------------Plot-----------------------------------
void XWindow:lot (int x, int y)
{XDrawPoint(display, window, gc, x, y);}
void XWindow:lot (int x, int y, int c)
{if (c) XDrawPoint(display, window, gc, x, y);
else XDrawPoint(display, window, gc2, x, y);}
//-------------------------------------Line-----------------------------------
void XWindow:rawLine (int x1, int y1, int x2, int y2)
{XDrawLine(display, window, gc, x1, y1, x2, y2);}
//-----------------------------------PlotState--------------------------------
void XWindow:lotState (int state[], int size, int xshift)
{
if (ypos>=sizey) { Clear(); ypos=0; };
int x; for (x=0;x<sizex;x++) if (state[x]>0) Plot(xshift+x,ypos); ypos++;
}
void XWindow:lotColorState (int state[], int size, int xshift)
{
if (ypos>=sizey) { Clear(); ypos=0; };
int x; for (x=0;x<sizex;x++) if (state[x]>0)
{ SetColor((double)state[x]/2); Plot(xshift+x,ypos);} ypos++;
}
//-----------------------------------Close Window-----------------------------
void XWindow::Close()
{
XFreeGC(display, gc);
XDestroyWindow(display, window);
XCloseDisplay(display);
}
//----------------------------------- Set Color -----------------------------
void XWindow::SetColor(double c)
{
double c1=c-floor(c);
double c2=c1+1.0/3-floor(c1+1.0/3);
double c3=c2+1.0/3-floor(c2+1.0/3);
int r = 255-(c1<0.5 ? (int)(512*c1) : 511-(int)(512*c1));
int g = 255-(c2<0.5 ? (int)(512*c2) : 511-(int)(512*c2));
int b = 255-(c3<0.5 ? (int)(512*c3) : 511-(int)(512*c3));
XSetForeground(display, gc, r<<16 | g<<8 | b);
}
// void XWindow::SetColor(double c)
// {
// double c1=c-floor(c);
// double c2=c1+1.0/3; c2-=floor(c2);
// double c3=c2+1.0/3; c3-=floor(c3);
// int r = 31-(c1<0.5 ? (int)(64*c1) : 63-(int)(64*c1));
// int g = 31-(c2<0.5 ? (int)(64*c2) : 63-(int)(64*c2));
// int b = 31-(c3<0.5 ? (int)(64*c3) : 63-(int)(64*c3));
// XSetForeground(display, gc, r<<11 | g<<6 | b);
// }
//------------------------------ Software for keypresses----------------------
bool XWindow::KeyPressed (void)
{
if (KeyIsPressed) return 1;
if (! XCheckTypedEvent(display,KeyPress,&event)) return 0;
int i; char text[10];
i=XLookupString((XKeyEvent *) &event, text, 10, &key, 0);
if (i!=1) return 0;
PressedKey=text[0]; KeyIsPressed=1;
return 1;
}
//////////////////////////////////////////////////////////////////////////////
#endif
brauche zwecks studium ein x11 window unter c++, sprich ich möchte bestimmte simulationen in c++ über ein x11 window grafisch darstellen. in der vorlesung wurde uns ein c++-programm bereitgestellt, ist aber für linux konzipiert. wenn ich es unter mac (os 10.3.9) laufen lasse (x11 ist installiert und läuft soweit fehlerfrei), gibt er mir folgende fehlermeldung (sonst keine weiteren):
ld: Undefined symbols:
_main
_XCheckTypedEvent
_XClearWindow
_XCloseDisplay
_XCreateGC
_XCreateSimpleWindow
_XDestroyWindow
_XDrawLine
_XDrawPoint
_XFreeGC
_XLookupString
_XMapRaised
_XNextEvent
_XOpenDisplay
_XSelectInput
_XSetBackground
_XSetForeground
_XSetStandardProperties
___gxx_personality_v0
was muss ich ändern, damit es funktioniert?? oder hat jemand einen anderen code??
hier dass uns bereitgestellte programm:
//*****************************************************************************
// Simple graphics interface for X11 Windows, by Haye Hinrichsen
//*****************************************************************************
#ifdef HAYE_WINDOWS
#else
#define HAYE_WINDOWS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
class XWindow
{
private:
Display *display; // Display handler
Window window; // Window handler
GC gc,gc2; // device context
XEvent event; // event flag
KeySym key;
char PressedKey, KeyIsPressed; // keypress flag
XSizeHints hint;
int screen, sizex, sizey, ypos;
unsigned long foreground, background;
public:
XWindow (void); // Konstruktor
// Farbtabelle RGB:
void Red (void) { XSetForeground(display, gc, 0xFF0000L); }
void Yellow (void) { XSetForeground(display, gc, 0xFFFF00L); }
void Green (void) { XSetForeground(display, gc, 0x00FF00L); }
void Blue (void) { XSetForeground(display, gc, 0x0000FFL); }
void Violet (void) { XSetForeground(display, gc, 0xFF00FFL); }
void Black (void) { XSetForeground(display, gc, 0x000000L); }
void White (void) { XSetForeground(display, gc, 0xFFFFFFL); }
void Open (int x=600, int y=400, char* title = "Simulation");
void Close(void);
void Clear (void) { XClearWindow(display, window); ypos=0; }
void Plot (int x, int y);
void Plot (int x, int y, int c);
void DrawLine (int x1, int y1, int x2, int y2);
void SetColor(double c);
void PlotState (int state[], int size, int xshift=0);
void PlotColorState (int state[], int size, int xshift=0);
void DecreaseYcoord (void) { ypos--; }
bool KeyPressed (void);
char GetCharacter (void) { KeyIsPressed=0; return (PressedKey); }
int GetX (void) { return sizex; }
int GetY (void) { return sizey; }
char WaitForKeypress (void) { while (! KeyPressed()); return GetCharacter(); }
void Wait (void) { while (! KeyPressed()); GetCharacter(); }
};
/////////////////// DEFINITION OF VARIOUS FUNCTIONS //////////////////////////
//-------------------------------Constructor---------------------------------
XWindow::XWindow (void)
{ PressedKey=0, KeyIsPressed=0; ypos=0; }
//-------------------------------Open Window---------------------------------
void XWindow::Open (int x, int y, char* title)
{
sizex = x; sizey = y;
display = XOpenDisplay("");
if(! display)
{
printf("### Error: Failed to open display !###\n");
exit(1);
}
screen = DefaultScreen(display);
background = WhitePixel(display, screen);
foreground = BlackPixel(display, screen);
hint.x = 200;
hint.y = 300;
hint.width = x;
hint.height = y;
hint.flags = PPosition | PSize;
window = XCreateSimpleWindow(display, DefaultRootWindow(display),
hint.x, hint.y, hint.width, hint.height,
5, foreground, background);
XSetStandardProperties(display, window, title, title, None, 0, 0,
&hint);
gc=XCreateGC(display, window, 0, 0);
gc2=XCreateGC(display, window, 0, 0);
XSetBackground(display, gc, background);
XSetForeground(display, gc, foreground);
XSetBackground(display, gc2, foreground);
XSetForeground(display, gc2, background);
XSelectInput(display, window, ButtonPressMask | KeyPressMask | ExposureMask);
XMapRaised(display, window);
XNextEvent(display, &event);
}
//-------------------------------------Plot-----------------------------------
void XWindow:lot (int x, int y)
{XDrawPoint(display, window, gc, x, y);}
void XWindow:lot (int x, int y, int c)
{if (c) XDrawPoint(display, window, gc, x, y);
else XDrawPoint(display, window, gc2, x, y);}
//-------------------------------------Line-----------------------------------
void XWindow:rawLine (int x1, int y1, int x2, int y2)
{XDrawLine(display, window, gc, x1, y1, x2, y2);}
//-----------------------------------PlotState--------------------------------
void XWindow:lotState (int state[], int size, int xshift)
{
if (ypos>=sizey) { Clear(); ypos=0; };
int x; for (x=0;x<sizex;x++) if (state[x]>0) Plot(xshift+x,ypos); ypos++;
}
void XWindow:lotColorState (int state[], int size, int xshift)
{
if (ypos>=sizey) { Clear(); ypos=0; };
int x; for (x=0;x<sizex;x++) if (state[x]>0)
{ SetColor((double)state[x]/2); Plot(xshift+x,ypos);} ypos++;
}
//-----------------------------------Close Window-----------------------------
void XWindow::Close()
{
XFreeGC(display, gc);
XDestroyWindow(display, window);
XCloseDisplay(display);
}
//----------------------------------- Set Color -----------------------------
void XWindow::SetColor(double c)
{
double c1=c-floor(c);
double c2=c1+1.0/3-floor(c1+1.0/3);
double c3=c2+1.0/3-floor(c2+1.0/3);
int r = 255-(c1<0.5 ? (int)(512*c1) : 511-(int)(512*c1));
int g = 255-(c2<0.5 ? (int)(512*c2) : 511-(int)(512*c2));
int b = 255-(c3<0.5 ? (int)(512*c3) : 511-(int)(512*c3));
XSetForeground(display, gc, r<<16 | g<<8 | b);
}
// void XWindow::SetColor(double c)
// {
// double c1=c-floor(c);
// double c2=c1+1.0/3; c2-=floor(c2);
// double c3=c2+1.0/3; c3-=floor(c3);
// int r = 31-(c1<0.5 ? (int)(64*c1) : 63-(int)(64*c1));
// int g = 31-(c2<0.5 ? (int)(64*c2) : 63-(int)(64*c2));
// int b = 31-(c3<0.5 ? (int)(64*c3) : 63-(int)(64*c3));
// XSetForeground(display, gc, r<<11 | g<<6 | b);
// }
//------------------------------ Software for keypresses----------------------
bool XWindow::KeyPressed (void)
{
if (KeyIsPressed) return 1;
if (! XCheckTypedEvent(display,KeyPress,&event)) return 0;
int i; char text[10];
i=XLookupString((XKeyEvent *) &event, text, 10, &key, 0);
if (i!=1) return 0;
PressedKey=text[0]; KeyIsPressed=1;
return 1;
}
//////////////////////////////////////////////////////////////////////////////
#endif