Link to home
Start Free TrialLog in
Avatar of Chaitanya021797
Chaitanya021797

asked on

How to maka characters dim?

How to make characters that are already displayed on the screen
to diminish continuously till they become invisible as is
done in games software (eg: Apogee's Hocus Pocus,Optik's Xixit ?
 Please tell me how i can do it using function or interrups availble in borland C.how do i use rbg contents and reduse the color(I mean which function available does it?)
I am using dos and I have all libraries provided by bc
ASKER CERTIFIED SOLUTION
Avatar of ansgar
ansgar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chaitanya021797
Chaitanya021797

ASKER

Edited text of question
Unfortunately, I stopped programming in Borland C two years ago.
Nevertheless, I want to help you !
I dug up some old sources and realized that I had been using the bgi library for 16 color and the SVGA library for 256 colors. A fading as you would want it is probably nicer to do with 256 colors. I also did some direct BIOS programming, which is faster but riskier and you can only set pixels ! I could send you the BIOS functions, and also search the SVGA library on the Borland WWW page.

Are you programming this under DOS ? Which gfx library are you using ? If you want to do this under Win, I cannot help you specifically, since I have never done any Win programming.

I have done this palette fading before, but its no use if I send you the code if you don't have the library to go with it.

Edited text of question
svga library:

-------------- svgalib.h --------------------
#include <graphics.h>
#include <process.h>
#include "d:\BORLANDC\BGI\VGAPALET.C"

int init_svga(int mode);
int outit_svga(void);
void getvgapalette16(DacPalette16 *PalBuf);
void getvgapalette256(DacPalette256 *PalBuf);
void setvgapalette16(DacPalette16 *PalBuf);
void setvgapalette256(DacPalette256 *PalBuf);

-----------------------------------------------

---------- svgalib.c --------------------------
#include "svgalib.h"

int init_svga(int gmode)
{
        int gdriver;

        gdriver = installuserdriver("SVGA256",0);
        initgraph(&gdriver,&gmode,"d:\\borlandc\\bgi\\");

        if (graphresult()!=grOk)
                exit(1);

        return 0;
}
int outit_svga()
{
        closegraph();
        return 0;
}

void getvgapalette16(DacPalette16 *PalBuf)
{
  struct REGPACK reg;

  reg.r_ax = 0x1017;
  reg.r_bx = 0;
  reg.r_cx = 16;
  reg.r_es = FP_SEG(PalBuf);
  reg.r_dx = FP_OFF(PalBuf);
  intr(0x10,&reg);
}

void getvgapalette256(DacPalette256 *PalBuf)
{
  struct REGPACK reg;

  reg.r_ax = 0x1017;
  reg.r_bx = 0;
  reg.r_cx = 256;
  reg.r_es = FP_SEG(PalBuf);
  reg.r_dx = FP_OFF(PalBuf);
  intr(0x10,&reg);
}

void setvgapalette16(DacPalette16 *PalBuf)
{
  struct REGPACK reg;

  reg.r_ax = 0x1012;
  reg.r_bx = 0;
  reg.r_cx = 16;
  reg.r_es = FP_SEG(PalBuf);
  reg.r_dx = FP_OFF(PalBuf);
  intr(0x10,&reg);
}

void setvgapalette256(DacPalette256 *PalBuf)
{
  struct REGPACK reg;

  reg.r_ax = 0x1012;
  reg.r_bx = 0;
  reg.r_cx = 256;
  reg.r_es = FP_SEG(PalBuf);
  reg.r_dx = FP_OFF(PalBuf);
  intr(0x10,&reg);
}

-----------------------------------------------


code, needs to include 'svgalib.c':

----------------------------------------

#include "svgalib.h"

main()
{
  int num;
  init_svga(SVGA800x600x256);
  set_palette();

  num=15;

  setcolor(num); /* set current drawing color to color cell 15 */
  /* draw something */
  fade(15);
  /* etc */
}

void set_palette()
{
  DacPalette256 palette;

  palette[0][0]=0; /* red component of color cell 0 */
  palette[0][1]=0; /* green component of color cell 0 */
  palette[0][2]=0; /* blue component of color cell 0 */
  /* rgb entries range from 0 to 255 */
  /* 000 eq black, 255 255 255 eq white */

  palette[1][0]=1;
  palette[1][1]=1;
  palette[1][2]=1;
  /* etc */
  palette[255][1]=255;
  palette[255][2]=255;
  palette[255][3]=255;

  /* this has immediate effect */
  setvgapalette256(&palette);
}

/* example for fading any colorcell entry to black */
void fade(int num)
{
  int i,r,g,b;
  int step=10;
  float rf,gf,bf;
  DacPalette256 palette;

  getvgapalette256(&palette);

  r=palette[num][0];
  g=palette[num][1];
  b=palette[num][2];

  rf=(float)r/(float)step;
  gf=(float)g/(float)step;
  bf=(float)b/(float)step;

  for(i=0;i<step;i++){
    palette[num][0]=r-(int)((float)i*rf);
    palette[num][1]=g-(int)((float)i*gf);
    palette[num][1]=b-(int)((float)i*bf);
    setvgapalette256(&palette);
    /* add some delay */
  }
}

-------------------------
You realize of course that this is a very crude example, and I have just typed this from memory, not beeing able to actually test the code. There are lot of things to refine, e.g. checking that palette entries stay in the range 0-255 etc...

But I guess the principal is clear! Hope that gets you going !