🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Windows API

Started by
27 comments, last by Steeeve 4 years ago

Have had a hell of a time getting back into programming. Couldn't get any IDE or graphics library to work. Finally I have Code Blocks working, and am using the Windows API as my library. Am I way off base? It looks like everyone is using Unity.

I'm using bitmaps for graphics and BitBlt to draw them, ANDing with a black background to cut a hole in my background, then ORing with a white background to draw a character and animate it.

Steeve

Advertisement

Unity has become the standard, but that doesn't make your approach invalid. Though, I'd reconsider your hard dependency on the Windows API and use something like SDL2, instead, and potentially move to using OpenGL for hardware acceleration, if necessary.

Steeeve said:
Couldn't get any IDE or graphics library to work.

Can you be more specific? There are quite literally millions of programmers who develop software every day and do not run into problems getting an IDE to work, or rendering graphics.

Start with what development host you're using (if I had to guess, it's Windows 10 since that's very popular these days but it's certainly not the only one). What IDEs have you tried? What problems did you encounter?

What graphics libraries have you tried? What problems did you encounter?

Stephen M. Webb
Professional Free Software Developer

@Bregma I started on Windows 7 and am now on Windows 10. The upgrade resulted in my user name being DefaultUser0. For IDEs I tried Visual Studio a dozen times, Eclipse, Dev C++. Tried DirectX many times, and OpenGL, and .NET, Can't come up with any specific problems; I just could not configure any of them to actually work. Never got to where I could even compile. I want to use whatever is widely used, so there would be a future in it, and plenty of help. Would DirectX be the way to go? Try and make it work with CodeBlocks or maybe go back to Visual Studio? The one setup that worked flawlessly the first time was Borland Builder, but that was back in the 80's! Showing my age, which might be the problem, too. Can't teach an old dog new tricks.

Steeve

@Steeeve Re-read your post. Maybe stick with Code Blocks but use OpenGL?

Steeve

You say you can't even get a program to compile.

It might be an idea to actually work with the shell only for some time, just to get a feeling of how to use the tools file system, editor, compiler, linker, debugger.

My personal and totally unprofessional opinion is that there is no good IDE. One must live with the subjectively least bad one that obfuscates as little as possible while at the same time let one work without too much waste of time figuring out things.

But i am just a hobbyist tinkering around.

Green_Baron said:
My personal and totally unprofessional opinion is that there is no good IDE. One must live with the subjectively least bad one that obfuscates as little as possible while at the same time let one work without too much waste of time figuring out things.

That's a great way to see it - sort of a pessimist variant of picking the IDE that will boost your productivity the most; you just go with the one where the flaws don't slow you down as much ?

Green_Baron said:
My personal and totally unprofessional opinion is that there is no good IDE. One must live with the subjectively least bad one that obfuscates as little as possible while at the same time let one work without too much waste of time figuring out things.

I'm with you there, but I'm old and I cut my teeth on punched cards and graduated to using ed on a vt100 (because vi took too much system resources on a VAX 750 shared between hundreds of students). My “IDE” is gvim and a half dozen CLI windows spread across multiple monitors with multiple workspaces. I've tried other ways, but most are so slow and bloated they can't keep up with my (slow) typing, they require me to take my hands of the keyboard too often, and they dumb things down so much they require cargo-culting basic steps.

That said, if you're Windows-oriented, there is nothing like Microsoft Visual Studio for getting started. Microsoft has plenty of docs on using it to produce program, plenty more on they various libraries, and the internet is full of tutorial and help sites. You would invite less pain if you start off with that product if you're starting fresh.

Stephen M. Webb
Professional Free Software Developer

Is no one using the Windows API? MY program works, but the animation is really clunky. And my drawings are awful. Is it just hard to draw with a mouse? Or is my utter lack of drawing skill the problem? Here's a screenshot and the animation routine…

/*
          PlayerAnimation
*/

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

#include "mapping.h"

extern int MoveViewPort(); // check if move is needed when location changes
extern int ShowError();

int PlayerAnimation()
{
  int type;    // 1 = player
  int subtype; // 0 = still, 1 = right, 2 = left, 3 = up, 4 = down
  int cframe;  // current animation frame
  int nframe;  // next animation frame, either +1 or -1
  int mframe;  // max animation frame, cycle between this and 1


  // draw the player in the viewport

  /* first, AND a solid black version of the player on a solid white background
            into the terrain. This will "cut" a hole for the player, leaving
            the background intact.
     then,  OR the actual colored player on a solid black background
            into the terrain. This will insert the player, and again leave
            the background intact.

    player has to go from px,py to dx,dy one pixel at a time,
    redrawing the terrain at px,py and dx,dy before redrawing the
    player one more pixel closer to dx,dy

    a timer will trigger each pixel move/redraw if px,py <> dx,dy
    or animate the player standing in place if px,py == dx,dy
*/

  screenDC = GetDC(hwnd);                  // screen DC for drawing
  bitmapDC = CreateCompatibleDC(screenDC); // memory DC for bitmaps

  // redraw terrain at plocx,plocy and at pdestx,pdesty to erase previous player image

  // terrain at player location

  type    = map[plocx][plocy].type;
  subtype = map[plocx][plocy].subtype;
  cframe  = map[plocx][plocy].curframe;
  nframe  = map[plocx][plocy].nxtframe;
  mframe  = map[plocx][plocy].maxframe;

  old = SelectObject(bitmapDC, (HBITMAP)terrain_image[type][subtype][cframe]);

  ok  = BitBlt(screenDC,vscrx + BMwidth *(plocx - vx),vscry + BMheight*(plocy - vy),
                                BMwidth,                      BMheight,
                        bitmapDC, 0, 0, SRCCOPY);
  SelectObject(bitmapDC, old);

  if (!ok)
  {
    ShowError();
    ok = MessageBox(NULL, LPCSTR("draw terrain @ploc failed"),LPCSTR("Player Animation"),MB_OKCANCEL);
    if (ok == IDCANCEL) exit(0);
  }


  // terrain at player destination

  type    = map[pdestx][pdesty].type;
  subtype = map[pdestx][pdesty].subtype;
  cframe  = map[pdestx][pdesty].curframe;
  nframe  = map[pdestx][pdesty].nxtframe;
  mframe  = map[pdestx][pdesty].maxframe;

  old = SelectObject(bitmapDC, (HBITMAP)terrain_image[type][subtype][cframe]);
  ok  = BitBlt(screenDC,vscrx + BMwidth *(pdestx - vx),vscry + BMheight*(pdesty - vy),
                                BMwidth,                       BMheight,
                        bitmapDC, 0, 0, SRCCOPY);
  SelectObject(bitmapDC, old);

  if (!ok)
  {
    ShowError();
    ok = MessageBox(NULL, LPCSTR("draw terrain @pdest failed"),LPCSTR("Player Animation"),MB_OKCANCEL);
    if (ok == IDCANCEL) exit(0);
  }


  // P L A Y E R


  // update the players position

  pscrx = pscrx + pincx;
  pscry = pscry + pincy;

  // AND a hole in the terrain for the player image

  type    = thing[0].type;
  subtype = thing[0].subtype;
  cframe  = thing[0].curframe;
  nframe  = thing[0].nxtframe;
  mframe  = thing[0].maxframe;

  old = SelectObject(bitmapDC, (HBITMAP)thing_image[type][subtype][cframe][1]); // AND bitmap
  ok  = BitBlt(screenDC,pscrx,pscry,
                        BMwidth, BMheight,
                        bitmapDC, 0, 0, SRCAND);
  SelectObject(bitmapDC, old);

  if (!ok)
  {
    ShowError();
    ok = MessageBox(NULL, LPCSTR(str),LPCSTR("AND player failed"),MB_OKCANCEL);
    if (ok == IDCANCEL) exit(0);
  }

  // OR the player image into that hole

  old = SelectObject(bitmapDC, (HBITMAP)thing_image[type][subtype][cframe][2]); // OR bitmap
  ok  = BitBlt(screenDC,pscrx,pscry,
                        BMwidth, BMheight,
                        bitmapDC, 0, 0, SRCPAINT);
  SelectObject(bitmapDC, old);

  if (!ok)
  {
    ShowError();
    ok = MessageBox(NULL, LPCSTR(str),LPCSTR("OR player failed"),MB_OKCANCEL);
    if (ok == IDCANCEL) exit(0);
  }

  // go to the next frame in the animation

  thing[0].curframe = cframe + nframe;

  if ((cframe + nframe) == 1)      thing[0].nxtframe = 1;
  if ((cframe + nframe) == mframe) thing[0].nxtframe = -1;

  // done

  ReleaseDC(hwnd,screenDC);
  DeleteDC(bitmapDC);

  // Has the player reached his destination?

/*
      if (pincx != 1 && pincx != -1) sprintf(str,"inc: %d",pincx);
      if (pincx == 1) sprintf(str,"to the right, from %d to %d",plocx,pdestx);
      if (pincx == -1) sprintf(str,"to the left, from %d to %d",plocx,pdestx);
      ok = MessageBox(NULL,LPCSTR(str),LPCSTR("DONE!"),MB_OKCANCEL);
      if (ok == IDCANCEL) exit(0);
*/


  if (plocx != pdestx)
  {
    if (pscrx == (vscrx + (BMwidth*(pdestx - vx))))
    {
      plocx = pdestx; pincx = 0; MoveViewPort();
    }
  }

  if (plocy != pdesty)
  {
    if (pscry == (vscry + (BMheight*(pdesty - vy))))
    {
      plocy = pdesty; pincy = 0; MoveViewPort();
    }
  }

  return(TRUE);
}
screen shot; that's supposed to be the player out in the water!

Steeve

What's your goal here?

You are re-inventing the game engine. There is nothing wrong with doing that for learning exercises. Everyone needs to know how the basics work. If that's your goal stay on that path.

If your goal is to make a modern game don't reinvent everything. Use a major engine (like Unity, Unreal, Godot, GameMaker Studio, RPG Maker, HeroEngine, or on and on) that have already written the standard parts. You don't need to program low-level graphics, low-level animations, low-level audio, low-level networking, low-level input, low-level timing, low-level game scripting, low-level task scheduling, math libraries, data processing libraries, etc. All of those pieces are created already, they have been debugged, and you don't need to worry about them. Use these to actually make a game rather than spending your time making an engine.

This topic is closed to new replies.

Advertisement