TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: CHRISTOPHER BUTLER
date: 1997-06-06 16:58:00
subject: Graphics routines

Hi All!
Could someone tell me whats wrong with this code?
This is my first try at creating a class, so I just used the graphics 
functions I was used to using in QB, converted to a C++ class...
Unfortunatly, it doesn't work.. on mine, the screen is cleared to red, then 
there's a GPF...
=== Begin graphics.cpp ===
#include         /* For pokeb() & peekb() */
#include 
class GraphicsScreen {
      public:
        GraphicsScreen();
        ~GraphicsScreen();
        PutPixel(int x, int y, unsigned char col);
        Box(int x1,int y1,int x2,int y2,unsigned char col);
/*        PrintText(const char *text, unsigned char col, unsigned char 
shadow=0, unsigned char shadowcol=0); */ /*** Not Implemented ***/
}
GraphicsScreen::GraphicsScreen()
{
        asm {           // Set video mode, via ASM
           mov ah,0x13
           int 0x10
        }
}
GraphicsScreen::~GraphicsScreen()
{
        asm {           // Back to text mode, via ASM again
           mov ah,0x13
           int 0x10
        }
}
GraphicsScreen::PutPixel(int x, int y, unsigned char col)
{
        // Poke the colour into the video memory directly
        pokeb(0xA000,(x+(y*320)),(char)col);
        return 0;
}
GraphicsScreen::Box(int x1,int y1,int x2,int y2,unsigned char col)
{
        // Do basically the same as above, but with a range.
        // I've repeated the poke instruction here as its probably faster.
        int x,y;
        for (x=x1;x<=x2;x++)
        {
                for (y=y1;y<=y2;y++)
                {
                pokeb(0xA000,(x+(y*320)),(char)col);
                }
        }
        return 0;
}
int main(void)
{
        GraphicsScreen gs;      // Initalize object, and set screen mode.
        gs.Box(100,100,200,200,0x13);   // Draw a box
        gs.PutPixel(150,150,0x2F);      // Put a pixel in the middle
        delete &gs;             // Back to text mode
        return 0;
}
=== End graphics.cpp ===
Chris
--- FMail/Win32 1.22
---------------
* Origin: Death Butler BBS, +44-1582-620141, 24 Hours (2:257/135)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.