Lab 1 – Getting Started



Lab 1 – Getting StartedObjectives: to understand the purpose of header files, lib files, DLLsinstall GLEW and freeglutto be able to configure an OpenGL project in Visual Studio (VS)OverviewSo, where do we begin? Well, through no fault of your own, many of you have never worked with external libraries/APIs in C++. Realistically, you’ve probably had no need to. Given that OpenGL is an external API, it’s time you learned how to work with things like headers, libs and DLLs. The way that I’m going to show you must be done for each new project you create because I want to drill this process into your brain. After that, I might show you how to skip a step or two during setup.In general, here’s the process that I want you to remember:You have to “install” the API/SDK(s) somewhere on your machine (you do this only once)You have to tell VS where the header files are.You have to tell VS which libraries it is going to use.You have to tell VS where those libraries are.You have to move the DLLs into a place where your executable can find them.Headers, Libs and DLLsI’ve probably already talked about headers, libs and DLLs before you started this lab, so if I have and you understand them, feel free to skip to the next section. Also, remember that there is a short video on this topic on YouTube. You don’t have to watch it now, but it’s a good idea to watch it later if you’re still unclear about how these files relate to one another.As a quick overview:Header files have a .h extension and you #include them in your code. They are text files, so you can open them up in Visual Studio and read them. They contain a series of function prototypes that contain no function body. They also contain constants and may contain class definitions. In general, these files tell us which functions are available to call.Library files or just libs are not text files, so you can’t read them. They usually have a .lib extension. They tell us where functions exist in the DLL. You can think of it as an index system; when we call a function, the lib can find the function in the DLL for us. More technically, the lib is a bunch of function pointers into the DLL. Dynamic Link Libraries or DLLs are a series compiled functions, so again, you can’t open them and read them. Remember that the header files contain no code, just prototypes. The DLLs contain the code (i.e. the function bodies).So in summary, we have header files to tell us what functions we can call, lib files that tell us where those functions are in the DLL, and DLLs that contain the compiled functions.Meet our APIs: freeglut and GLEWfreeglutYou’ve probably never had to create a window in C++ using the Windows API. It sucks. It literally takes about 100 lines of code to get a basic application going, so we’re clearly not going to do that. Instead, we’re going to use something called freeglut. It’s a simple API that enables us to easily create a window, handle mouse input, create menus, and so on. It’s all event-based, so as an event occurs (e.g. the mouse moved, a key was pressed, the window was resized, etc), functions are called. All we have to do is tell freeglut which functions we want it to call when those events occur. For example, I might have a function called render that looks like this:void render ( ) { // magic stuff that draws triangles}Then, I can tell freeglut to use that function when it’s time to draw:int main (int argc, char** argv) { glutDisplayFunc (render); // tell freeglut to use render} We’ll get into more of that later, but realize it’s a simple system that works for what we’re trying to do.GLEWThe second API we’re going to use is called GLEW. Did you notice that we didn’t have to download OpenGL? Where is OpenGL then? It’s actually in the driver of your graphics card! So, GLEW’s job is to talk with the driver of your graphics card and return us a series of function pointers to all the OpenGL functions. In other words, without GLEW, we wouldn’t have any OpenGL functions to call. Fortunately, working with GLEW is easy - it’s only one line of code (well, three if you do error checking).Installing GLEW and freeglut: Directory StructureI’m expecting all of you to set up your machines at home. Of course, how you do this is a personal preference, so feel free to set it up however you like. You should only have to do this once at home, but if the lab machines are frozen, you might have to do this each time you log in. If you’re new to this, I would recommend doing the following:Create a C:\dev directory. This will contain all the SDKs/APIs you’ll use in the future.Create an “opengl” directory inside of dev (e.g. C:\dev\opengl)Download freeglut version 2.81. This link is to TransmissionZero’s site, and is the one that I use. It’s a .zip file, so unzip it and copy the contents into the opengl directory (e.g. C:\dev\opengl\freeglut)Download GLEW. The link is to SourceForge and the latest version is 1.11. Similar to step #3, copy the contents of the .zip file into your opengl directory (e.g. C:\dev\opengl\glew-1.11.0)So, you should now have a directory structure that looks like the following:C:\ - dev\ - opengl\ - freeglut\ - bin\ - include\ - lib\ - glew-1.11.0\ - bin\ - doc\ - include\ - lib\ Configuring Visual StudioNow that you understand headers, libs and DLLs, and have installed GLEW and freeglut, it’s time to configure Visual Studio. For this course, we’ll be using VS 2015. However, the process is similar to configuring VS 2010 for OpenGL. However, let’s walk through it explicitly.Create a new C++ project (File -> New -> Project). You will want to select an Empty Project and name the project Lab1. Then click OK.In the Solution Explorer (on the left), right-click on Source Files and then (Add -> New Item). Create a C++ file called “main.cpp” and the click the Add button. You should see that the code editor is now active (i.e. main.cpp is open) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download