Zeichnen unter Linux
-
Wie kann ich unter Linux zeichnen?
[edit]ein bisschen für die FAQ verschönert ;)[/edit]
[ Dieser Beitrag wurde am 02.01.2003 um 15:56 Uhr von kingruedi editiert. ]
-
Hi !
Klar, du brauchst nur Clanlib (www.clanlib.org) :
first.h
#include <ClanLib/core.h> #include <ClanLib/display.h> #include <ClanLib/application.h> class CFirst : public CL_ClanApplication { public: CFirst(); ~CFirst(); virtual char *get_title() { return "CFirst"; } virtual int main(int, char **); void render ();
first.cpp
#include "first.h" // This application instance is required or the app will not run CFirst applicationInstance; CFirst::CFirst() {} CFirst::~CFirst(){} int CFirst::main(int, char **) { //CL initialization functions //These must be called or CL functions will not work //Also, SetupCore must be init()'ed first and denit()'ed last CL_SetupCore::init(); CL_SetupDisplay::init(); //Set display mode (not fullscreen) CL_Display::set_videomode(640, 480, 32, false); render (); //CL deinitialization functions //These must be called because CL does not unload itself CL_SetupDisplay::deinit(); CL_SetupCore::deinit(); } void CFirst::render () { while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) { CL_System::keep_alive(); CL_Display::clear_display(0, 0, 0, 1.0f); //zeichnet eine Linie von (0,0) zu (20,23) mit der Farbe rot (1.0,0.0f,0.0f) CL_Display::draw_line(0,0,20,23,1.0f,0.0f,0.0f); CL_Display::flip_display(); } }
-
Linie auf der Konsole zeichnen:
/* lines.c */ # include <stdio.h> # include <vga.h> int main() { if (vga_init()) return(1); if (vga_setmode(G640x480x16)) return(1); vga_clear(); vga_setcolor(15); vga_drawline(0, 0, 639, 479); vga_getch(); return(0); }
Übersetzen mit "gcc lines.c -lvga -o lines" (svgalib muss installiert sein) und z.B. als root ausführen.
Mehr dazu findest du in meinem Buch "C und Linux".
Martin
-
Hallo,
da dieser Thread schon einige Zeit her ist und die vga.h nicht mehr existiert unter Arch Linux, ist die Vorgehensweise von Martin G nicht mehr möglich.
Kennt jemand noch eine Methode um auf der Konsole zu zeichnen ?
-
Bist du sicher, dass die Lib nicht verfügbar ist?
Du benötigst auch das Dev-Paket für die Header (libsvga1-dev).
-
Die Bibliothek ist scheinbar standardmässig schon vorhanden da pacman keine ungelösten Abhängikeiten zeigt bei Spielen die diese Bibliothek benötigen. Doch die Datei vga.h ist nicht vorhanden
In der /usr/include/GL/svgamesa.h ist eine kurze Anleitung dazu ->
* Intro to using the VGA/Mesa interface 29 * 30 * 1. #include the <vga.h> file 31 * 2. Call vga_init() to initialize the SVGA library. 32 * 3. Call vga_setmode() to specify the screen size and color depth. 33 * 4. Call SVGAMesaCreateContext() to setup a Mesa context. If using 8-bit 34 * color Mesa assumes color index mode, if using 16-bit or deeper color 35 * Mesa assumes RGB mode. 36 * 5. Call SVGAMesaMakeCurrent() to activate the Mesa context. 37 * 6. You can now use the Mesa API functions. 38 * 7. Before exiting, call SVGAMesaDestroyContext() then vga_setmode(TEXT) 39 * to restore the original text screen. 40 * 41 * Notes 42 * 1. You must run your executable as root (or use the set UID-bit) because 43 * the SVGA library requires it. 44 * 2. The SVGA driver is not fully implemented yet. See svgamesa.c for what 45 * has to be done yet. 46 */
-
Wie gesagt, du brauchst nicht nur die Bibliothek selbst, sondern auch Header & Co.
-
Das Packet ist unter ArchLinux nicht vorhanden muss quasi per makepkg erstellt und nachinstalliert werden.
-
VGA Man schrieb:
Das Packet ist unter ArchLinux nicht vorhanden muss quasi per makepkg erstellt und nachinstalliert werden.