Re: A82: Hmm


[Prev][Next][Index][Thread]

Re: A82: Hmm




At 08:51 PM 12/15/97 +0100, you wrote:
>
>At 22:50 1997-12-14 EST, you wrote:
>>
>>I know that this is the wrong place to send this question to, but I can't
find
>>the answer anywhere else, and I know some of you might know the answer.
How do
>>you plot pixels in C???
>
>That depends on the compiler, because there is no function like that in
the standard library.

Here is the fastest way to plot a pixel on a 320x200x256 screen using any
ANSI C compiler:

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <bios.h>
#include <math.h>
#include <conio.h>

#define VGA256  0x13
#define TEXT_MODE  0x03

unsigned char far *video_buffer = (char far *)0xA0000000L;

void Set_Video_Mode(int mode)
{
  union REGS inregs, outregs;
  inregs.h.ah = 0;
  inregs.h.al = (unsigned char)mode;
  _int86(0x10, &inregs, &outregs);   // it could be int86 instead of _int86
}

void Put_Pixel(int x, int y, unsigned char color)
{
  video_buffer[((y<<8) + (y<<6)) + x] = color;
}

void main (void)
{
  Set_Video_Mode(VGA256);
  Plot_Pixel(100,100,5);
  while(!kbhit());
  Set_Video_Mode(TEXT_MODE);
}

That should be a good demonstration of how to plot one pixel on the screen
in C.  If you want to start programming serious graphics, then I recommend
getting a good game programming book like "Teach Yourself C in 21 Days."
Even though the book uses the Microsoft C compiler exclusively, it is still
quite useful for any other C compiler since each compiler is nearly the same.


                 Thomas J. Hruska -- thruska@tir.com
Shining Light Productions -- "Meeting the needs of fellow programmers"
         http://www.geocities.com/SiliconValley/Heights/8504
                    http://shinelight.home.ml.org

  Spam-Fighter code is:  14806560   (New technique to fighting spam)
  Enter "Spam-Fighter:  XXXXXXXX" in the body of a personal message
  to thruska@tir.com.  Otherwise the message will be filtered as spam.


Follow-Ups: References: