Table of Contents
First things first, open up Visual Studio and select File->Create New Project. Make it a Visual C++ project and select Empty Project. Call it "GettingStarted" and make sure there are no spaces in the "Location" (file path) to avoid any compiler errors. Make sure that "Create directory for solution is checked". Then click "OK".
Add a new file to the solution (CTRL + SHIFT + A) and call it "Main.cpp". Write down the main function and make sure it compiles (F5 is the default hotkey to "Start Debugging" your project, which should then compile and lanch a console window, which then closes immediately (since your code doesn't do anything yet). Here's a main function, in case you need it:
int main(int argc, char **argv)
{
return 0;
}
If you've done it right so far, you should have a folder called "GettingStarted" and within that folder a file called "GettingStarted.sln" amongst some other files. Within this folder, there should be another folder called, "GettingStarted". Open this inner folder and within you should see your "Main.cpp" file and a "GettingStarted.vcxproj" file as well . In here, create a new folder and call it "Include".
Let's pause for a moment and look at some pseudo code:
#include <libraryheaders>
int main()
{
createWindow(title, width, height);
createOpenGLContext(settings);
while (windowOpen)
{
while (event = newEvent())
handleEvent(event);
updateScene();
drawGraphics();
presentGraphics();
}
return 0;
}
The first thing that happens is you create a window (giving a title, width, and height at minimum) and then you create your OpenGLContext with whatever settings you need.
Then you enter a loop, that continues until your window closes. Your loop checks for any events (the only things that can actually interrupt your loop) and then processes them.
Once done with that, it will perform any update logic. Then it will render, and it does this using a method called double buffering. This involves rendering your frame to the
"back buffer" which is not visible to the user. When this this is finished, the presentGraphics() call will take that result from the back buffer and move it to the front buffer
which is the visible window buffer. Doing this prevents flickering, as we let the back buffer finish first.
Back the original point, we need to make a decision. By default, OpenGL does not include any createWindow() nor a createOpenGLContext() function. Instead, you must write this code yourself. However, some lovely developers out there have taken the time to create some libraries to handle a lot of this work for you. In order to create your OpenGL window/context, we're going to be using one of these libraries. If you'd rather write all the code on your own (only do this if you know what you're doing; it's not that simple), feel free to check out this tutorial on just that: [CLICK HERE]
Now we have to make a decision.
There are plenty of libraries out there that exist to create a window and OpenGL context, and none of them are the "best". There's no such thing. Instead, you should be selecting one that suits your individual ideals and needs. This tutorial will cover several options, but more exist. Feel free to do some research on Google if you're interested in the others. Choose from one of the following libraries:
One more library that we're going to want is GLEW (OpenGL Extension Wrangler). Do not be confused by SFML, which has an internal application for GLEW that you can't actually access. Instead, you'll want to get GLEW directly. Just be sure that when linking GLEW, glew32.lib is included before SFML. If you don't have SFML, this shouldn't be an issue.
Okay, so you may be asking yourself, what are all these words being thrown around? What are we actually doing in this part of the tutorial? What this really means is that we'll be attaching our code with code that other developers wrote to help take care of some of the messier/complicated parts of using OpenGL. Doing this allows us to focus our time and effort on the parts of the code we care about and are going to write. If you're ready to get started adding some libraries, go to the next page. If you'd like to learn more about code libraries, go here: [INSERT LINK HERE]