Introduction to Windows Programming and OpenGL

By RoD
While OpenGL is cross-platform, this tutorial is written for programming on Windows, and we'll dive into the basics of Windows programming. For the programs we will be creating you will need a base understanding of the mechanics and structuring of the Windows operating system. Not to worry, however, because I am going to teach this to you!

Basic elements of a Windows program

Microsoft Windows is a multi-tasking operating system that allows multiple applications, referred to here on out as processes. Every process in Windows is given a certain amount of time, called a time slice, where the application is given the right to control the system without being interrupted by the other processes. The runtime priority and the amount of time allocated to a process are determined by the scheduler.

The scheduler is, simply put, the manager of this multi-tasking operating system, ensuring that each process is given the time and the priority it needs depending on the current state of the system.

Processes can be broken down into threads, where each thread can execute its own code to allow for multitasking within a single application. The scheduling for threads is the same as that for processes, except that threads are what make up the process. What is the difference between a thread and a process, you ask? All the threads within a process share access to the same memory, whereas processes do not (by default) share any memory.

Within your games you can have multiple threads running that can perform multiple calculations at once and thus provide your game with multitasking within itself. Going even further, each thread in your process has the ability to house multiple fibers, which can perform multiple operations at once within a single thread.

Event-driven programming

Windows is what is known as an event-driven operating system. What this means is that each process is executed based on the events they receive from the operating system. For instance, an application may sit at idle and wait for the user to press a key. When that key is pressed Windows will register an event to the application that the key is down.

Windows programming is not difficult at all in most cases, and to start we'll use the most basic program ever created. Hello World is used in almost every class when you begin programming in any language, and that won't change here. So, shall we have a look at Hello World in Windows style? Sure!
#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
	MessageBox(NULL, "\tHello World!", "My first windows app", NULL);
	return 0;
As you can see, it's pretty straight forward. Don't pay attention to the things that don't make sense, as in the next lesson we will go in-depth to explain WinMain () and other functions, as well as show how this and OpenGL work together!

As always, happy coding!

Previous: OpenGL vs. DirectX
Next: The WinMain Procedure
Back to OpenGL tutorial index