Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to maka characters dim?

Posted on 1997-02-20
6
Medium Priority
?
280 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:Chaitanya021797
  • 4
  • 2
6 Comments
 

Accepted Solution

by:
ansgar earned 600 total points
ID: 1249400
Draw the characters using color cells reserved exclusively for them. After the characters are on the screen, morph the rgb content of these colorcells towards the background color. In the simplest case, just reduce each rgb stepwise to zero. This will give a smooth fading effect. You might want to increase the speed of the morphing towards the end, this will give a better optical effect.
0
 

Author Comment

by:Chaitanya021797
ID: 1249401
Edited text of question
0
 

Expert Comment

by:ansgar
ID: 1249402
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.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Chaitanya021797
ID: 1249403
Edited text of question
0
 

Expert Comment

by:ansgar
ID: 1249404
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);
}

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


0
 

Expert Comment

by:ansgar
ID: 1249405
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 !

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question