Thread: Drawing a single pixel

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    48

    Drawing a single pixel

    I need help.. how do I draw a pixel? I'm making a very simple-designed program (not a game, and the pixel will not move) and all I need to know is how to draw one pixel.
    Last edited by SMB3Master; 05-23-2003 at 06:41 PM.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    It would help to know things like:

    1) Are you talking about drawing a pixel on a console window, on a graphical window, etc.

    2) What operating system you're compiling it for

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    Console, DOS.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Then it's going to be a royal pain in the ass, unless you have an old compiler from the DOS days, and Windows' DOS emulation is good enough to handle your compiler's graphics routines.

    You can try to get an ancient compiler, and write a DOS program with graphics, but there are no standards at all for how to do graphics pre-Windows. Before windows universalized the Software->OS->Driver->Hardware model for accessing hardware, it was kind of a mess. Modern compilers don't do DOS graphics (in fact, many won't even do DOS programs; you can do GUI Windows programs, or console Windows programs).

    I believe some of the old Borland compilers can generate graphics code that will still work under XP's DOS emulation, but I haven't programmed DOS graphics since sometime around 1993. Dunno how well Borland's old compilers like running under Windows; I've heard it's tricky to make them work right.

    If you have a DOS compiler that will allow inline assembly (or you have an assembler that will do real-mode assembly) you might try BIOS interrupts. Int10h, function 00h sets graphics mode; Int10h function 0Ch writes a graphics pixel. I have no clue what would happen when you execute them on the virtual DOS machine that WinNT uses. Again, it's not something I've done since the pre-Win3.1 days (OK, Win 3.1 existed in 1993 but I didn't use it very much).

    This will almost certainly screw up any text output you had planned. Back the, there were 2 display modes: text and graphics. In text mode, you could only display characters, in graphics mode, you got only graphics; you had to use special functions to draw text in a graphics mode (standard text output was no good).
    Last edited by Cat; 05-23-2003 at 07:12 PM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    So you program in windows now? I wanna learn but its so confusing

    Any advice on starting?
    Last edited by SMB3Master; 05-23-2003 at 07:30 PM.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Check out the FAQ, and check the Windows programming forum, and try the links in:

    http://cboard.cprogramming.com/showt...threadid=39585

    It's not THAT hard, just go slowly and try to understand each step in turn.

    It's really just a different WAY of thinking. At its heart, you have:

    * A message pump in every thread which receives messages and dispatches them to your windows
    * A procedure for each window that responds to messages

    Messages are really the key to everything. Stuff happens to respond to a message, and if you want something else to happen, you send a message.
    Last edited by Cat; 05-23-2003 at 08:24 PM.

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    A Single pixel:

    #define _WIN32_WINNT 0x0500 //this should be the first line of your program
    #include <windows.h>//this should be the second

    //use this whenever you need it
    HWND hwnd=GetConsoleWindow();
    HDC hdc=GetDC(hwnd);
    SetPixel(hdc, 10, 10, RGB(0,0,0));
    ReleaseDC(hwnd, hdc);



    Note, you need to have win2k or higher I think for this to work.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    That will work fine, once he does Windows programming.

    He's compiling for DOS at the moment.

  9. #9
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Might not be very helpfull but i know the old Borld Turbo PAscal compiler would allow drawing in dos.

  10. #10
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by SMB3Master
    So you program in windows now? I wanna learn but its so confusing

    Any advice on starting?
    Search around the net for win32 tutorials, and you'll get the hang of it. If you just want to plot a few pixels, you'll find it is quite easy. Make sure you read what the tutorials tell you, and don't just mess with their code - since understanding how windows works (i.e. messages) is very important. It's really not so bad.

  11. #11
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    jaso n i must say that chess game and 3ds you have are amazing. the tunnel is fun to stare at

  12. #12
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Originally posted by Cat
    That will work fine, once he does Windows programming.

    He's compiling for DOS at the moment.
    He said console. A console program is a windows program, a lot of it is just hidden from the programmer.

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    I interpreted "Console, DOS" to mean he was writing for DOS and running it under the virtual DOS emulation of WinNT or somesuch.

    You are correct, console WINDOWS programs can use WinAPI functions.

  14. #14
    Don't use interrupt calls to manipulate pixels. Too slow. Edit the video memory directly. If I remember right, VGA cards working under mode 13h's memory starts at 0xA0000000. Only use the interrupt calls to set the graphics mode.

    If you can use dos.h you don't even need assembly. Look at www.brackeen.com/home/vga/ for info about DOS graphics. It even covers Mode X junk. I also found a site somewhere that was just interrupt calls, and you can find some cool graphics modes that way. There is a mode similiar to Mode 13h that works in 640x480 that not many know about, but I forget the interrupt number for it.

  15. #15
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I would also check out Denthor's Asphyxia Tutorials if you wish to learn about mode 13h in DOS.

    Iamien, thanks. Yeah, the tunnel effect was pretty cool. It's very simple, too. The idea just popped into my head one day, and it only took me 30 minutes to code. Fairly simple to convert into assembly, as well. The chess game is not that great, since it lacks hash tables, but it is ok for what was required for the project. If I had time, I would reprogram it from scratch and try to polish it off a little nicer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. DX pixel drawing
    By VOX in forum Game Programming
    Replies: 3
    Last Post: 07-04-2005, 03:59 PM
  4. drawing flow-charts for every single program??
    By LogicError in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 05-30-2005, 10:22 AM
  5. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM