PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Grafikprogrammierung unter Linux 7.2



Crush
21-08-2001, 12:35
Ich habe folgendes Problem. Ich muss für mein Studium eine grafische Oberfläche für ein C-Programm schreiben. Dafür hat unser Prof. uns ein Beispiel-Programm gegeben, welches angeblich unter Linux funktionieren soll. Wenn ich dieses aber jetzt compiliere, wird die ausführbare Datei ohne Probleme erstellt. Nur wenn ich diese dann ausführe, erhalte ich folgende Fehlermeldung und das Grafikfenster blinkt nur einmal kurz auf.

X Error of failed request: Bad Match (invalid parameter attributes)
Major opcode of failed request: 70 (X_PolyFillRectangle)
Serial Number of failed request: 38
Current serial number in output stream: 219

Wer kann mir da weiterhelfen???

MFG
Crush

jgbauman
21-08-2001, 12:43
Ohne Quellcode wird´s schwierig dir zu helfen.

Crush
21-08-2001, 13:11
Den Quellcode könntest du bekommen. Aber ich befürchte bald, dass es am Object-Code liegt. Und da habe ich nur die compilierte Form von. Aber wenn du mir weiterhelfen kannst oder willst, kann ich dir das Beispiel wohl zuschicken.

Crush

iGEL
21-08-2001, 18:39
Moin!

Zwar Offtopic, aber muss mal gesagt werden: Linux 7.2 gibts nicht, und wird auch noch etwas dauern. Gerade ist Linux 2.4 aktuell. Du meinst wahrscheinlich SuSE 7.2. :)

cu Johannes

PS: Poste deinen Code hier mal am besten, dann kann man dir bestimmt besser helfen. Und am besten auch, wie du den Compiler aufgerufen hast.

[ 21. August 2001: Beitrag editiert von: iGEL ]

jgbauman
21-08-2001, 22:39
meine mail-Adresse steht im Profl

Crush
22-08-2001, 08:16
So, jetzt noch mal den Quellcode!


Die main-Funktion(graph_test.c):

/*Funktion : int graph_test (void)
Test der Graphikfunktionen */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "xgraph.h"

int main (void)
{
int
i,j,n_col=16,
x_win0 = 100, y_win0 = 100, b_win0 = 400, h_win0 = 350,
x1_win = 100, y1_win = 180,
b1_win = 200, h1_win = 50,
rand,chrb;
int
x1,x2,y1,y2,
xr,yr,br,hr;
int
col_win = 15,
col_rand = 3,
col_text = 0,
col_line = 5;
char c;
char str2[] = {"FH Osnabrueck"};
char str1[] = {"Semester 2b"};
char buf[15];
MouseKey mk;
GraphMeasure gm;

ini_graph (x_win0,y_win0,b_win0,h_win0); /* Graphik initialsieren */
gm = get_graph_measure();
chrb = gm.font_w;
rand = chrb/2;

xr = 50; yr = 150; br = 200; hr = 150;
FillRectangle (xr,yr,br,hr,col_rand);
xr += rand; yr += rand; br -= 2*rand; hr -= 2*rand;
DrawRectangle (xr,yr,br,hr,col_win);
DrawString (str1,xr+rand,yr,col_text);

x1 = 150; y1 = 200;
for (i = 0; i < n_col; i++) {
for (j = 0; j < 5; j++) {
DrawPoint (x1+j, y1, i);
}
x1 += 5; y1 += 5;
}
if (read_char() == 'q') return 1;

def_win (x1_win,y1_win,b1_win,h1_win); /* Fenster anlegen */
FillRectangle (0,0,b1_win,h1_win,col_win);
xr = rand; yr = rand; br = b1_win - 2*rand; hr = h1_win-2*rand;
DrawRectangle (xr,yr,br,hr,col_rand);

x1 = 3*rand; y1 = xr+2*rand;
DrawString (str2,x1,y1,col_text);

x2 = x1 + strlen(str2) * chrb; y2 = y1;
y1 = y1 - rand;
DrawLine (x1,y1,x2,y1,col_line);

y1 = y1 + 20;
DrawString ((char *)("Fenster (b,h):"), x1,y1,col_line);
gm = get_graph_measure();
sprintf (buf, "%d", gm.win_b);
x2 = sizeof(buf);
DrawString (buf,x1+x2*chrb,y1,col_line);

sprintf (buf, "%d", gm.win_h);
DrawString (buf,x1+(x2+4)*chrb,y1,col_line);

if (read_char() == 'q') return 1;
close_win(1); /* Fenster schliessen */

i = 3;
do {
mk = read_mouse();
x1 = mk.x; y1 = mk.y;
DrawString ((char *)("FH"),x1,y1,col_line);
i--;
} while (i > 0);
if (read_char() == 'q') return 1;

i = 3;
do {
c = read_char();
mk = read_mouse();
x1 = mk.x; y1 = mk.y;
pl_h_char (c,x1,y1,col_line);
i--;
} while (i > 0);
read_char();

close_graph (); /* Graphik schliessen */
return 1;
}

Der Makefile:

# Makefile fuer xgraph_test.c
#


NAME = t

all : $(NAME)

INCLUDE = -I/usr/X11R6/include
LIBPATH = -L/usr/X11R6/lib
LIBS = -lX11 -lm lib_xgraph
CFLAGS = -Wall -ansi -Wstrict-prototypes
COMP = g++

OBJS = graph_test.o xgraph_l.o
#OBJS = graph_test.o

.c.o:
$(COMP) $(CFLAGS) $(INCLUDE) -c -o $*.o $<

$(NAME): $(OBJS)
$(COMP) -o $(NAME) $(OBJS) $(LIBPATH) $(LIBS)

graph_test.o : graph_test.c xgraph.h
#xgraph.o : xgraph.c xgraph.h

clean :
rm -f *.o $(NAME) core *.ps *.bak *~ $(NAME)

lib:
ar rv lib_xgraph xgraph_l.o

Die xgraph.h:

/*
Datei : xgraph.h
Aufgabe : Headerdatei fuer xgraph.c
Funktionsprototypen, bauen auf X - Grafikroutinen auf

Anmerkung : Nullpunkt fuer ini_graph oben links im Display,
fuer alle anderen Routinen unten links im Fenster

*/

/*---- Tastenbezeichnungen Sondertasten -----------------------------*/

#define K_BackSpace 127 /* Backspace vga: 127 */
#define K_Return 10 /* Returntaste: 10 */
#define K_Escape 27 /* Escapetaste: 27 */
#define K_Up 65 /* Cursortasten */
#define K_Down 66
#define K_Left 67
#define K_Right 68

/*-------------------------------------------------------------------*/
/* Funktionsprototypen der Funktionen der Datei */
/*-------------------------------------------------------------------*/

typedef struct {
char
type, /* k: Taste, m: Maus, e: expose*/
c; /* Tastencharacter */
int x,y; /* Mauslage */
} MouseKey;

typedef struct {
int font_w,font_h; /* FontMaße Breite, Hoehe */
int win_b, win_h; /* Maße des mom. Fensters */
} GraphMeasure;

void ini_graph (int x0, int y0, int b_win, int h_win);
void close_graph (void);
int def_win (int x_win, int y_win, int b_win, int h_win);
void close_win (int);
void clear_screen (void);
MouseKey read_mouse_key (void);
MouseKey read_mouse (void);
char read_char (void);
GraphMeasure get_graph_measure (void);
void cross (int x1, int y1, int color);
void pl_h_char (char zeichen, int xpos, int ypos, int col);
void poligon_line (int it[], int ix[], int np, int col);

void FillRectangle (int x1, int y1, int x2, int y2, int color);
void DrawLine (int x1, int y1, int x2, int y2, int color);
void DrawString (char *string, int xpos, int ypos, int col);
void DrawRectangle (int x1, int y1, int x2, int y2, int color);
void DrawPoint (int x, int y, int col);

/* ************************************************** *****************/

#if 0

/************************************************** *******************/
/* */
/* Funktion: ini_graph (int x0, int y0, int b_win, int h_win) */
/* Aufgabe: Grafikmodus einschalten, Farben erzeugen, ... */
/* Eingabe: x0, y0 : Fensterlage, Nullpunkt oben links */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: FontMeasure get_graph_measure (void) */
/* Aufgabe: Rueckgabe der Fontmasse Breite, Hoehe */
/* Rueckgabe der Fenstermassee des momentanen Fensters */
/* Eingabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: close_graph () */
/* Aufgabe: Grafikmodus schliessen, zum Textmodus zurueckkehren */
/* Eingabe: keine */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: clear_screen () */
/* Aufgabe: Bildschirm loeschen */
/* Eingabe: keine */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: def_win () */
/* Aufgabe: Ausgabe eines Windows */
/* Eingabe: xmin, ymin, xmax, ymax Koordinaten */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/
/************************************************** *******************/
/* */
/* Funktion: close_win (int r) */
/* Aufgabe: schliesst das zuletzt geoeffnete Window */
/* Eingabe: int r, wenn r = 1, Fenster schliessen */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: read_mouse_key () */
/* Aufgabe: liest ein char von der Tastatur und gibt es zurueck */
/* oder liest Mauslage und gibt Struktur zurueck */
/* Eingabe: - */
/* Rueckgabe: struct Maustaste */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: read_char () */
/* Aufgabe: liest ein char von der Tastatur und gibt es zurueck */
/* Eingabe: - */
/* Rueckgabe: Tastatur - char */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: read_mouse () */
/* Aufgabe: liest Mausklick und gibt Lage der Maus zurueck */
/* Eingabe: - */
/* Rueckgabe: Struktur MausTaste */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: void FillRrectangle () */
/* Aufgabe: Ausgabe eines Rechtecks in Farbe color */
/* Eingabe: x1, y1, rb, rh Lage/Hoehe */
/* color - Textfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: DrawLine () */
/* Aufgabe: Zeichnen einer Verb. von x1,y1 nach x2,y2, Farbe color */
/* Eingabe: x1, y1 - Koordinaten Anfangspunkt */
/* x2, y2 - Koordinaten Endpunkt */
/* color - Linienfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: DrawPoint () */
/* Aufgabe: Zeichnen einer Verb. von x1,y1 nach x2,y2, Farbe color */
/* Eingabe: x, y - Koordinaten des Punktes */
/* color - Punktfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* Funktion; DrawString() */
/* Aufgabe: Ausgabe eines Strings in der Farbe color */
/* Eingabe: zstring[] Auszugebender String */
/* xpos, ypos Koordinaten */
/* color Textfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: DrawRectangle () */
/* Aufgabe: Zeichnet ein Rechteck mit mit dem Eckpunkt (x0,y0) und */
/* und der Breit / Hoehe rb, rh in der Farbe color. */
/* Eingabe: x0, y0 untere linker Eckpunkt */
/* rb, rk Breite / Hoehe */
/* color Linienfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: cross () */
/* Aufgabe: Ausgabe eines x mit Hoehe gleich Breite in Farbe color */
/* Eingabe: x1, y1 Mittelpunkt */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: pl_h_char () */
/* Aufgabe: Ausgabe eines Zeichens an der Stelle x,y, Farbe color */
/* Eingabe: x, y Koordinaten */
/* CHAR Auszugebendes Zeichen */
/* color Textfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

/************************************************** *******************/
/* */
/* Funktion: poligon_line () */
/* Aufgabe: Zeichnen eines Linienzuges in der Farbe color */
/* Eingabe: it[] Array der Zeitwerte */
/* ix[] Array der Funktionswerte */
/* np Anzahl der Wertepaare */
/* color Linienfarbe */
/* Rueckgabe: keine */
/* */
/************************************************** *******************/

#endif


Und ausserdem ist da noch der Objectcode xgraph_l.o und die lib_xgraph. Aber davon habe ich den Quellcode nicht. Oder kann man das irgendwie zurückcompilieren?


Crush

jgbauman
22-08-2001, 13:51
Die "Grafik-Bibliothek" ist etwas unflexibel.
Es laeft nur mit einem X-Server im 8-bit Modus.
Falls dein X-Server passend konfigueriert und XFree 4.0 ist, koennte ein

startx -- -fbbpp 8

Zum Starten von X von der Linux-Konsole aus reichen.
Dann sollte es funktionieren ;-)

Crush
22-08-2001, 14:20
Danke, ich werde das mal ausprobieren. Auch wenn sich das im Moment für mich noch ein bisschen spanisch anhört, weil ich noch nicht so lange mit Linux arbeite.

Gruss

Crush

Crush
23-08-2001, 07:52
Tja, hat noch nicht funktioniert. Aber wenn ich den X-Server einstelle, wie auch immer, dann funktioniert das?

jgbauman
23-08-2001, 10:42
Wenn der X-Server auf 8 bit Farbtiefe steht, dann funktionierts (bei mir) ;-)