Results 1 to 14 of 14

Thread: Colors or graphics in C++ console app?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Is there a way to use colors or graphics in a C++ console application?

  2. #2
    Guest
    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Hey Megatron...

    How do I use graphics.h?

  4. #4
    Guest
    I do not have Borland C++, nor do I have the graphics.h file so I'm unsure of the usage.

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    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

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In console mode, you need to directly access the video memory. You will then have an array which corresponds to the displayed image.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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...
    Harry.

    "From one thing, know ten thousand things."

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Ahhh haaa

    So how do you get a pointer to the graphics memory?
    Harry.

    "From one thing, know ten thousand things."

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I have this piece of code from the book "Cutting-Edge 3D Game programming with C++" (Coriolis Group 1996, ISBN 1883577705).

    Code:
    #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, &regs, &regs);
    }
    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/sou...oad/vbe2_c.zip
    Also take a look at http://www.vesa.org/vbe3.pdf
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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?
    Harry.

    "From one thing, know ten thousand things."

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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 refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Guest
    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.

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Pity DX only works under windoze.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Guest
    ChimpFace9000: You can download a graphics library by Clicking here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width