How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio
Many programmers prefer OpenGL for graphics. If you are one of them, you are strongly advised by its producer, to use a window toolkit (such as SDL) and an OpenGL loading libraries (such as GLEW). This guide will help you get over the...
Method 1 of 8:
Downloading SDL and GLEW
- Highlight what you expect to do. Highlight step or sub-step or part of it and then do it. For example see picture above.
- Create folder GL. In directory (disk) C:, right click > select New > Folder > type GL > hit ↵ Enter.
- 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) .
- Download the version for Visual C++. Today it is the SDL2-devel-2.0.10-VC.zip (Visual C++ 32/64-bit).
- In the window where it is downloaded, click SDL2-2.0.10 (or the latest) > right click > select Copy.
- Navigate (always by double click) to C: > GL > select Paste.
- Click on name SDL2-2.0.10 and rename it to SDL2.
- If the folder SDL2-devel-2.0.10-VC is downloaded, double click it to get SDL2-2.0.10.
- 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.
- In the window where it is downloaded, click folder glew-2.1.0 > right click > select Copy.
- Navigate to C: > GL > right click > select Paste. Rename glew-2.1.0 to glew.
- 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
- Create an empty project.
- With Visual Studio 2017
- In V.S. main menu, click File. Then go to New > Project…
- In the left part of the new project window, click Visual C++ if it is not clicked.
- In the center of the screen click Empty Project.
- Below that, find the Name text box, type Project-0.
- Next to Location text box, click Browse... and navigate to C: > GL.
- Click Select a folder. The Location in New Project window is C:GL.
- Make sure the Create directory for solution box is not checked.
- Click OK.
- With Visual Studio 2019
- If it's not opened. Open it > Click Create a new project > Empty Project > Next.
- In Configure your new project wizard, for "Project name", type: Project-0. Next to "Location" text field click ....
- Navigate to C: > GL > click Select folder. Now "Location" is C:GL.
- Check "Place solution and project in the same directory" > click Create.
- Wait till Visual Studio 2019 instance appears.
- If it has already been opened. Click File > New > Project… > Empty Project > Next. The rest as above.
- With Visual Studio 2017
- Add your source file to the Project.
- In the Solution Explorer window, right click the Source Files entry (the last one) > select Add > New Item….
- 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.
- The Location is C:GLProject-0.
- 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
- 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).
- Additional Include Directories.
- Copy C:GLSDL2include > in Additional Include Directories wizard click first icon > paste.
- Copy C:GLglewinclude > click again the first icon > paste > click OK on Additional Include Directories wizard.
- 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.
- Copy this C:GLSDL2libx86 > in Additional Library Directories click first icon > paste.
- Copy this C:GLglewlibReleaseWin32 > click first icon > paste > click OK.
- 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.
- 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.
- 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.
- 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.
- Additional Include Directories.
- Put "dll" files in the project-folder.
- Copy SDL2.dll file and paste to Project-0 folder.
- Navigate to C: > GL > SDL2 > lib > x86. Inside x86 folder click SDL2.dll file > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- 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.
- Copy glew32.dll file and paste to Project folder
- Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- 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.
- Copy SDL2.dll file and paste to Project-0 folder.
Method 4 of 8:
Testing your Project
- 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.
- Correct errors if any. In "Error List" if you see error about
- file with extension .h go to part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
- file with extension .lib go to sub-step "Configure the linker "Additional Library Directories"", and follow instructions. Also to "Additional Dependencies"".
- "entry point must be defined" go to sub-step "SubSystem" and follow instructions.
- file .dll go to step 2, "Put "dll" files in the project-folder" and follow instructions.
- 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
- Create template.
- Go to main menu and, while Project-0 is open, click Project > Export Template....
- On Export template Wizard check Project Template, if it's not checked. Click Next >.
- On Select Template Options, in Template name text box type: OpenGL-SDL-GLEW. Click Finish.
- Template has been created.
- Create project
- With V.S. 2017. Click File > New > Project....
- On the New Project window, click template: OpenGL-SDL-GLEW.
- In Name text field, type: Project-1.
- Next to Location text field click ... > navigate C:GL. Folder text box should be C:GL. Click Select a folder.
- Be sure Create directory for solution is unchecked. Click OK.
- With V.S. 2019. Click File > New > Project....
- In Create a new project wizard scroll down the list of templates and select OpenGL-SDL-GLEW > click Next.
- In Configure your new project wizard, in "Project name" text field type Project-1.
- Next to Location text field click ... > navigate C:GL. Folder text box should be C:GL. Click Select a folder.
- Be sure Place solution and project in the same directory is checked. Click Create.
- On Solution Explorer, double click Source Files > double click ++Main.cpp.
- If its code appears, it's okay. If does not, right click on it > click Exclude From Project, and create new Main.cpp file.
- 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.
- With V.S. 2017. Click File > New > Project....
- Add SDL2.dll file to new project-folder
- Navigate to C: > GL > Project-0 > click file SDL2.dll > right click > click Copy.
- Navigate to C: > GL > Project-1 > click on empty area > right click > click Paste.
- Now file SDL2.dll is in folder Project-1 among Main.cpp and other 4 files.
- Add glew32.dll file to new project-folder
- Navigate to C: > GL > Project-0 > click file glew32.dll > right click > click Copy.
- Navigate to C: > GL > Project-1 > click on empty area > right click > click Paste.
- Now file glew32.dll is in folder Project-1 among with SDL2.dll, Main.cpp and other 4 files.
- Test your project as above. Good job.
- TIP: Remember copy dll files from previous project and paste in new one.
Method 6 of 8:
Creating project to target x64 platform
- Create empty project as above with name Project-2, and add Main.cpp file.
- 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...
- In Active solution platform: select x64
- In Platform entry select x64
- Click Close
- Additional Include Directories. As with targeting x86 platform, see Method 3 step 1.
- 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.
- Copy this C:GLSDL2libx64 > in Additional Library Directories click first icon > paste.
- Copy this C:GLglewlibReleasex64 > click first icon > paste > click OK.
- Additional Dependencies. As with targeting x86 platform, see Method 3, step 1.
- Subsystem. As with targeting x86 platform, see Method 3, step 1.
- Copy dll files and paste into Project-2.
- Copy SDL2.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
- C: > GL > SDL2 > lib > x64. In "x64" folder click "SDL2.dll" file > right-click > "Copy".
- C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
- Copy glew32.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
- C: > GL > glew > bin > Release > x64. In "x64" folder click "glew32.dll" file > right-click > "Copy".
- C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
- Copy SDL2.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
- Test project and correct errors if any. As with targeting x86 platform, see Method 4.
- Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
- Create template. As above.
- 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
- 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.
- 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.
- 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.
- In downloading window click zip folder SDL2-2.0.10.zip (or latest version) > right click > select Copy.
- In File Explorer navigate to C: > GL > right click > select Paste. Click twice on folder's name > delete name > type: SDL > hit ↵ Enter.
- Download GLEW source. Right-click on following address and select Open Link in New Window http://glew.sourceforge.net/. Beside Source click ZIP.
- In download in window click folder glew-2.1.0 (or latest) > right click > Copy.
- 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.
- Build SDL by CMake and Visual Studio. Go to CMake GUI.
- Copy C:/GL/SDL and paste in first text field.
- Copy C:/GL/SDL/build and paste in second text field.
- Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > select Visual Studio 16 2019 > click Finish.
- When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
- Build your solution.
- 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".
- Wait till you read the last line in "Output" window: ========== Build: XX succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
- Number XX of "succeeded" changes in freeglut versions. Today (11-Feb-2020) is 5.
- Navigate to C:GLSDLbuildDebug. Inside you should see file SDL2d.lib.
- Build GLEW by CMake and Visual Studio. Follow above step but
- In first text field paste C:/GL/glew/build/cmake
- In second paste C:/GL/glew/build
- Navigate to C: > GL > glew > build. Double click "glew.sln", or "glew", or "ALL_BUILD.vcxproj".
- In V.S. Output wizard, number of succeeded today (31-1-2020) is 6, may change in later version though.
- Navigate to C: > GL > glew > build > lib > Debug. Inside you should see file glew32d.lib among two other files.
- Set up built SDL and built GLEW in project.
- Create empty project and add source file according to Method 2.
- Configure project's Properties. In Solution Explorer wizard, right click Project's name that is Project-0 > select Properties.
- (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- In Active solution platform: select x64.
- In Platform entry, x64 is automatically selected.
- Click Close.
- (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 ...
- Navigate to C: > GL > SDL > include > click include > click Select a folder.
- Click again first icon > three dots > navigate to C: > GL > glew > include > click include > click Select a folder > click OK.
- (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.
- Copy C:GLSDLbuildDebug and paste in upper-most text field.
- Copy C:GLglewbuildlibDebug > click again first icon > paste in upper-most text field > click OK.
- (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) 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.
- (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- Copy files SDL2d.dll and glew32d.dll, and paste into Project-0 folder.
- Navigate to C:GLSDLbuildDebug. Click SDL2d.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- Navigate to C:GLglewbuildbinDebug. Click glew32d.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- 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.
- Test your project and correct errors if any. As above, Method 4.
- 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
- In this tutorial you learn 3 was to set up SDL and GLEW in Project with Visual Studio.
- Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
- Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
- Compile SDL source, GLEW source, and set up them in project. Targets x64 too.The most difficult. The best though.
3.8 ★ | 9 Vote
You should read it
- How to Create an Executable File from Eclipse
- How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio
- How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio
- How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio
- How to Open an MPP File on PC or Mac
- How to Set Up SFML in a Project on Visual Studio
- Toshiba will be the main supplier for Project Ara
- How to Set Up SDL with Visual Studio
- How to Add JARs to Project Build Paths in Eclipse (Java)
- Latest Project XL code and how to enter Project XL code
- How to Play Sounds for Calendar Notifications on a Mac
- How to Make a Bug in GIMP
Maybe you are interested
5 popular Auto Click software for computers today
Latest Roblox Clicker Simulator Codes 12/2024
How to use GS Auto Clicker, automatically click mouse on computer
How to use Auto Clicker Assist to automatically click the mouse
Instructions to fix double click error on computer mouse - Click once becomes twice
PowerToys will soon support creating app spaces and launching with just one click