2016-04-10 3 views
0

次のコードをコンパイルしようとしていますが、以下のエラーメッセージが表示されます。私はLinuxのcグラフィックスの初心者であり、それを理解することはできません。誰もが解決策を提案できますか?Linux Graphics Cプログラムで次のエラーを解決するにはどうすればよいですか?

コード:

#include<stdio.h> 
#include<graphics.h> 
void main() 
{ 
     int gd = DETECT, gm; 
     int dx, dy, p, end; 
     float x1, x2, y1, y2, x, y; 
     initgraph(&gd, &gm,NULL); 
     printf("Enter Value of X1: "); 
     scanf("%f", &x1); 
     printf("Enter Value of Y1: "); 
     scanf("%f", &y1); 
     printf("Enter Value of X2: "); 
     scanf("%f", &x2); 
     printf("Enter Value of Y2: "); 
     scanf("%f", &y2); 

     dx = abs(x1 - x2); 
     dy = abs(y1 - y2); 

     p = 2 * dy - dx; 
     if(x1 > x2) 
     { 
      x = x2; 
      y = y2; 
      end = x1; 
     } 
     else 
     { 
      x = x1; 
      y = y1; 
      end = x2; 
     } 
     putpixel(x, y, 10); 
     while(x < end) 
     { 
      x = x + 1; 
      if(p < 0) 
      { 
        p = p + 2 * dy; 
      } 
      else 
      { 
        y = y + 1; 
        p = p + 2 * (dy - dx); 
      } 
      putpixel(x, y, 10); 
     } 
     getch(); 
     closegraph(); 
} 

エラーメッセージ:

[email protected]:~/libgraph-1.0.2$ ./b 
[xcb] Unknown sequence number while processing queue 
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 
[xcb] Aborting, sorry about that. 
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. 
[xcb] Unknown sequence number while processing queue 
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 
[xcb] Aborting, sorry about that. 
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. 
Aborted (core dumped) 
+0

* graphics.hは単なるヘッダファイルです。あなたが実際に使っているのは* libgraph *です。たぶんあなたはそれを指定するときにもっと答えを得るでしょう。 – tofro

+0

イメージに線を引く場合は、Magick ++を使用できます。これらはあなたがhttps://www.imagemagick.org/Magick++/Image++.htmlとhttp://www.imagemagick.org/Magick++/tutorial/Magick++_tutorial.pdf –

+0

を起動させるかもしれません。もう一つのオプションは 'libvga '、私の答えはこちらhttp://stackoverflow.com/a/36529602/2836621とhttp://www.svgalib.org –

答えて

1

あなたがLinuxのミント上で正常に動作するようですlibsvgaを使用して試すことができます - 私は何の問題もなく、Mac上でVirtualboxの下にミントを走りました。

私は次のパッケージインストール:

sudo apt-get install svgalib-bin libsvga1 libsvga1-dev 

をそして、私は次のようにコードをハッキング:

#include <stdlib.h> 
#include <math.h> 
#include <unistd.h> 
#include <vga.h> 
#include<stdio.h> 

void main() 
{ 
    int dx, dy, p, end; 

    /* detect the chipset and give up supervisor rights */ 
    if (vga_init() < 0) 
     return EXIT_FAILURE; 

    vga_setmode(G1024x768x256); /* some low resolution dont work */ 
    vga_setcolor(14);   /* color of pixel */ 

    float x1, x2, y1, y2, x, y; 
    x1=10; 
    y1=40; 
    x2=800; 
    y2=500; 

    dx = abs(x1 - x2); 
    dy = abs(y1 - y2); 

    p = 2 * dy - dx; 
    if(x1 > x2) 
    { 
     x = x2; 
     y = y2; 
     end = x1; 
    } else { 
     x = x1; 
     y = y1; 
     end = x2; 
    } 
    vga_drawpixel(x, y); 
    while(x < end){ 
     x = x + 1; 
     if(p < 0) 
     { 
     p = p + 2 * dy; 
     } else { 
     y = y + 1; 
     p = p + 2 * (dy - dx); 
     } 
     vga_drawpixel(x, y); 
    } 
    sleep(10); 

    /* restore textmode and fall back to ordinary text console handling */ 
    vga_setmode(TEXT); 

} 

私はこのようにコンパイル:

gcc graphics.c -lvga -lm -o graphics 

として走りました。

sudo ./graphics 

私はこの出力を得ました。色やサイズを変えたい場合は、簡単に数値を変更することができます。

enter image description here

関連する問題