Solved

How to maka characters dim?

Posted on 1997-02-20
6
265 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
The goal of this video is to provide viewers with basic examples to understand recursion 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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now