Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

50 OpenGL Win32 Projects in One

4.91/5 (28 votes)
8 Jun 2017CPOL21 min read 19.9K   2.2K  
Former NeHe OpenGL Lessons adapted to MSVS-15 pro Win32 in INICODE and the samples of the Joystick implementation

Image 1

Introduction

This article is the continuation of the article published last month with almost the same name just with one key word replacement. But it is a replacement of fundamental importance. The replacement MFC to Win32 comprehends the great changes in code. And a lot of people prefer Win32 code

This article is to demonstrate some samples of the good old-fashioned, 20-years old projects working in the modern MSVS-15 Win32 and Windows-10 environment.

Background

The sample project provided is based on the old 48 lessons' project of NeHe. Three years ago, I've already done the job of adapting the lessons above to MSVS-10 pro Win32. And I've translated the codes "as it was" in MBCS coding one by one. Currently, the UNICODE coding is proposed to be used the job seemed as not completely executed. And there is no need to develop the project particularly for every lesson. The flow chart scheme is common to all OpenGL projects, therefore, it is worth developing one common project for all the lessons in demo purposes.

And now, I have some time to present this solution for MSVS-15 pro Win32 in UNICODE coding with the some samples of the Joystick implementation and the samples of using my former CodeProject articles.

Before you start building the project provided, it is highly recommended to have a look to the Demo presentation enclosed in order to get an idea of the output expected.

1.Demo Explanations

1.1.Executable Handling

The executable WIN_GL.exe in the WIN_GLdemo directory has been built with MSVS-2015 pro using the instruments of MSVS-2010. Therefore, the WIN_GL.exe is valid even for Windows-XP. Distinct from the previous article, demo performance special *.dll files are not required.

The WIN_GL.exe may be started without any arguments. In this case, the presentation of the last former called lesson appeared.

The WIN_GL.exe XX may be started in the command line with the two-symbols argument as follows : 01-48, X4, X5. In this case, the presentation of the corresponding lesson appeared.

Here and elsewhere, XX means two-symbols string: ( 01-48) - the order numbers of the lessons in the NeHe tutorial, (X4,X5) - the numbers of the lessons published by the author on the Russian NeHe site.

Image 2

The controls of the WIN_GL.exe are as follows:

  • Menu File->Lesson... - calling the Select Lesson Dialog (also keyboard Ctrl+O)
  • Menu File->Play - play/stop current lesson presentation (also keyboard Ctrl+P)
  • Resent File - calling the Select Lesson Dialog with the list box line selected in the resent lesson called corresponding
  • Menu File->Exit - exit application(also keyboard Alt+F4 (exit immediately) or keyboard Esc (with the confirmation required) )
  • Menu View->Full Screen - install/demount current lesson full screen performance (also keyboard Ctrl+Enter)
  • Menu View->Language->Russian - adjusting Lessons' Titles in Russian
  • Menu View->Language->English - adjusting Lessons' Titles in English
  • Menu View->ToolBar - show/hide the toolbar(also keyboard Ctrl+T)
  • Menu View->Status Bar - show/hide the status bar(also keyboard Ctrl+S)
  • Menu View->Next Scene - next scene of the current lesson presentation if stopped (also keyboard Ctrl+N)
  • Menu View->Joystick Test - calling the Joystick Test Dialog if applicable (lessons 09, 10, 32, 40, X4, X5)(also keyboard Ctrl+J)
  • Menu Help->About... - calling the About Dialog (also keyboard Ctrl+A)
  • Menu Help->Help Dialog... - calling the Help Dialog (also keyboard F1)
  • Menu Help->Joystick Help.. - calling the Joystick Help Dialog if applicable (lessons 09, 10, 32, 40, X4, X5)(also keyboard Ctrl + Y)

Once WIN_GL.exe started, you may select any other lesson demo to start from the list of the lessons of the dialog box that appears with the menu command File->Open...(or keyboard Ctrl + O).

Please note that the Recent file system is an alternative to the standard MS VS one and based on my CodeProject article "Your Own Resent File List(s)." Currently, the present project the special class ClassWinResent has been developed for the Win32 platform.

1.2. Lesson Select Dialog

Image 3

The Lesson Select Dialog to be called with the Menu File->Lesson... command (also keyboard Ctrl+O).

The controls of the Lesson Select Dialog are as follows:

  • List Box Control: presenting the list of the lessons' names available
  • Ok Button: starting the lesson selected in the List Box Control (also double click the left mouse button on the List Box Control line corresponding)
  • New Window Check Box: if selected, the new lesson presentation starting in the new window (current lesson remaining unchanged); otherwise new lesson starting in the same window as the current one instead
  • English Radio Button: adjusting Lessons' Titles in English
  • Russian Radio Button: adjusting Lessons' Titles in Russian
  • Cancel Button: just close the dialog

1.3. Help Using

Image 4

The Help Dialog to be called with the Menu Help->Help Dialog command (or keyboard F1). Most of the keyboard and mouse commands remain the same as per the original lessons corresponding to the NeHe site.

The controls of the Help Dialog are as follows:

  • List Box Controls: presenting the list of the keyboard and/or mouse commands for the current lesson presentation available
  • Ok Button: executing the command selected in the Control Column of the List Box Controls (also double click the left mouse button on the List box Control line corresponding)
  • Joystick Help Button: calling the Joystick Help Dialog if applicable (lessons 09, 10, 32, 40, X4, X5)

The Help Dialog is unmodal, therefore, it is possible both to use the keyboard commands listed or to select the command from the List Control and press the Ok button (or double click mouse left button).

1.4. About Dialog

With regards to the respected authors of the original code, the About Dialog (Menu Help->About...) contains the original NeHe's ReadMe texts:

Image 5

1.5. Joystick Using

The Joystick using is available in the lessons 09, 10, 32, 40, X4, X5. You may adjust the Joystick yourself to any other lesson (or in some projects of your own) with the Joystick implementation instructions enclosed.

The Joystick functionality may be tested with the Menu View->Joystick Test command (or keyboard Ctrl+J or button 8 on the Joystick itself) with the Joystick Test Dialog (where applicable).

Image 6

The controls of the Joystick Test Dialog are as follows:

  • 1-12 Check Boxes: checking if the corresponding Joystick button is pressed
  • Unnumerated Check Boxes: checking if the Joystick Hatch button corresponding is pressed
  • Left Picture Control: presenting the Cross position coordinates for bending the Joystick handle port-starboard and foarward-aft
  • Right Picture Control: presenting the Cross position coordinates for turning the Joystick handle port-starboard and the Joystick acceleration toggle foarward-aft
  • On-Off Radio Buttons: presenting the conditions of the Joystick to be connected

While the Joystick Test Dialog is visible, all the Joystick commands are valid just for this dialog only and for the application itself, the Joystick commands are not available.

Please note that the Joystick Test Dialog is based on my CodeProject article "Joystick Win32 and MFC Projects" just with Picture Control removed.

The help on the Joystick for the lessons affected to be obtained with Menu Help->Joystick Help Dialog command (or keyboard Ctrl+Y or Joystick help button in the Help dialog) with the Joystick Help dialog (where applicable).

Image 7

The Joystick Help Dialog is unmodal, therefore, it is possible both to use the Joystick commands listed or to select the command from the list and press Ok button (or double click mouse left button at the corresponding line).

2. Important Building Notes.

Before you start to build all the projects with the menu Project->Build Solution with the WIN_GLproj\WIN_GLproj\WIN_GLproj.sln file, please take into consideration some important notes.

Solution configuration must be installed as Release and the platform to be X86.

The default coding property is UNICODE; nevertheless MBCS coding is also available, just change the property.

Please note that the solution WIN_GLproj\WIN_GLproj\WIN_GLproj.sln consists of three similar projects that differ just by the degree of building complexity:

  1. WIN_GL0 - the simplest project which may be built by the people without any experience of MSVS coding; this project is without Joystick and Lessons 43 and 47
  2. WIN_GL1 - the solution requires some Property Box installations before the building; this solution is with the Joystick but without the Lessons 43 and 47
  3. WIN_GL- the complete solution requires some External Libraries installations before the building; the WIN_GL.exe result of this solution presented in WIN_GLdemo directory provided.

Even if you are working for the first time with MSVS, just appoint the WIN_GL0 project as StartUp project (right mouse button click -> menu Set as StartUp Project) and select menu Debug->Start without debugging and the program WIN_GL0.exe should start building and working.

2.1. Joystick Building Notes (projects WIN_GL1 and WIN_GL)

The project provided has been developed with MSVS-2015 pro using the instruments of MSVS-2010. Therefore, the exe files are valid even for Windows-XP.

If you no longer need to run the application in Windows-XP, just change the instruments to MSVS-2015 and no problems with the Joystick procedures building will occur.

Problems may occur using the instruments of MSVS-2010 with the Joystick implementation. The problem is that external library hid.lib is used.

Before you start to build the project WIN_GL1 with the instruments of MSVS-2010, you must ensure three things in the project concerned:

  • In the Project Property Box in Configuration Properties->VC++Directories->Include Directories, select Change command and set directory to ..\Windows Kits\8.1\Include\shared (just for #include <hidsdi.h> command to use)
  • In the Project Property Box in Configuration Properties->VC++Directories->Library Directories, select Change command and set directory to ..\Windows Kits\8.1\Lib\winv6.3\um\x86
  • In the Project Property Box in Linker->Input->Additional Dependencies, select Change command and install hid.lib (or you may insert the library hid.lib directly with the menu PROJECT->Add Existing Item from the directory ..\Windows Kits\8.1\Lib\winv6.3\um\x86\hid.lib).

2.2. Lessons 43 and 47 Building Notes (Project WIN_GL)

Lesson 43 requires the external library of freetype.lib which requires the installation of the Program Files\GnuWin32 directory(17.8 Mb) from http://gnuwin32.sourceforge.net/packages/freetype.htm link.

Before you start building the project WIN_GL with Lesson 43, you must ensure four things in the project concerned:

  • In the Project Property Box in Configuration Properties->VC++Directories->Include Directories, select Change command and set directory to ..\GnuWin32\include\freetype2
  • In the Project Property Box in Configuration Properties->VC++Directories->Library Directories, select Change command and set directory to ..\GnuWin32\lib
  • In the Project Property Box in Linker->Input->Additional Dependencies, select Change command and install freetype.lib.
  • In the root directory of the application, the FreeType6.dll and zlib.dll files are to be inserted.

Lesson 47 requires the external libraries of cg.dll and cgGL.dll which require the installation of the Program Files\NVIDIA Corporation directory(596 Mb) from https://developer.nvidia.com/cg-toolkit-download link.

Before you start building the WIN_GL project with Lesson 47, you must ensure three things in the project concerned:

  • In the Project Property Box in Configuration Properties->VC++Directories->Include Directories, select Change command and set directory to ..\NVIDIA Corporation\Cg\include
  • In the Project Property Box in Configuration Properties->VC++Directories->Library Directories, select Change command and set directory to ..\NVIDIA Corporation\Cg\lib
  • In the root directory of the application, the Cg.dll and CgGL.dll files are to be inserted.

3. Project Source, Data and Info Storage

The original projects of MS Studio .NET (Grant James, 2002) are located on the NeHe GameDev site, but not adopted to the modern Win32 and to the latest versions of MSVS. I’ve adopted all the codes of the lessons one by one and also integrated them in one common project WIN_GLproj\WIN_GL\WIN_GL.sln. While adapting the code, I found a lot of conflicts occurred in projects modification from one version of MS Visual Studio to another. Finally, for demonstration purposes, I’ve developed the project in UNICODE coding in Win32 MSVS-15 pro environment with the instruments of MSVS-10.

You may select in the Solution Explorer window any *.h or *.cpp file and you may look at and edit it. At first glance, it seemed that there are too many files enclosed, but further consideration shows that everything is not too complicated. The project consists of the common procedures and special procedures for every lesson implementation.

All three projects, WIN_GL0, WIN_GL1, WIN_GL have similar structure, just Properties Box installations differ. Therefore, Source, Data and Info storage are almost the same.

3.1. WIN_GLproj\WIN_GL\WIN_GL

Source codes in WIN_GLproj\WIN_GL\WIN_GL path have been created with the standard Win32 Application Wizard:

  • WIN_GL.cpp - defines the standard Win32 procedures for the application; HanldleCmdLine, InitGLWindow procedures and WndGLProc modification - inserted by the author;

3.2. WIN_GLproj\NeHeDrawInit

Source XX_*DrawInit.cpp codes (XX in range 01-48) in the WIN_GLproj\NeHeDrawInit path have been borrowed from original NeHe site and modified by the author for UNICODE coding in Win32 MSVS-15 pro environment. I've tried not to change these codes as far as possible.

X4_UFOGameDrawInit.cpp have been combined by the author from the original lessons 07, 11, 30, 32, 34 for demo purposes.

X5_BoxmanDrawInit.cpp has been developed by the author for demo purposes.

Just a few changes have been made in XX_*DrawInit.cpp codes from the previous article due to the platform change from MFC to Win32.

3.3. WIN_GLproj\NeHeProgs

Special source code for the separate lessons in the WIN_GLproj\NeHeProgs\XX_Spec paths (XX in range 01-48) have been borrowed from the original NeHe site and modified by the author for UNICODE coding in Win32 MSVS-15 pro environment. I've tried not to change these codes as far as possible.

Special source codes for the lessons X4 and X5 in the WIN_GLproj\NeHeProgs\X4_Spec and in the WIN_GLproj\NeHeProgs\X5_Spec have been developed by the author.

Just a few changes have been made in Special source codes files from the previous article due to the platform change from MFC to Win32;

3.4. WIN_GLproj\GlobUse

Source codes in WIN_GLproj\GlobUse path have been developed by the author based on the standard Win32 Application Wizard technologies:

  • GLRoutine.cpp - compulsory to be used in the project
  • GlobTexture.cpp - to be used in GL Texture procedures (instead of former Glaux.lib library used in original projects)
  • DlgAbout.cpp, DlgHelp.cpp, DlgLesson.cpp, DlgTitle.cpp - appended for demo purposes only by the author and are not compulsory for the main project implementation
  • JoystickWin32Dlg.cpp, JoystickHelpDlg.cpp, ClassWinResent - appended in demo purposes by the author for Joystick use demonstration only and are not compulsory for the main projects implementation
  • GlobDrawGL.cpp - created for demo purposes only by the author for external links between the project and separate lesson and is not compulsory for the main project implementation

Just a few changes have been made in GlobDrawGL.cpp from the previous article due to the platform change from MFC to Win32; all the other files have been developed new for Win32 platform (nothing special, just routine).

3.5. WIN_GLproj\Data

Data files for the separate lessons in the WIN_GLproj\Data\XX_Data paths (XX in range 06-47) have been borrowed from the original NeHe site.

Data files for the lessons X4 and X5 in the WIN_GLproj\Data\X4_Data and in the WIN_GLproj\Data\X5_data have been created by the author.

Nothing has been changed in Data Files from the previous article.

3.6. WIN_GLproj\HelpText

Help texts for the separate lessons in the WIN_GLproj\HelpText\XX_GLhelp.txt and WIN_GLproj\HelpText\XX_JoystickHelp.txt files have been created by the author to be used in DlgHelp.cpp, JoystickMFCHelpDlg.cpp. in DlgHelp dialog and in DlgJoystickHelp dialog.

ReadMe texts for the separate lessons in the WIN_GLproj\HelpText\ReadMe\ReadMe_XX.txt and WIN_GLproj\HelpText\XX_JoystickHelp.txt files have been borrowed from the original NeHe site to be used in DlgAbout dialog.

Nothing has been changed in ReadMe texts from the previous article.

3.7. WIN_GLproj

Resource files WIN_GLproj path have been created borrowed from the previous article with a few changes regarding the name of the application:

  • WIN_GL.rc and resource.h - menu, dialog, accelerator resources created by the author using the standard Resource Wizard procedures;

4. Code Explanations

The control flow-chart of the standard OpenGL application with the steps numerated as per items of these sections accordingly:

4.1. Windows Initialization in Win32 Platform

The standard MFC Application Wizard provides both CMainFrame and CChildWindow windows. The standard Win32 Application Wizard provides just one window template.

Therefore, the InitGLWindow procedure has been inserted by the author into the standard Initinstance procedure:

C++
 BOOL InitGLWindow(void)                     //initialization of the Child GL Window
{
	_tgetcwd(m_rootDir, _MAX_PATH);          //Get root path of the application 
	SummaryListLessons();                    //Create List of Lessons available
	InitClassUseResent();			         //Initialization of the MRU lessons handling	
	InitMRU(m_hMainWnd);                     //Search for recently called lessons  

	while (hTool == NULL)			         //Tool Bar and Status bar initialization 
		CreateToolBar(m_hMainWnd);
		ShowToolStatus();

	RECT rect;
	GetWindowRect(m_hMainWnd, &rect);        //Initial sizes od the Main Frame
	m_boxWidth = rect.right - rect.left;
	m_boxHeight = rect.bottom - rect.top;

	//Create Child window handle m_hGLwnd:
	if (!CreateChildWindow(_T(""), m_boxWidth, m_boxHeight, m_bits, fullscreen))
		return FALSE;

	//GL window creation(borrowed from NeHe samples);
	if (!CreateGLWindow(m_bits, m_boxWidth, m_boxHeight))
		return FALSE;                         // Quit If Window Was Not Created

	return TRUE;
}

In MFC platform, the procedures of adjusting of the Main Frame, Child window, Tool Bar, Status Bar are embedded in building process.

In Win32 platform, special procedures are required for adjusting of the Main Frame, Child window, Tool Bar, Status Bar with the WM_SIZE message in the WndProc:

C++
case WM_SIZE:
	WndGLProc(hWnd, message, wParam, lParam);
	AdjustChildToRect();         //Adjusting Child GL window sizes to the Main Frame
	break;

4.2. Create GL Window

The procedure CreateGLwindow is common to all the lessons and located in GLRoutine.cpp file in the common GlobUse directory.

The procedure CreateGLWindow are to be called while initialization procedure InitGLWindow. The CreateGLWindow procedure has almost completely has been borrowed from the original NeHe lessons and as much as possible, I've tried not to change the authoring codes.

4.3. Init Application

Initialization procedure to be called in the procedure CreateGLWindow:

C++
if (!InitGL())                // Initialize Our Newly Created GL Window
{
	KillGLWindow();	          // Reset The Display
	MessageBox(NULL, _T("Initialization Failed."), _T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
	exit(0);
}

InitGL initialization of the OpenGL window procedure (located in GlobUse\GlobDrawGL.cpp) refers to the initialization procedure InitGL_XX(GLvoid) of the current lesson located in the NeHeDrawInit\XX_*DrawInit.cpp. These initialization procedures have been borrowed from the NeHe site. I've tried not to change this code as far as possible.

The only big difference is that I've taken the liberty to exclude is the Glaux.lib library from all the lessons used for the texture initialization. Nevertheless, I hope the authors of the original code will not complain. Surely they could not expect MS VS developers that the Glaux.lib library to be excluded from 10th version onwards. And if it is still possible to include Glaux.lib in the MS VS 10th version in the 11th version, it is not working.

The procedures for the texture initialization instead of Glaux.lib are located in the Globuse\GlobTexture.cpp. The instructions for the texture initialization may be obtained from my former CodeProject articles "Texture Mapping in OpenGL using Class CImage" and "Masking Texture in OpenGL using Class CImage".

4.4. Resize GL Window

Procedure ResizeGLScene is common to all the lessons to be called with the WM_SIZE message in the WndGLProc:

C++
case WM_SIZE:                                       // Resize The OpenGL Window
{
	ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));  // LoWord=Width, HiWord=Height
	return 0;                                       // Jump Back
}

In distinct from the NeHe original base some global variables inserted:

C++
GLfloat  fNearPlane = 0.1f, //Frustum Near Plane
fFarPlane = 100.f,          //Frustum Far Plane
fViewAngle = 45.f,          //Frustum View Angle
fAspect;                    //Frustum Width/Height ratio
int m_boxWidth = 800;       //GL window width 
int m_boxHeight = 600;      //GL window height

In some lessons (30,31,34,36,44,45,46,X4), the Frustum values set differ from default ones in the InitGL_XX procedure.

In lessons 21 and 24, the glOrtho presentation has been used:

C++
if(m_bOrtho)
	 glOrtho(0.0f,width,height,0.0f,-1.0f,1.0f);	// Create Ortho (0,0 At Top Left)
else                                            	// Calculate The Aspect Ratio Of The Window
	gluPerspective(fViewAngle,(GLfloat)width/(GLfloat)height,fNearPlane,fFarPlane);

4.5. Draw GL Scene

OpenGL drawing procedure to be called with the WM_PAINT message in the WndGLProc:

C++
case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(m_hGLwnd, &ps);
	    DrawGLScene();
        EndPaint(m_hGLwnd, &ps);
    }
    break;

DrawGLScene drawing of the OpenGL window procedure (located in GlobUse\GlobDrawGL.cpp) refers to the drawing procedure DrawGLScene_XX(GLvoid) of the current lesson located in NeHeDrawInit\XX_*DrawInit.cpp. These drawing procedures have been borrowed from the NeHe site. I've tried not to change these codes as much as possible.

4.6. Messages Handling

Keyboard procedures handling to be called with the WM_KEYDOWN and WM_KEYUP messages in the WndGLProc :

C++
case WM_KEYDOWN:                            // Is A Key Being Held Down?
{
		HandleKeyboard(int(wParam));        //Key code handling
		return 0;                           // Jump Back
}
case WM_KEYUP:                              // Has A Key Been Released?
	{
		ProcessKeyUpN(int(wParam));
		return 0;                   // Jump Back
	}

ProcessKeyboard and VkKeyUpN keyboard commands handling procedures(located in GlobUse\GlobDrawGL.cpp) refer to the keyboard procedure ProcessKeyboard_XX(int idKey) and VkKeyUp_XX of the current lesson located in the NeHeDrawInit\XX_*DrawInit.cpp. These keyboard commands have been borrowed from the NeHe site. I've tried not to change these commands as far as possible. Just F1 command I've changed for Help performance and Ctrl+Enter command changed to FullScreen Mode handling .

Mouse procedures handling to be called Mouse procedures handling to be called with the WM_MOUSEMOVE, WM_LBUTTONDOWN and WM_RBUTTONDOWN messages in the WndGLProc :

C++
case WM_MOUSEMOVE:
{
	POINT point = { LOWORD(lParam), HIWORD(lParam) };
	mouse_x = point.x;
	mouse_y = point.y;
	isClicked = (LOWORD(wParam) & MK_LBUTTON) ? true : false;
	isRClicked = (LOWORD(wParam) & MK_RBUTTON) ? true : false;
	MouseMoveN(LOWORD(wParam), point);
}
break;
case WM_LBUTTONDOWN:
{
	POINT point = { LOWORD(lParam), HIWORD(lParam) };
	mouse_x = point.x;
	mouse_y = point.y;
	LButtonDown(mouse_x, mouse_y);
	isClicked = TRUE;
}
break;
case WM_RBUTTONDOWN: isRClicked = TRUE; break;

MouseMoveN, LButtonDown mouse commands handling procedures (located in GlobUse\GlobDrawGL.cpp) refer to the mouse handling procedures MouseMove_XX, LButtonDown_XX of the current lesson located in NeHeDrawInit\XX_*DrawInit.cpp. These mouse commands have been borrowed from the NeHe site. I've tried not to change these commands as far as possible.

Timer procedure handling to be called with the WM_TIMER message in the WndGLProc :

C++
case WM_TIMER:
if (m_bPlay)
switch (LOWORD(wParam))
{
case ID_TIMER:
		::UpdateScene();
		DrawGLScene();
		break;
}
break;

UpdateScene procedure for one step image change (located in GlobUse\GlobDrawGL.cpp) refers to the procedure Update_XX of the current lesson located in NeHeDrawInit\XX_*DrawInit.cpp. These update procedures have been borrowed from the NeHe site. I've tried not to change these procedures as much as possible.

4.7. Kill GL Window

If the new lesson in the Lesson Dialog is selected to start at the same window the memory must be released and the OpenGL window to be closed. Also before the application exit, the memory must be released and the OpenGL window must be closed:

C++
case ID_APP_EXIT:
    Deinitialize();
    KillGLWindow();
    DestroyWindow(hWnd);
break;

DeinitializeN procedure for clear memory (located in GlobUse\GlobDrawGL.cpp) refers to the procedure Deinitialize_XX of the current lesson located in the NeHeDrawInit\XX_*DrawInit.cpp. These clear memory procedures have been borrowed from the NeHe site. I've tried not to change this procedure as much as possible.

The procedure KillGLwindow is common to all the lessons and located in the GLRoutine.cpp file in the common GlobUse directory. The KillGLWindow procedure almost completely has been borrowed from the original NeHe lessons and as much as possible, I've tried not to change the authoring codes.

5. Joystick Implementation

Joystick handling available in the lessons 09, 10, 32, 40, X4, X5 in projects, WIN_GL and WIN_GL1. In the WIN_GL0 project, the Joystick functions are not available. The next two steps require to make WIN_GL0 working with the Joystick as in WIN_GL1:

  • Select menu Project->Add Existing Item... and insert GlobUse\JoystickWin32Dlg.cpp and GlobUse\JoystickHelpDlg.cpp into Solution Explorer window;
  • Open WIN_GL0\WIN_GL0\SetName.cpp and put in comments(or just remove) the empty procedure void InitJoystickDlg(void){}.

And that's all (point 2.1 of this article conditions understood). Now the project should be working with the Joystick.

Joystick procedures handling to be called with the WM_INPUT message in the JoystickWin32Dlg.cpp.

HandleJoystickN procedure for Joystick Controls handling (located in GlobUse\GlobDrawGL.cpp) refers to the procedure HandleJoystick_XX of the current lesson located in NeHeDrawInit\XX_*DrawInit.cpp. These procedures have been developed by the author in demo purposes. Lesson 40 Joystick handling, e.g.:

C++
    void HandleJoystick_40(int nx, int ny, int nz, int nzr, int nh, 
    BOOL bButtonStates[], BOOL bButtonPrev[])
{
	ropeConnectionVel = Vector3D(-0.003f*nzr, 0.003f*nx, 0.003f*ny);
}

You may change this existing HandleJoystick_XX code or create yourself as you like.

6. Exceptions (lessons 43 and 47)

Lessons 43 and 47 require some External Libraries installations (point 2.2 of this article) and are not available in the projects, WIN_GL0 and WIN_GL1.

Next two steps require to make them available in the project WIN_GL1 as in WIN_GL:

  • Select menu Project->Add Existing Item... and insert NeHeDrawInit\43_FreeTypeFontsDrawInit.cpp, NeHeDrawInit\47_CGVertexShaderDrawInit.cpp and NeheProgs\43_Spec\freetype.cpp into Solution Explorer window;
  • Open WIN_GL1\WIN_GL1\SetName.cpp and put in comments (or just remove) all the lines containing strings 43 and/or 47.

And that's all ( point 2.2 of this article conditions understood). Now, lessons 43 and 47 are available in the project.

7. Your Own Applications Development Using the Project Provided

The set of lessons provided represents the exciting opportunities for the development of some effective presentations of the applications. These possibilities have been illustrated in the present project with the lessons X4 UFOGame (combined by the author from the original lessons 07, 11, 30, 32, 34) and X5 Boxman (demonstrates the possibility to create the performance just with the drawing entities managed by the primitive text files).

You may pick up all these projects, rename it with the project of my former CodeProject article "MFC Project from Existing Code in One Click" and combine and improve the codes as you like (your references to my code, if any, will be highly appreciated).

Present three projects of the solution provided have been developed one from another just by renaming with the technology above.

Points of Interest and Acknowledgements

The projects above have been developed with the great help of the editor of the Russian site of NeHe Sergey Anisimov whom I thank very much for his kind assistance.

Also many thanks to the respected authors of the original code and their perfect instructions in the lessons articles on NeHe site. They have done their job more than twenty years ago and their programs are still alive in the modern environment of Windows 10 and Win32 MSVS 2015 and their instructions are still valid just with a very few corrections.

The advantages of the Win32 projects over MFC projects of the previous article:

  • smaller size of the applications
  • faster work of the progs
  • Windows XP applications do not require special *.dll files;
  • the code of Win32 platform is almost compatible with the Mobile applications codes

The advantage of the MFC projects of the previous article over the present Win32 projects is that dialogs, messages and tools handling are less labor-consuming.

History

The precursor of this article has been published on the CodeProject in 2014: "Concentration of all the Lessons in Common Win32 Project". After that, I have published some five or six articles on CodeProject and most of them also became the precursors to the present article.

I think that the present article and code are more euphemistical for the program's development.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)