Click here to Skip to main content
13,864,419 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


27 bookmarked
Posted 4 Feb 2014
Licenced CPOL

Concentration of all the Lessons in Common Win32 Project

, 4 Feb 2014
Rate this:
Please Sign up or sign in to vote.
Ssupport for the tutorials and lessons on OpenGL


Some three months ago I published the article of the Lessons integrated in Visual C++ MFC project. With a little bit surprise I've discovered that a lot of people feel something like panic with the words MFC (somebody even called it as a disgust). Nevertheless the idea of OpenGL lessons is fine and the codes this site provided from are applicable in any version of software. Therefore I've done the same job for Win32 Visual C++ Visual Studio 2010-2012 pro.

I believe that concentrations of all the lessons in one common project should be very helpful for all the beginners to commence the OpenGL study. The codes of the lessons arranged closely one by one demonstrate the progression of the procedures from the previous stage to the next one. Also the integration of all the lessons in one common project makes it possible to use and combine procedures from separate lessons and also to develop new applications based on original lessons.

While adapting the code to the modern versions of Visual C++, I’ve found some conflicts occurred in projects modified from one version of MS Visual Studio to another. Finally for demonstration purposes, I’ve developed the project OpenGLWin32_2010. Here 2010 means that project has been developed for Microsoft Visual Studio Professional 2010. Nevertheless, all the projects easily jump into version 2012, but for this version Windows 7 is required while version 2010 is available for Windows XP SP3 and higher.

The project above has 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.

The code above may give a great help for people who want to study Visual C++ from the beginning. Needless to say that the best way to study any compiler is to start learning with some working projects. Presentation of this lesson refers to Visual Studio 2010 pro. However, there will not appear too many differences in version 2012.

The content of the OpenGLWin32_2010 directory is as follows:

  • OpenGLWin32 - the empty project containing the projects of all the lessons
  • Lesson01..X5 - projects of every separate lesson
  • GLSummary - project containing all the lessons
  • Data - source data for all the lessons
  • NeHeProgs - the main and auxiliary codes of the lessons
  • GlobUse - procedures common to all the lessons
  • DemoLessons - all executable files of all the lessons
  • HelpText - help and info files for all the lessons

For code view and edition OpenGLWin32.sln file to be started. Even if you have no experience of using Visual C++, you may commence to learn it by starting this (or any other enclosed) project.

The list of the procedures used in the project to be found by menu View->Solution Explorer. Just select any *.h or *.cpp file and you may look at it and edit. At first sight, it may seem that there are too many files enclosed but further consideration shows that everything is not too complicated.

To build all the projects, just start building (menu Build->Build Solution). If everything is done right, the report in the Output window your results must be: 49 succeeded, 3 failed, 0 skipped.

The failed projects are OpenGLWin32 itself (it has no entry point) and Lesson43/Lesson47. To my regret, I have not mu?h experience OpenGL handling and two of the lessons I’ve failed to adapt to modern versions of the Visual C++. I hope that for the respected authors of the original codes will not be difficult to improve my codes to fit them completely to their original intentions.

To start any project, just appoint one as starting (right mouse click – menu Appoint As Starting Project) and select menu Debug->Start Without Debugging. If everything is done right, the demonstration of the corresponding lesson will commence. If you appoint the GLSummary project as starting one of the lessons to be commenced (the lesson whose name is stored in LastNum.txt file in LessonsGL/GLSummary directory). For any other lesson demonstration, select menu File->Lesson... The Select Lesson dialog to be appeared:

You may select any other lesson from the list for demonstration. If you start working from the single lesson the program calls the lesson selected and after that kills itself. If you start from GLSummary the program just calls the selected lesson contained. Lesson43/Lesson47 also available to start, but you can not call other lessons from them: these are original .exe files.

For the independent application creation:

  • Create a new directory (say, GLTest);
  • copy all *. exe programs (located in ../lesson*/Release and ../GLSummary/Release directory) into this new directory;
  • copy Data and HelpText directories into this new directory and the applications are ready for use and they must work exactly as the programs in DemoLessons directory.

The procedures CreateGLWindow, ResizeGLScene, WndProc and GlobWinMain are common to all the lessons and located in the GlobUse/GLRoutine.cpp file.

The procedure CreateGLWindow is almost the same as the original in NeHe's tutorials.

In the procedure ResizeGLScene a few modifications occurred:

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)      // Resize And Initialize The GL Window
        if (height==0)                                      // Prevent A Divide By Zero By
               height=1;                                       // Making Height Equal One
        glViewport(0,0,width,height);                       // Reset The Current Viewport
        glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
        glLoadIdentity();                                   // Reset The Projection Matrix
         glOrtho(0.0f,width,height,0.0f,-1.0f,1.0f);        // Create Ortho View (0,0 At Top Left)
        // Calculate The Aspect Ratio Of The Window
        glMatrixMode(GL_MODELVIEW);                         // Select The Modelview Matrix
        glLoadIdentity();                                   // Reset The Modelview Matrix
HWND hWin = GetDlgItem(hWnd, IDC_MAIN_TOOL);
if(hWin != NULL)
{                                                       //ToolBar Adjusted to Main window
        RECT rect;
    GetWindowRect(hWin, &rect);  
        BOOL bVisible = IsWindowVisible(hWin);
        MoveWindow(hWin, rect.left,, rect.bottom -, width, TRUE);                                         
HWND  hSt = GetDlgItem(hWnd, IDC_MAIN_STATUS);
if(hSt != NULL)
{                                                       //StatusBar Adjusted to Main window
        RECT rect;
    GetWindowRect(hSt, &rect);  
        BOOL bVisible = IsWindowVisible(hSt);
        MoveWindow(hSt, rect.left, height + - rect.bottom, rect.bottom -, width, TRUE);                                                

m_boxWidth =  width;    //remember thr current width and height in global variables. 
m_boxHeight = height;

In the gluPerspective procedure, the global variables fViewAngle,fNearPlane,fFarPlane appeared. In most lessons, the default values:

fViewAngle = 45; fNearPlane = <st1:metricconverter
ProductID="0.1f" w:st="on">0.1f</st1:metricconverter>; fFarPlane = 100;

are to be used. However in the lessons 30,31,34,36,44,45,46, these values are to be changed.

Also the global variable m_bOrtho arranges the glOrtho performance if required (lessons 21 and 24).

The TollBar and StatusBar are adjusted to main window while ResizeGLScene.

The procedures WndProc and GlobWinMain also have had some changes due to extra dialogs and bars handling. You may take a look at these changes in the GlobUse/GLRoutine.cpp - nothing special, just routine.

Full screen view in difference with the original lessons occurred by simultaneously pressing Ctrl+Enter.

F1 key in difference with the original lessons is used for standard purpose for help call (menu Help->Help Dialog...)

Help Dialog window is non-modal, thus the program handling may be performed as from this window and/or by the other ways. All help information is stored in HelpText directory as simple text files.

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

This About Dialog is also available from another Lesson and

with the About... button.

One more difference with the original lessons is that all the texture procedures are integrated in GlobGLTexture.cpp file in GlobUse directory. Just instead of auxDIBImageLoad for texture loading I've arranged procedures as follows using class CImage:

HBITMAP GetImgBitmap(CImage * nImg)
        if(nImg == NULL)
           return NULL;
        CImage * pImg = new CImage;
        pImg->Create(nImg->GetWidth(),nImg->GetHeight(), 24);
        HDC hdc = CreateCompatibleDC(pImg->GetDC());
        HBITMAP hbm = CreateCompatibleBitmap(pImg->GetDC(), pImg->GetWidth(), pImg->GetHeight());
        HBITMAP bmOld = (HBITMAP) SelectObject(hdc,hbm);
        pImg->BitBlt(hdc, CPoint(0,0));
        delete pImg;
        return hbm;
HBITMAP LoadMyBitmap(char * fName)
                 char strk[_MAX_PATH];
                 _getcwd(str, _MAX_PATH);
                 sprintf_s(strk, "LoadMyBitmap\nNo File exist:\n%s\nin Directory:\n%s", fName, str);
                 MessageBox(NULL, strk, "No File:", MB_OK | MB_ICONINFORMATION); 
                 return NULL;
  CImage * pImg = new CImage; 
   HBITMAP bm = GetImgBitmap(pImg);
               delete pImg;
    pImg = NULL;
  return bm;

You may copy GlobGLTexture.cpp file and use it for any projects using OpenGL development with all kind of image files that Windows has available.

The lesson's codes themselves are concentrated in NeHeProgs directory and commenced from "01_", "02_",..."X5_" in correspondence with the lesson number. These are the codes presented in NeHe’s GameDev site (Grant James) and as far as possible I’ve tried not to change the code while adapting to modern versions of Visual Studio.

The only big difference is that I dare to exclude Glaux.lib library from all the projects. Nevertheless, I hope the authors of the original code will not complain. Sure they could not expect from MS VS developers that 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 concentrations of all the procedures in one common directory GlobUse make it possible to use and combine common procedures in separate lessons and also to develop new applications based on original lessons. The samples of application development are presented in projects lessonX4/UFOgame and lessonX5/BoxMan. Lesson X4.UFO Games are combined from the lessons 07, 11, 30, 32, 34. Lesson X5.BoxMan demonstrates the possibility of figures and their movements creation in outer text files and the user need not know programmer details, space imagination enough.

And this LessonX5 shows one problem due to simultaneous use of <windows.h> and <afxwin.h>. The conflict occurred was deprecated in Properties Window Configuration Propeties->Linker->General->Force Output. The error is gone but the warning still remains and EXE file occurred to be very large. In MFC platform, no problems occurred.

I think that the idea of OpenGL study with the help of the ready working projects completely fit to the people’s tutorial on OpenGL. I hope that the projects provided should arrange a good support for the tutorials and lessons on OpenGL.


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


About the Author

Petrov Vladimir
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionA couple of lessons act differently Pin
Mike Riley - QUSA18-Feb-14 14:44
memberMike Riley - QUSA18-Feb-14 14:44 
AnswerRe: A couple of lessons act differently Pin
Mike Riley - QUSA18-Feb-14 14:45
memberMike Riley - QUSA18-Feb-14 14:45 
AnswerRe: A couple of lessons act differently Pin
Petrov Vladimir18-Feb-14 16:02
mvaPetrov Vladimir18-Feb-14 16:02 
QuestionIs the download link of "demo and source" broken? Pin
Member 423053210-Feb-14 20:48
memberMember 423053210-Feb-14 20:48 
AnswerRe: Is the download link of "demo and source" broken? Pin
Petrov Vladimir11-Feb-14 12:07
mvaPetrov Vladimir11-Feb-14 12:07 
QuestionLink to MFC project(s) Pin
Petrov Vladimir10-Feb-14 12:16
mvaPetrov Vladimir10-Feb-14 12:16 
QuestionA link to another article? Pin
Victor Nijegorodov10-Feb-14 0:36
memberVictor Nijegorodov10-Feb-14 0:36 
GeneralRe: Spam Pin
pwasser4-Feb-14 15:45
memberpwasser4-Feb-14 15:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 4 Feb 2014
Article Copyright 2014 by Petrov Vladimir
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid