I am not familiar with the Windows development environment (and I don’t feel like I need to be). For this reason, I do not enjoy developing software on Windows. However, Windows is what we have available to us in Phillips 115. In this post I will describe how I get around having to know Windows but still allow you to get my OpenGL starter code up and running in this lab.
You may want to set up your personal machines too. Be warned, however. I do not have the time resources or the know-how to support setting up your own machine for graphics development. The graphics cards in Phillips 115 are decent. Yours may not be.
The code I share with you in lectures will be developed on Linux. So that you may take this exact same code and build it on Windows, I am using a tool called CMake. This is a cross-platform build system. We create one file named CMakeLists.txt listing our desired executables and the source code and libraries our executables depend on. Based on that file, CMake will generate makefiles, or a Visual Studio project, or an XCode project, and so on.
This is the process LTS used to set up the lab machines:
If you want your project to stay decoupled from Visual Studio, do not change your project configuration through Visual Studio. Rather, add files through the source directory that you pointed CMake to, and edit CMakeLists.txt accordingly. (Feel free to edit the contents of files already in your project through Visual Studio. Just don’t add new ones.)
To add shader code, put the shader files in the shaders directory in the source directory. Whenever you need a path to one of these shaders in your C++ code, use something like SHADERS_DIR "/bulbous.vert.glsl"
. In CMakeLists.txt, I’ve defined a preprocessor macro named SHADERS_DIR that evaluates to the shaders directory in your project source.
To make a new executable, you need to add two lines to CMakeLists.txt, having the following form:
add_executable(myexe source1.cpp source2.cpp ${COMMON})
target_link_libraries(myexe ${GLUT_LIBRARIES} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES})
myexe is the name you pick for your executable file. source1.cpp through sourceN.cpp are the names of the source files that myexe depends on. ${COMMON} already holds the source files like ShaderProgram.cpp and BaseRenderer.cpp that I’ve provided to you. You need only add the files that you create.
If you’d rather work on Linux, you may, but the burden is on you to figure out how to get things set up. I installed cmake 2.8, glew-dev, and freeglut-dev through my package manager. (The names of these libraries will vary from distribution to distribution.) Make a build directory somewhere, then run
cmake ../path/to/source/dir/which/contains/CMakeLists.txt
make
Comments
[…] Follow the last two sections of Visual Studio, CMake, and OpenGL. […]