Method 1 of 8:

Downloading SDL and GLEW

  1. How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 1
    Highlight what you expect to do. Highlight step or sub-step or part of it and then do it. For example see picture above.
  2. Create folder GL. In directory (disk) C:, right click > select New > Folder > type GL > hit Enter.
  3. How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 2
    Download the SDL2. Right click on following link and select Open Link in New Window https://www.libsdl.org/download-2.0.php. Scroll to the bottom of the page and find Development Libraries (see picture above) .
    1. Download the version for Visual C++. Today it is the SDL2-devel-2.0.10-VC.zip (Visual C++ 32/64-bit).
    2. In the window where it is downloaded, click SDL2-2.0.10 (or the latest) > right click > select Copy.
    3. Navigate (always by double click) to C: > GL > select Paste.
      1. Click on name SDL2-2.0.10 and rename it to SDL2.
    4. If the folder SDL2-devel-2.0.10-VC is downloaded, double click it to get SDL2-2.0.10.
  4. Download the GLEW. Right click on following link and select Open Link in New Window http://glew.sourceforge.net/. Below Downloads find Binaries and click Windows 32-bit and 64-bit.
    1. In the window where it is downloaded, click folder glew-2.1.0 > right click > select Copy.
    2. Navigate to C: > GL > right click > select Paste. Rename glew-2.1.0 to glew.
    3. If folder glew-2.1.0-win32 is downloaded, double click it for get glew-2.1.0.
Method 2 of 8:

Creating a Visual Studio Project

  1. Create an empty project.
    1. With Visual Studio 2017
      1. In V.S. main menu, click File. Then go to New > Project…
      2. In the left part of the new project window, click Visual C++ if it is not clicked.
      3. In the center of the screen click Empty Project.
      4. Below that, find the Name text box, type Project-0.
      5. Next to Location text box, click Browse... and navigate to C: > GL.
      6. Click Select a folder. The Location in New Project window is C:GL.
      7. Make sure the Create directory for solution box is not checked.
      8. Click OK.
    2. With Visual Studio 2019
      1. If it's not opened. Open it > Click Create a new project > Empty Project > Next.
      2. In Configure your new project wizard, for "Project name", type: Project-0. Next to "Location" text field click ....
      3. Navigate to C: > GL > click Select folder. Now "Location" is C:GL.
      4. Check "Place solution and project in the same directory" > click Create.
      5. Wait till Visual Studio 2019 instance appears.
      6. If it has already been opened. Click File > New > Project… > Empty Project > Next. The rest as above.
  2. Add your source file to the Project.
    1. In the Solution Explorer window, right click the Source Files entry (the last one) > select Add > New Item….
    2. In the Add New Item - Project-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In Name text box type Main.cpp.
    3. The Location is C:GLProject-0.
    4. Click the Add button. The file will open in the main text editor but leave the file blank for now.
Method 3 of 8:

Installing SDL and GLEW in Project

  1. How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 3
    Configure project's Properties. In Solution Explorer right click on the name of your project, that is Project-0, and select Properties. Leave default settings: Configuration: Active(Debug), and Platform: Active(Win32).
    1. Additional Include Directories.
      How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 4
      Open the C/C++ drop-down menu. Click General > Additional Include Directories > down arrow at the right of the field > click in the drop down menu.
      1. Copy C:GLSDL2include > in Additional Include Directories wizard click first icon > paste.
      2. Copy C:GLglewinclude > click again the first icon > paste > click OK on Additional Include Directories wizard.
        How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 5
    2. Additional Library Directories. Open the "Linker" drop-down menu, and click "General". Click "Additional Library Directories" entry > down arrow at the end of the field > "Edit" in the drop-down menu.
      How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 6
      1. Copy this C:GLSDL2libx86 > in Additional Library Directories click first icon > paste.
      2. Copy this C:GLglewlibReleaseWin32 > click first icon > paste > click OK.
    3. Additional Dependencies. In the "Linker" drop-down menu, click "Input" > the "Additional Dependencies" entry > down arrow at the right of the field > "Edit" in the drop-down menu.
      How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 7
      1. Copy this SDL2.lib; SDL2main.lib; glew32.lib; opengl32.lib and paste on the topmost text box of the Additional Dependencies wizard > click OK in the Additional Dependencies wizard.
        How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 8
    4. SubSystem.In the "Linker" drop-down menu, click "System" > "SubSystem" > down arrow > select "Windows (/SUBSYSTEM:WINDOWS)" from the dropdown menu. Click Apply > OK on the "SDLproject Property Pages" wizard.
      How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 9
  2. Put "dll" files in the project-folder.
    1. Copy SDL2.dll file and paste to Project-0 folder.
      1. Navigate to C: > GL > SDL2 > lib > x86. Inside x86 folder click SDL2.dll file > right-click > Copy.
      2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
      3. The SDL2.dll file should now be in your project directory along with your Main.cpp file and 4 other files created by Visual Studio.
    2. Copy glew32.dll file and paste to Project folder
      1. Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
      2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
      3. The glew32.dll file should now be in Project-0 folder along with Main.cpp, SDL2.dll, and 4 other files created by Visual Studio.
Method 4 of 8:

Testing your Project

  1. How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio Picture 10
    Download the code. Right click on following link and select Open Link in New Window http://lazyfoo.net/tutorials/SDL/51_SDL_and_modern_opengl/index.php > Scroll down to last sentence "Download the media and source code for this tutorial here". Click here > download 51_SDL_and_modern_opengl.cpp folder. Double click it > double click file of same name. Its code will appear in Visual Studio by the side of Main.cpp file or in new Visual Studio instance. Copy code (413 lines) and paste on Main.cpp code area > hit Ctrl+F5. If everything is gone well two windows appear: one black and one with title: SDL Tutorial and inside a white square with black background.
  2. Correct errors if any. In "Error List" if you see error about
    1. file with extension .h go to part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
    2. file with extension .lib go to sub-step "Configure the linker "Additional Library Directories"", and follow instructions. Also to "Additional Dependencies"".
    3. "entry point must be defined" go to sub-step "SubSystem" and follow instructions.
    4. file .dll go to step 2, "Put "dll" files in the project-folder" and follow instructions.
    5. For other errors, if you cannot correct them, close Visual Studio > delete project folder Projetc-0 which lives in C:GL > open Visual Studio > repeat set up from part Method 2. Good job.
Method 5 of 8:

Creating Project with OpenGL-SDL-GLEW Template

  1. Create template.
    1. Go to main menu and, while Project-0 is open, click Project > Export Template....
    2. On Export template Wizard check Project Template, if it's not checked. Click Next >.
    3. On Select Template Options, in Template name text box type: OpenGL-SDL-GLEW. Click Finish.
    4. Template has been created.
  2. Create project
    1. With V.S. 2017. Click File > New > Project....
      1. On the New Project window, click template: OpenGL-SDL-GLEW.
      2. In Name text field, type: Project-1.
      3. Next to Location text field click ... > navigate C:GL. Folder text box should be C:GL. Click Select a folder.
      4. Be sure Create directory for solution is unchecked. Click OK.
    2. With V.S. 2019. Click File > New > Project....
      1. In Create a new project wizard scroll down the list of templates and select OpenGL-SDL-GLEW > click Next.
      2. In Configure your new project wizard, in "Project name" text field type Project-1.
      3. Next to Location text field click ... > navigate C:GL. Folder text box should be C:GL. Click Select a folder.
      4. Be sure Place solution and project in the same directory is checked. Click Create.
    3. On Solution Explorer, double click Source Files > double click ++Main.cpp.
      1. If its code appears, it's okay. If does not, right click on it > click Exclude From Project, and create new Main.cpp file.
      2. If a Wizard appears saying: File 'C:GLProject-1Main.cpp' already exists in the project, go to this path and delete the file Main.cpp. Click OK on the Wizard and then click Add on the Add New Item - Project-1 window. Now on Solution Explore, below Source Files, you have the new ++Main.cpp file.
  3. Add SDL2.dll file to new project-folder
    1. Navigate to C: > GL > Project-0 > click file SDL2.dll > right click > click Copy.
    2. Navigate to C: > GL > Project-1 > click on empty area > right click > click Paste.
    3. Now file SDL2.dll is in folder Project-1 among Main.cpp and other 4 files.
  4. Add glew32.dll file to new project-folder
    1. Navigate to C: > GL > Project-0 > click file glew32.dll > right click > click Copy.
    2. Navigate to C: > GL > Project-1 > click on empty area > right click > click Paste.
    3. Now file glew32.dll is in folder Project-1 among with SDL2.dll, Main.cpp and other 4 files.
  5. Test your project as above. Good job.
  6. TIP: Remember copy dll files from previous project and paste in new one.
Method 6 of 8:

Creating project to target x64 platform

  1. Create empty project as above with name Project-2, and add Main.cpp file.
  2. SDLproject's Properties settings. Go to "Solution Explorer" > right click on the name of your project that is Project-2 > select "Properties". In Platform: entry, choose x64 > Click Configuration manager...
    1. In Active solution platform: select x64
    2. In Platform entry select x64
    3. Click Close
  3. Additional Include Directories. As with targeting x86 platform, see Method 3 step 1.
  4. Additional Library Directories. Open the "Linker" drop-down menu, and click "General". Click "Additional Library Directories" entry > down arrow at the end of the field > "Edit" in the drop-down menu.
    1. Copy this C:GLSDL2libx64 > in Additional Library Directories click first icon > paste.
    2. Copy this C:GLglewlibReleasex64 > click first icon > paste > click OK.
  5. Additional Dependencies. As with targeting x86 platform, see Method 3, step 1.
  6. Subsystem. As with targeting x86 platform, see Method 3, step 1.
  7. Copy dll files and paste into Project-2.
    1. Copy SDL2.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
      1. C: > GL > SDL2 > lib > x64. In "x64" folder click "SDL2.dll" file > right-click > "Copy".
      2. C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
    2. Copy glew32.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
      1. C: > GL > glew > bin > Release > x64. In "x64" folder click "glew32.dll" file > right-click > "Copy".
      2. C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
  8. Test project and correct errors if any. As with targeting x86 platform, see Method 4.
    1. Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
  9. Create template. As above.
    1. TIP: In every project you create with it, select x64 (next to Debug) in Visual Studio's GUI.
Method 7 of 8:

Setting up Built SDL and Built GLEW

  1. In directory C, create folder GL. If folder with this name exists, close Visual Studio > in File Explorer > directory C > right click GL folder > select Delete > again right click > select New > Folder > type: GL > hit Enter.
  2. Install CMake. Right-click on following link and select Open Link in New Window Use CMake to Get Binaries from Source Code. Follow Method 1 Installing CMake.
  3. Download SDL source. Right-click on following address and select Open Link in New Window https://www.libsdl.org/download-2.0.php. Below Source Code: click SDL2-2.0.10.zip or latest version.
    1. In downloading window click zip folder SDL2-2.0.10.zip (or latest version) > right click > select Copy.
    2. In File Explorer navigate to C: > GL > right click > select Paste. Click twice on folder's name > delete name > type: SDL > hit Enter.
  4. Download GLEW source. Right-click on following address and select Open Link in New Window http://glew.sourceforge.net/. Beside Source click ZIP.
    1. In download in window click folder glew-2.1.0 (or latest) > right click > Copy.
    2. Navigate to C: > GL. Right click > Paste. Click twice on folder's name and rename glew > hit Enter. Now in folder GL you have folders SDL and glew.
  5. Build SDL by CMake and Visual Studio. Go to CMake GUI.
    1. Copy C:/GL/SDL and paste in first text field.
    2. Copy C:/GL/SDL/build and paste in second text field.
    3. Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > select Visual Studio 16 2019 > click Finish.
      1. When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
    4. Build your solution.
      1. Navigate to C: > GL > SDL> build. Double click "SDL2.sln", or "SDL2", or "ALL_BUILD.vcxproj". An instance of Visual Studio appears. Wait until in main menu Build entry appears. Click it > "Build Solution".
      2. Wait till you read the last line in "Output" window: ========== Build: XX succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
        1. Number XX of "succeeded" changes in freeglut versions. Today (11-Feb-2020) is 5.
    5. Navigate to C:GLSDLbuildDebug. Inside you should see file SDL2d.lib.
  6. Build GLEW by CMake and Visual Studio. Follow above step but
    1. In first text field paste C:/GL/glew/build/cmake
    2. In second paste C:/GL/glew/build
    3. Navigate to C: > GL > glew > build. Double click "glew.sln", or "glew", or "ALL_BUILD.vcxproj".
    4. In V.S. Output wizard, number of succeeded today (31-1-2020) is 6, may change in later version though.
    5. Navigate to C: > GL > glew > build > lib > Debug. Inside you should see file glew32d.lib among two other files.
  7. Set up built SDL and built GLEW in project.
    1. Create empty project and add source file according to Method 2.
    2. Configure project's Properties. In Solution Explorer wizard, right click Project's name that is Project-0 > select Properties.
      1. (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
        1. In Active solution platform: select x64.
        2. In Platform entry, x64 is automatically selected.
        3. Click Close.
      2. (2) Additional Include Directories. Click C/C++ > General > In beside menu select the first one, Additional Include Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ...
        1. Navigate to C: > GL > SDL > include > click include > click Select a folder.
        2. Click again first icon > three dots > navigate to C: > GL > glew > include > click include > click Select a folder > click OK.
      3. (3) Additional Library Directories. Double click Linker > click General > Additional Library Directories > click the down arrow at the end of the field > click Edit... > first icon.
        1. Copy C:GLSDLbuildDebug and paste in upper-most text field.
        2. Copy C:GLglewbuildlibDebug > click again first icon > paste in upper-most text field > click OK.
      4. (4) Additional Dependencies. In Linker drop-down menu select Input > in beside menu select the first one, Additional Dependencies > click the down arrow at the end of the field > Edit... > copy opengl32.lib; SDL2d.lib; SDL2maind.lib; glew32d.lib and paste in Additional Dependencies wizard's upper-most text box > click OK.
      5. (5) Set System to SubSystem CONSOLE. In Linker drop-down menu select System > in beside menu select the first one, SubSystem > click the down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE). Click Apply and OK.
    3. Copy files SDL2d.dll and glew32d.dll, and paste into Project-0 folder.
      1. Navigate to C:GLSDLbuildDebug. Click SDL2d.dll > right-click > Copy.
      2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
      3. Navigate to C:GLglewbuildbinDebug. Click glew32d.dll > right-click > Copy.
      4. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
      5. Files SDL2d.dll and glew32d.dll should now be in Project-0 folder along with Main.cpp, and 4 other files created by Visual Studio.
  8. Test your project and correct errors if any. As above, Method 4.
  9. Create Template. As above Method 5, but in Visual Studio GUI main menu, select x64. Remember copy and paste dll files.
Method 8 of 8:

Choosing Set Up

  1. In this tutorial you learn 3 was to set up SDL and GLEW in Project with Visual Studio.
    1. Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
    2. Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
    3. Compile SDL source, GLEW source, and set up them in project. Targets x64 too.The most difficult. The best though.
3.8 ★ | 9 Vote | 👨 5865 Views

Above is an article about: "How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio". Hope this article is useful to you. Don't forget to rate the article, like and share this article with your friends and relatives. Good luck!

« PREV POST
NEXT POST »