Solved

How to maka characters dim?

Posted on 1997-02-20
6
267 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 200 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 177
why debugging a macro i s difficult 10 33
How to align numbers in C using the %d 2 96
distributed computing in Python 4 123
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

770 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