- Open up Eclipse then start by clicking File >> New >> C++ Project. In the New Project dialog, enter the name of the project (e.g. OpenGLTemplate) and choose the location. While still in the dialog, make sure thatShow Project types and toolchains only if they are supported on the platformis unchecked. SelectEmpty Projectas project type and selectMinGW GCCfrom the among the options in Toolchains. Take a look at Figure 1 below for reference. Afterwards, clickFinish. Figure 1. Options that need to be considered when creating a new OpenGL project. 
- Your project should now be in the Project Explorer pane on the left side Eclipse. Expand the project by double-clicking it. Right-click the project folder, select New >> Source Folderand name the folder assrc.
- Right-click on the newly created srcfolder,New >> Source File. In the dialog that just came up, name the file asmain.cpp. In the template dropdown,Default C++ source template.Then, clickFinish.
- Next, we will need to include a library called GLAD that will make creating OpenGL projects more convenient. Go to the GLAD web service, set the language to C++ and in the API section, select an OpenGL version of at least 3.3, higher versions are ok as well. Also make sure the profile is set to Core and that the Generate a loader option is ticked. You can ignore the extensions for now. Click Generate to produce the resulting library files. You will be provided with a zip file containing two include folders (glad and KHR) and a single glad.cfile.
- Extract the zip file that you got in Step 4 directly into your Eclipse project directory. By this time, your Project directory must now have an include folder that contains two folders namely glad and KHR. Inside your srcfolder, an additional file namedglad.cshould be present. Now go back to your Eclipse IDE and refresh theProject Explorerpane and you should see a similar structure as Figure 2 below. Figure 2. Project Explorer directory structure after adding GLAD libraries. 
- Right-click the main project folder and select  Properties.Go toC/C++ Build >> Settings >> Tool Settings. Click onIncludesunderGCC C++ Compilerthen add a new item toInclude paths (-l). In the dialog window that came up, click theWorkspacebutton, select and expand the current project directory (in this case, OpenGLTemplate), select theincludefolder but not its contents, then click OK. You will be taken back to theAdd directory pathdialog box which should now look like Figure 3, then click OK. Figure 3. Content of "Add directory path" after selecting include folder. 
- While you are still in the Tool Settings pane, click on  Includesbut underGCC C Compilerand do the same thing that you did in Step 6.
- Again, while still in the Tool Settings pane, click on  LibrariesunderMinGW C++ Linkerthen add the following items toLibraries (-l)one by one:glfw3, glew32, freeglut, opengl32, glu32,freeimage. Take note that the order of the entries will matter. YourLibraries (-l)pane should now look like Figure 4. Now, click OK and accept the prompts that will follow to complete the configuration of your project! Figure 4. The Libraries pane of the MinGW C++ Linker after adding the OpenGL libraries. 
- To test the project, copy the code which can be found here, this is code from https://learnopengl.com, a great site to learn OpenGL. After copying the code, go back to your Eclipse project and double-click main.cpp. Paste the code over and then save the file. There might be several error messages right after you paste the code...that is normal since Eclipse is still running the Indexer. The errors should clear once the Indexer is done.
- Now, right-click the Project Folder in the Project Explorer and click Build Project.If the build is successful, you shouldn't see any problems. Click theRunbutton in the toolbar and you should see a window like Figure 5.
 You can press the Figure 5. The LearnOpenGL Window ESCbutton on your keyboard to close the window. And that's it! Head on over to https://learnopengl.com and go over their tutorials. You can skip the topic on configuring Visual Studio, cmake, and compiling GLFW as we took care of that part in this tutorial. Enjoy learning!
Wednesday, July 19, 2017
Setting up Eclipse and OpenGL using MSYS2/MinGW - Part 2
In Part 1 of this tutorial we installed Eclipse, the GCC compiler suite, and the OpenGL libraries that we would use. If you followed through that tutorial, then you be good to go for this tutorial which covers setting up a template project for OpenGL. Let's begin.
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment