Windows - Compiling OpenGL Programs in Windows

2005-10-29

I. Install Cygwin.
Download from the Cygwin website
Packages I needed to install:

  • binutils (devel)
  • gcc-g++ (devel)
  • gcc-core (devel)
  • make (devel)
  • opengl (lib)
  • w32api (lib)

(you will probably want other programs like ssh, bzip2, etc. But I believe the above is all is needed to compile).

II. Set the enviornment variables
Right-Click My Computer, Properties, Advanced, Envriornment Variables, and add “;C:\cygwin\bin” to the end of “PATH” unde System Variables.

Now you can compile programs by opening up a command prompt and typing:

g++ test.cpp -lglut32 -lglu32 -lopengl32

Here’s a Makefile modified for Windows. The original was from Tong Lai Yu, Ph.D. in his CS420 Computer Graphics class.

#sample Makefile for using OpenGL of Red Hat Linux 7.x
#CS 420, Tong Yu, Fall 2002
# Modified for Windows Fall of 2005 --Ben

PROG	= robot
CFLAGS	= -w -s -O2 -ansi -DSHM
LIBS	= -lglut32 -lglu32 -lopengl32
#source codes
SRCS = robot.cpp
#substitute .cpp by .o to obtain object filenames
OBJS = $(SRCS:.cpp=.o)

#$< evaluates to the target's dependencies,
#$@ evaluates to the target

$(PROG): $(OBJS)
g++ -o $@ $(OBJS)  $(LIBDIR) $(LIBS) $(XLIBS)

$(OBJS):
g++ -c  $*.cpp $(INCLS)

clean:
rm $(OBJS) $(PROG)

On most programs I have been able to compile them without changing the includes. Here are the headers I usually use:

#include 
#include 
#include 
#include 

Most OpenGL programs seem to compile fine with just these two includes:

#include 
#include 

And that’s all.