Pascal Graphics


Home

About the Author

General Programming

Pascal

Delphi

C&C++

Visual Basic

SQL

JAVA Script

Links

 

Pascal Tutor ] [ Pascal Graphics ] Pascal Math ] Pascal Misc ]

  1. How to load 320 X 200, 256 color PCX Images
  2. How to link graphics drivers directly an executable
  3. How to initialize graphics with out BGI files
  4. Assembler pixel functions
  5. Assembler line procedure

Any questions send them to pascalgrph@teentwo.8m.com


1. How to load 320 X 200, 256 color PCX Images:

To load a PCX you will need the SPX UNITS(you can find then in our download menu) You will also need to install a 256 color user bgi driver, the bgi file (bgi256.bgi) is included with the SPX UNITS.
To install a userdriver type Graphicsdriver := InstallUserdriver('BGI256',Nil');.
To load the pcx you must type LoadPcx('TEEN2.PCX'); and FSetColors(RGB256);.
FSetColors(RGB256) changes the current pallet to that of the image. RGB256 is of type RGBlist that stores the pallet and it is already declared in the SPX_VGA unit.

EXAMPLE:

Uses
   Spx_Vga,Spx_Img,GRaph;


Var
   GraphicsDriver,GraphicsMode:Integer;


Begin
   Graphicsdriver := InstallUserdriver('BGI256',Nil');
   OpenMode(3);    {Creates 3 dynamic pages in the memory}
   InitGraph(GraphicsDriver,GraphicsMode,'');
   LoadPCX('TEEN2.PCX');
   FsetColors(RGB256);
end.


PS! DO NOT DRAW THE PCX IN WINDOWS PAINT, it does not store it in the correct size. Use a program witch gives you a specific resize option.

Click here to download the spx libraries, spx.zip

Any questions send them to pascalgrph@teentwo.8m.com


2. How to link graphics drivers directly an executable.

To do this you will need BINOBJ.EXE. It comes with TP 7, and it's a program that translates a file so that TP's compiler can use it.
At the command prompt just type BINOBJ <file to use> <out file> <name to use in program>
ex. BINOBJ EGAVGA.BGI EGAVGA.OBJ EGAVGA

Now that you have created the object file you link it to your program like this
Procedure egavga;external;
{$L egavga.OBJ}

Now if you compile the program the object file will be included.

EXAMPLE:

Program NoBgi;

Uses
   Graph;

Procedure egavga;external;
{$L egavga.OBJ}

VAR
   GD,GM:integer;

Begin
   RegisterBGIdriver(@EGAVGA);
   Gd:=Detect;
   InitGraph(gd,gm,'');
   CloseGraph;
end.

REGISTERBGIDRIVER if a function and sends a value back. If this value is larger than 0 the file has not been linked correctly.

Font files can also be linked like this to your program. Instead of typing REGISTERBGIDRIVER you must type REGISTERBGIFONT(@X);

You can also use this to link assembler programs to your TP program. You can then use the procedures in the assembler program.
ex. procedure SetMode(Mode: Word); external;
{$L CURSOR.OBJ}

Any questions send them to pascalgrph@teentwo.8m.com


3. How to initialize grphics with out BGI files

This proceure initializes 320X200 256color graphics.

Procedure VideoMode(Mode: Byte); Assembler;
   Asm
   xor ah,ah
   mov al,Mode
   int 10h
end;

To use simply type VideoMode($13); to initilazi graphics and VideoMode($3) to return to textmode.

Any questions send them to pascalgrph@teentwo.8m.com


4. Assembler pixel fnctions

Procedure Putpixel (X,Y : Integer; Col : Byte);
begin
    Mem [VGA:X+(Y*320)]:=Col;
end;

This procedure will work in both 640X480 and 320X200 video modes.

Any questions send them to pascalgrph@teentwo.8m.com


5. Assembler line procedure

Procedure line(a,b,c,d,col:integer);

Function sgn(a:real):integer;
begin
    if a>0 then sgn:=+1;
    if a<0 then sgn:=-1;
    if a=0 then sgn:=0;
end;

var
    u,s,v,d1x,d1y,d2x,d2y,m,n:real;
    i:integer;

begin
    u:= c - a;
    v:= d - b;
    d1x:= SGN(u);
    d1y:= SGN(v);
    d2x:= SGN(u);
    d2y:= 0;
    m:= ABS(u);
    n := ABS(v);
    if not (M>N) then
    begin
       d2x := 0 ;
       d2y := SGN(v);
       m := ABS(v);
       n := ABS(u);
   end;
   s := INT(m / 2);
   for i := 0 to round(m) do
   begin
      putpixel(a,b,col);
      s := s + n;
      if not (s<m) THEN
      begin
         s := s - m;
         a:= a +round(d1x);
         b := b + round(d1y);
      end
      else
      begin
         a := a + round(d2x);
         b := b + round(d2y);
      end;
   end;
end;

You can use this procedure to create other proccedures like bar.

Any questions send them to pascalgrph@teentwo.8m.com

Pascal Tutor ] [ Pascal Graphics ] Pascal Math ] Pascal Misc ]

Link of the week 
http://www.cpp-
programming.
com/
Newsgroups
comp.lang.c
comp.lang.c++
comp.programming

This page is best viewed in 800x600x256. This page was last edited Tuesday, June 27, 2000

1