2

I am about to start my project for a university course unit. I am looking to make something a bit like asteroids, the retro 2D game, in c++.

I could do this using something like SFML, which would certainly seem to be the logical thing to do. However I cannot use SFML, as the libraries are not available by default on Windows.

The requirement is that my c++ code must be copied and pasted onto any Windows PC (with Visual Studio already installed) and then compiled/run from Visual Studio.

I have never used the Windows API before, however I get the feeling I might be able to use it to open a window and draw some 2d graphics within the window. Am I correct? Essentially this is all I need to be able to do: Open a window then draw some lines on it.

This is not a "can you do my homework for me" type of question. Please could someone point me in the right direction for getting started with WinAPI if this is the tool I need, and if not is there something else I can use instead? What about some sort of OpenGL libraries? Are the OpenGL 2.0 or similar libraries bundled with Visual Studio?

(In case it is significant, I think we are using VS 2010.)

Cheers everyone,

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225

3 Answers3

1

You can open a window, create some sort of canvas and draw on it, but I don't know if that is rendered by software or hardware. In your case, if it is a very small game you might not need hardware rendering.

However, if you want hardware rendering through DirectX, you can try Mircrosoft XNA Game Studios 4.0, it comes free for universities with DreamSpark subscription.

what is sleep
  • 916
  • 4
  • 12
1

This tutorial covers just avout everything you need for creating a graphical Win32 app:

http://www.winprog.org/tutorial/

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
1

Please note that some older versions of visual studio express couldn't compile windows application unless windows sdk is installed. If that's the case with your visual studio installations, then you won't be able to do any graphics at all with requirements you listed.

Please could someone point me in the right direction for getting started with WinAPI

Sure.

The requirement is that my c++ code must be copied and pasted onto any Windows PC (with Visual Studio already installed) and then compiled/run from Visual Studio.

You know, you can simply include code of whatever library you use into your project. Because projects like libsdl use permissive licenses, you could do that. Not sure if that would break your "rules", though.

With default visual studio installation you don't get much. You definitely can create a window and draw something on it with pure winapi. Using something like SetDIBitsToDevice you could easily do full software rendering yourself.

Advanced OpenGL features require wrapper library (like GLEW), but you can initialize extensions and advanced features yourself. Quake3 engine did that, so you could do that to.

Using DirectX most likely is out of question, because it normally requires installation of SDK. You could copy/paste required libraries/headers into subdirectory of your project, but then again, it is unclear if this would break the "rules".

Are the OpenGL 2.0 or similar libraries bundled with Visual Studio?

Default OpenGL header supports version 1.1 or something like that. However, you can load missing functions yourself using wglGetProcAddress. You can also declare missing constants yourself in your code. Whether it is worth it or not, is another story.

Bottom line:

If you want full software rendering, create window using winapi, allocate 2d buffer for a "screen" (RGB format) and blit it onto window every frame using SetDIBitsToDevice or StretchDIBitsToDevice. That'll work and compile pretty much anywhere, if windows headers are available.

You could also try using GDI routines for drawing lines, etc, but I'm not sure how well that would work for a game. I haven't used GDI in quite a while, but I think you can get noticeable flickering if you aren't careful.

If you need advanced features (for example, for some people it'll be difficult to write software rendering routines that can draw textured triangles or can rotate 2d sprites) consider using OpenGL and loading missing functions using wglGetProcAddress. However, if your university (for some reason) has ancient(or faulty) hardware, you might want to limit yourself to an old version of OpenGL (OpenGL 1.1). The reason is that OpenGL 1.1 is supported by software OpenGL renderer which will be enabled in case there's some kind of trouble using hardware acceleration.

SigTerm
  • 26,089
  • 6
  • 66
  • 115
  • 1
    Microsoft provides a reference implementation of OpenGL 1.1 built on top of GDI for use with any system that does not have a hardware ICD installed. I cannot imagine anyone teaching OpenGL 1.0, it does not even have texture objects :-\ – Andon M. Coleman Nov 08 '13 at 04:03
  • @AndonM.Coleman: I know that 1.0 doesn't support textures, I simply forgot to which version of GL windows defaults in case of trouble - 1.0 with textures as extensions (or something) or 1.1. I had a problem (several times) with OpenGL failing to initialize with hardware acceleration for unknown reason. Never figured that one out. – SigTerm Nov 08 '13 at 14:40