Created
May 9, 2011 13:22
-
-
Save Fab1n/962506 to your computer and use it in GitHub Desktop.
vgalib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================ | |
Name : vgalib.c | |
Author : | |
Version : | |
Copyright : Your copyright notice | |
Description : Hello World in C, Ansi-style | |
============================================================================ | |
*/ | |
#include <stdlib.h> | |
#include <vga.h> | |
struct rect{ | |
int x; //Position rechts | |
int y; //Position oben | |
int width; //Breite | |
int height; //Hoehe | |
int r,g,b; //Farbe | |
}; | |
int drawrect(rect mrec){ | |
int i,j=0; | |
int c=vga_setrgbcolor(0,100,100); | |
//vga_setcolor(c); | |
for(i=mrec.x;i<mrec.x+mrec.width;i++) | |
for(j=mrec.y;j<mrec.y+mrec.height;j++) | |
vga_drawpixel(i, j); | |
return 1; | |
} | |
int main(void) | |
{ | |
int i,j; | |
if(vga_init()) | |
return -1; | |
if(vga_setmode(G640x480x16)) | |
return -1; | |
vga_clear(); | |
rect r1; | |
r1.x=10; | |
r1.y=10; | |
r1.width=100; | |
r1.height=50; | |
r1.r=0; | |
drawrect(r1); | |
//drawrect(120, 10, 100, 50, 16); | |
//drawrect(230, 10, 100, 50, 16); | |
// sleep(5); | |
vga_getch(); | |
vga_setmode(TEXT); | |
return EXIT_SUCCESS; | |
} | |
/* | |
vga_draw.c - SVGALIB-Malprogramm | |
*/ | |
#ifdef NEVER | |
# include <stdio.h> | |
# include <vga.h> | |
# include <vgamouse.h> | |
int main() | |
{ | |
int x, y, x_old, y_old, i, color; | |
static unsigned char background[21][21]; | |
if (vga_getmousetype() == MOUSE_NONE) | |
{ | |
fprintf(stderr, "No mouse configured.\n"); | |
return(1); | |
} | |
if (vga_init()) | |
return(1); | |
vga_setmousesupport(1); /* Maus vorbereiten */ | |
if (vga_setmode(G640x480x16)) | |
return(1); | |
vga_setpalette(0, 24, 48, 60); /* Hellblau */ | |
vga_setpalette(1, 0, 0, 0); /* Schwarz */ | |
vga_clear(); | |
for (i=0; i<448; i++) /* Palette zeichnen */ | |
{ | |
vga_setcolor(1+i/32); | |
vga_drawline(0, i, 32, i); | |
} | |
vga_setcolor(1); /* Box mit aktueller Farbe */ | |
vga_drawline(1, 478, 1, 449); | |
vga_drawline(1, 478, 31, 478); | |
vga_drawline(31, 478, 31, 449); | |
vga_drawline(1, 449, 31, 449); | |
color = 5; /* aktuelle Farbe */ | |
vga_setcolor(color); | |
for (i=451; i<477; i++) | |
vga_drawline(3, i, 29, i); | |
x = x_old = 320; /* Startkoordinaten */ | |
y = y_old = 240; | |
mouse_setposition(x, y); /* Maus einstellen */ | |
mouse_setxrange(10, 629); | |
mouse_setyrange(10, 469); | |
mouse_setscale(32); | |
for (i=0; i<21; i++) | |
vga_getscansegment(background[i], | |
x-10, y-10+i, 21); | |
vga_setcolor(1); | |
vga_drawline(x-10, y, x+10, y); | |
vga_drawline(x, y-10, x, y+10); | |
do | |
{ | |
mouse_waitforupdate(); | |
for (i=0; i<21; i++) | |
vga_drawscansegment(background[i], | |
x-10, y-10+i, 21); | |
x = mouse_getx(); | |
y = mouse_gety(); | |
if (mouse_getbutton() == MOUSE_LEFTBUTTON) | |
{ | |
if (x > 32) /* Zeichenflaeche */ | |
{ | |
vga_setcolor(color); | |
vga_drawline(x_old, y_old, x, y); | |
x_old = x; | |
y_old = y; | |
} | |
else /* Farbauswahl */ | |
{ | |
color = y/32+1; | |
vga_setcolor(color); | |
for (i=451; i<477; i++) | |
vga_drawline(3, i, 29, i); | |
} | |
} | |
else | |
{ | |
x_old = x; | |
y_old = y; | |
} | |
for (i=0; i<21; i++) | |
vga_getscansegment(background[i], | |
x-10, y-10+i, 21); | |
vga_setcolor(1); | |
vga_drawline(x-10, y, x+10, y); | |
vga_drawline(x, y-10, x, y+10); | |
} | |
while (mouse_getbutton() != MOUSE_RIGHTBUTTON); | |
return(0); | |
} | |
/* | |
vgagl_demo.c - komplexere Grafik mit der LIBVGAGL | |
*/ | |
#include <stdio.h> | |
#include <vga.h> | |
#include <vgagl.h> | |
#include "DLabel.h" | |
int main() | |
{ | |
int mode; | |
GraphicsContext gc; | |
DLabel label; | |
if (vga_init()) | |
return(1); | |
mode = G640x480x16; | |
if (vga_setmode(mode)) | |
return(1); | |
gl_setcontextvga(mode); | |
gl_getcontext(&gc); /* GraphicsContext holen */ | |
vga_setpalette(0, 58, 58, 58); | |
vga_clear(); | |
gl_setcontextvgavirtual(mode); | |
label.draw(); | |
#ifdef NEVER | |
gl_setfont(8, 8, gl_font8x8); /* Text vorbereiten */ | |
gl_setwritemode(FONT_COMPRESSED | |
| WRITEMODE_OVERWRITE); | |
gl_setfontcolors(15, 1); | |
gl_write(10, 10, "Dies ist ein Test."); | |
gl_printf(10, 20, "Breite=%d", vga_getxdim()); | |
#endif | |
gl_circle(320, 240, 100, 1); | |
gl_fillbox(10, 400, 100, 70, 5); | |
gl_copyscreen(&gc); /* Grafik ins Video-RAM */ | |
vga_getch(); /* auf Taste warten */ | |
return(0); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment