Setting up OpenGL

In this post we will look at how to set up OpenGL with visual studios to start working.

First go to this link and download the OpenGL pack and extract it to you'r project folder or anywhere that is easily accessible, you will need these files for the rest of the development.

Now open up visual studios and create a new C++  Win32 Console application under which can be found under Viusal C++. Give it a name you like and click ok.


Next when you are prompted with the Win32 Application wizard just click finish, you do not need to change anything there.


It will take a moment to be setup.

Once it's setup, click on the projects menu and go to the (appname)properties.
you should be presented with the following window.


On this window expand the C/C++ and go to the general tab click the drop down menu found at the end of the row named Additional Include Directories.


From this window click on the folder icon and navigate to your openGL pack folder and navigate to Freeeglut\include\GL  and click ok.


Next go to the general tab which can be found under the Linker of the property page and click the drop down menu at the end of the row named 'Additional Library Directories'.


Next click on the folder icon and navigate to openGL pack folder and navigate to Freeglut\lib, and click ok.


Once this is done, click on the input tab that can be found under Linker. click the drop down arrow at the end of the row named 'Additional Dependancies' and add these two lines to it :

opengl32.lib
freeglut.lib

... and click ok.


Once this is done click apply and ok on the property page window and close it.

Now go to the OpenGL pack folder and navigate to freeglut\bin and copy and past the freeglut.dll file to your solutions debug folder.
For example my debug folder was found in doucuments\Visual Studio 2017\Projects\TestApp\Debug.

Once this is done go back to the visual studio editor and copy paste the base code to test whether openGL has been set up properly. the base code can be found in the openGL pack folder or just copy paste from here:
/////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "freeglut.h"
#include <Windows.h>
#include <iostream>

using namespace std;

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}



int main(int argc, char* argv[]) {

// Initialize GLUT
glutInit(&argc, argv);
// Set up some memory buffers for our display
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
// Set the window size
glutInitWindowSize(800, 600);
// Create the window with the title "Hello,GL"
glutCreateWindow("Hello, GL");
// Bind the two functions (above) to respond when necessary
glutReshapeFunc(reshape);
glutDisplayFunc(display);

glutMainLoop();
return 0;
}

//////////////////////////////////////////////////////////////////////

once the code is copied make sure the debug mode is set to x86 and then click on the green play button with the text "Local Windows Debugger" and an empty black windows with a console should pop-up. If all the above setups are done correctly you will be presented with these windows.


Congratulations you have successfully set up freeglut to start developing 3D graphics.

Comments