Click to See Complete Forum and Search --> : Colors or graphics in C++ console app?
SteveCRM
Jul 26th, 2000, 09:14 PM
Is there a way to use colors or graphics in a C++ console application?
What about us that have Visual C++, there is no graphics.h. They might have a similar header file, but i have no idea what the name id.
SteveCRM
Jul 27th, 2000, 08:17 AM
How do I use graphics.h?
I do not have Borland C++, nor do I have the graphics.h file so I'm unsure of the usage.
CthulhuDragon
Jul 27th, 2000, 10:46 AM
In a console app you have access to a limited number of windows api calls for console apps. They include things like back/fore color, mouse support, etc. check out msdn under Console, it might help you a bit
parksie
Jul 29th, 2000, 06:08 AM
In console mode, you need to directly access the video memory. You will then have an array which corresponds to the displayed image.
HarryW
Jul 29th, 2000, 11:16 AM
If you run the console in Windows, will Windows allow you to directly access the hardware like that? I know that's how it used to be done but I thought you couldn't do it like that any more...
HarryW
Jul 29th, 2000, 08:09 PM
Ahhh haaa ;)
So how do you get a pointer to the graphics memory?
parksie
Jul 30th, 2000, 02:29 PM
I have this piece of code from the book "Cutting-Edge 3D Game programming with C++" (Coriolis Group 1996, ISBN 1883577705).
#include <dos.h>
#include <conio.h>
unsigned int BaseDs = 0u;
int InitDPMI(void) {
REGS Register;
// Do not proceed if BaseDs has already been initialized
if (BaseDs == 0) {
// Get the base linear address for DS.
Register.w.bx = _DS;
Register.w.ax = 0x0006;
int386(0x31, &Register, &Register);
// If we encounter an error, return zero
if (Register.x.cflag)
return 0;
// Multiply by 65,536 and mask out un-wanted bits
BaseDs = ((unsigned int)(Register.w.cx) << 16) | Register.w.dx;
Register.w.bx = _DS;
Register.w.ax = 0x0008;
Register.w.cx = Register.w.dx = 0xFFFF;
int386(0x31, &Register, &Register);
return !Register.x.cflag;
} else {
return 1;
}
}
// Call this one to get a real-mode address
unsigned int GetAddress(unsigned int RMLocation) {
if ((BaseDs == 0) && (InitDPMI() == 0))
return 0;
return (RMLocation - BaseDs);
}
// Call this one to get a real-mode address
// Don't call this one without calling InitDPMI
unsigned int ConvertAddress(unsigned int Address) {
return Address - BaseDs;
}
// Function returns video address
unsigned char* VideoAddress () {
return (unsigned char *)GetAddress(0xA0000UL);
}
// Function to set video mode
void SetVideo (short int mode) {
REGS regs;
regs.w.ax = mode;
regs.h.ah = 0;
int386(0x10, ®s, ®s);
}
It works for VGA mode 19 (320x200 256colour). It probably won't work, because I don't understand it. It involves creating an address high enough that it wraps into a real-mode address. It may prove useful for dissection, however.
The best solution is probably to use VESA drivers, which games like GTA used to provide loads of video modes. These let you access all SVGA modes easily. Cubic has a C++ library (for Watcom C++, but should be easily portable) for using VESA and VBE here: http://www.cubic.org/~submissive/sourcerer/download/vbe2_c.zip
Also take a look at http://www.vesa.org/vbe3.pdf
HarryW
Jul 30th, 2000, 03:16 PM
Cheers parksie. Is that book of yours any good?
I bought a book on game architecture (hoping it would give advice on how to approach the different genres) but it turned out to be more or less about management, not actual development. Know any gooduns?
parksie
Jul 31st, 2000, 12:23 PM
It's very good, actually, like a couple of other Coriolis books. "Windows Game SDK Developer's Guide" is also quite good (I don't have it, though). http://www.coriolis.com. Check out the Sourcerer at http://www.cubic.org for loads of useful information.
I know this is irrelevant to the question, but I have a book on Dx(DirectX), and it seems to be quite easy to have direct access to the video memory.
parksie
Aug 6th, 2000, 07:59 AM
Pity DX only works under windoze.
ChimpFace9000: You can download a graphics library by Clicking here (http://www.cprogramming.com/source/graphic_h.exe)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.