C graphics RGB

This is a discussion on C graphics RGB within the C Programming forums, part of the General Programming Boards category; Hello any body know's IN turbo c How can i put a pixel with color values 256 pair Red ,blue, ...

  1. #1
    kishore_ kishore
    Guest

    Post C graphics RGB

    Hello any body know's IN turbo c How can i put a pixel with
    color values 256 pair Red ,blue, green... plz give code ....

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    28
    to the best of my knowledge... u can't do it using conio.h

    which is the graphic library w/h Turbo C uses.

  3. #3
    Unregistered
    Guest
    To put a pixel in VGA mode w/o using BGI you will access the video memory directly.

    Code:
    unsigned char *Screen=(unsigned char *)MK_FP(0xa000,0);
    
    Screen[y*320+x]=paletteindex;

    To change a palette entry:
    Code:
    outp(0x03C8,index);
    outp(0x03C9,red);
    outp(0x03C9,green);
    outp(0x03C9,blue);
    To get a palette entry:
    Code:
    outp(0x03C7,index)
    red=inp(0x03C9);
    green=inp(0x03C9);
    blue=inp(0x03C9);
    This will get the current palette's respective RGB values
    Code:
    struct RGB
    {
      unsigned char red;
      unsigned char grn;
      unsigned char blu;
    };
    
    RGB CurPalette[256];
    
    for (int i=0;i<255;i++)
    {
      outp(0x03c7,i);
      CurPalette[i].red=inp(0x03c9);
      CurPalette[i].grn=inp(0x03c9);
      CurPalette[i].blu=inp(0x03c9);
    }
    You can also just send 0 to port 0x03C7 and then do 256*3 reads from port 0x03C9 to get the entire palette. Same is true with set palette. Send 0 to port 0x03C8 and then send 256*3 values to port 0x03C9.



    For color in non-palette modes (like VESA 16/24/32 bit modes do this:

    For 565 RGB:

    unsigned int color=(red<<11)+(green<<6)+blue;


    For 32 bit color, or 24 bit (last byte is alpha so no worries)

    unsigned long=(red<<16)+(green<<8)+blue;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  2. OpenGL: Pixel addition
    By Hunter2 in forum Game Programming
    Replies: 4
    Last Post: 12-15-2008, 01:36 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. Stopwatch program (need help!)
    By modnar in forum C Programming
    Replies: 9
    Last Post: 03-21-2004, 11:42 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21