Thread: Game-related stuff with WinAPI

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    1

    Question Game-related stuff with WinAPI

    Hello y'all.

    I'm looking for a good description of how to do graphics (simply putting pixels is perfectly fine), keyboard and mouse I/O, and image and sound I/O with winAPI. Does anyone know of a good tutorial/some basic things to know?
    I would love to have DOS-esque graphics (easy pixel putting) but sadly that doesn't work any more.

    I'm using Windows 7 64-bit with MinGW as a compiler.
    Last edited by YuriKahn; 05-22-2013 at 04:25 PM.

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Though it's possible, you're really going to be wasting a lot of time and a lot of that kind of thing has been deprecated. You're basically looking into the GDI functions (and if Googling hasn't already found that out for yourself, I suggest you start somewhere like here: Win32 Programming - FunctionX ).

    Honestly? Forget it and just go to SDL. It's a nice layer on top of all that junk that is cross platform, suffers absolutely minimal performance loss over doing it yourself (and if you read the SDL code you'll see why) and can take advantage of newer hardware (e.g. OpenGL textures, etc.).

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    358
    Quote Originally Posted by YuriKahn View Post
    Hello y'all.

    I'm looking for a good description of how to do graphics (simply putting pixels is perfectly fine), keyboard and mouse I/O, and image and sound I/O with winAPI. Does anyone know of a good tutorial/some basic things to know?
    I would love to have DOS-esque graphics (easy pixel putting) but sadly that doesn't work any more.

    I'm using Windows 7 64-bit with MinGW as a compiler.
    What you want to do is create your own little system on top of Windows.
    So you need to set up windows in the normal way, with a main window and a message loop.
    You then create a window of your own class, call it "raster" or "canvas". This is going to draw your graphics for you. Only you can decide exactly how you want it to work, but a good interface might be setpixel(x, y, rgb), and refresh(). So implement these as messages that the canvas understands - you've got a back buffer which setpixel() writes to, and you blit it out to the screen when you get a refresh(). Probably refresh() calls invalidate rect and generates a redraw message via updatewindow.
    The next step is to set up a timer, which ticks at your frame refresh rate. You have a tick() function which is called in response to the timer, and which does your game logic and regenerates the frame. Then you call refesh() on your canvas window.
    All graphics can be build on top of setpixel() and getpixel(), and simple graphics can very easily be implemented by calls to setpixel(). However if you want to use fonts, built in geometry routines, and the like, you need to make the canvas more complicated.
    The mouse sends a message which you simply intercept, as does the keyboard. You've got to mess about a bit to get the focus into the window you want, which might be the main window or might be the canvas window. Code in response to these messages should be very simple - just set an x, y or put a character into a buffer. Do all your serious processing in tick().
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Card game war, programming related-ish
    By colerelm in forum Tech Board
    Replies: 2
    Last Post: 11-10-2011, 08:22 AM
  2. Replies: 5
    Last Post: 05-18-2010, 09:42 PM
  3. Just want some clarification on some game related things
    By Rumproast23 in forum Game Programming
    Replies: 5
    Last Post: 06-02-2006, 07:08 AM
  4. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 03:35 PM
  5. related to game programming but it isn't
    By Scourfish in forum Game Programming
    Replies: 6
    Last Post: 09-08-2001, 05:03 PM

Tags for this Thread