You are on page 1of 14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Home

Academic Projects

Portfolio

    

Drudoo {dot} com

1st April 2015 by Frederik Vanggaard | Programming

Using Sublime Text with
C++ and OpenGL on
Windows!
On Mac, using OpenGL and GLUT is easy. On Windows not
so much. Before we can even begin trying to make a
Sublime Text build system, we need to set up OpenGL and
http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

1/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

GLUT. This guide will show you how to set up Freeglut and
MinGW before making a custom build system for Sublime
Text.
This guide might not work if you other c++ compilers installed
with e.g. CodeBlocks or VisualStudio. This does work on a
fresh Windows installation.
First we need to install freeglut. Go to
http://freeglut.sourceforge.net and scroll down to
Prepackaged Releases.
Press on Martin Payne’s Windows binaries.

This directs you to Transmission Zero where you need to
download the freeglut MinGW package.

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

2/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Extract the folder and move it to C:\freeglut , you can place
it somewhere else, but it is recommended to place it here
and i will use this pagh for the rest of the guide.
Now go to MinGW’s Sourgeforge site and press on the
newest release. This will give you three options.
Download the exe file.

Double click the installer. Choose Use pre-packaged
repository catalogues.

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

3/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Install it to C:\MinGW . This is important, we will use this path
later on.

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

4/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Be sure to check C Compiler, C++ Compiler and MSYS Basic
System.

Press next and install it. This will take some time and the
command-line window will open and run a lot of download
commands. This is normal and just let it do its job.
When the installer is done, we need to set up the
environment path for MinGW. This is done through the
control panel.
Go to Control Panel ‐> System and Security ‐> System ‐> 
Advanced System Settings .

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

5/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

6/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

When the System Properties window opens, press on
Environment Variables...

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

7/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

First scroll down to Path and press on it. Then press Edit…

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

8/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

A dialogbox with your Path will open up. Here we have to
add the path of MinGW. If you installed it the exact way i
did, it will be placed on C:\MinGW .
At the end of the line make sure there is a semi-colon before
writing C:\MinGW\bin;
Again remember the semi-colon at the end.

Press Ok to close all the windows (should be 3 in total).
http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

9/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

To verify that the path has been added open up the
command-line and write path .

Your path will be different from mine, but make sure there
is C:\MinGW\bin; at the end.
Right now we will be able to compile OpenGL programs but
we can’t run them without having freeglut.dll in the same
folder as our application. To avoid this we need to copy
freeglut.dll to our System32 folder and SysWOW64 folder.
Go to C:\freeglut\bin and copy freeglut.dll to
C:\Windows\System32 and to C:\Windows\SysWOW64 . Now

everything should be set up correctly and we are ready to
move on to making the build system for Sublime Text.
To make sure the path is updated and that the system
folders are updated, you need to restart your computer. I
had a few problems when testing this and a restart did fix
those.
Open Sublime Text and go to Tools ‐> Build System ‐> New 
Build System…

This will open up a new document called untitled.sublimebuild. Delete what is in the document and paste in:

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

10/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

{          
"cmd": [ "g++ $file_name ‐IC:\\freeglut\\include ‐
LC:\\freeglut\\lib ‐w ‐Wl,‐subsystem,windows ‐lOpenGL32 
‐lglu32 ‐lfreeGLUT ‐o $file_base_name"],          
"working_dir": "${project_path}",          
"selector": ["source.c++"],          
"shell": true           
}          

Lets go through the code. First we have the cmd line. This
line is basically what you would write in the command-line
if you compiled from that. First we have g++ which is
basically the program that compiles the code. Then we use
$filename to access the name of our cpp file with extension.
Next we have our two freeglut libraries. This path should be
changed, if you did not install freeglut to C:\freeglut. Then we
link various other system and OpenGL libraries before adding
-o $filebase_name at the end. This determines what the exe
file that is produces will be called. In this case it is set to the
file name without extension.
The working dir is the folder from where the command
should be executed. Selector is used to determine which
build system should be used if Automatic is chosen. Lastly
we have the shell, which is optional and means that the
cmd will be run through the shell.

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

11/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Save the file as OpenGL or some other name. Go to Tools ‐> 
Build System and select the build system we just saved. In

this case OpenGL.
Download the this cpp file and open it in Sublime Text.
Go to Tools and press Build. If everything goes right you
should see [Finished in 0.6s] or some other time.
Now navigate to the folder where you saved the document
end you should see a new file named Square.exe. Double
click it and the program should run.
You should now see a new application like the one shown
below. Just a red square. You can quit the program using the
normal red x at the top right corner or by pressing Esc.

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

12/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

If you get the error that freeglut.dll is missing, make sure it
is placed in system32 and sysWOW64 . Alternatively you can copy
it from C:\freeglut\bin to the folder containing the program.
 
Frederik Vanggaard

 

← oF and Tesseract

Using Sublime

Text with C++ and OpenGL on Mac! →

Leave a Reply
You must be logged in to post a comment.

Categories

Search …

Arduino (5)
CUI32 (2)
Maya (3)
Myo (1)
News (8)
PCL (1)
Programming (25)
Raspberry Pi (2)
 

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

13/14

24/12/2016

Using Sublime Text with C++ and OpenGL on Windows! | Drudoo {dot} com

Casper WP by Lacy Morrow

http://www.drudoo.com/2015/04/01/using­sublime­text­with­c­and­opengl­on­windows/

14/14