Go to http://www.eclipse.org
In the downloads
Download and install
For OSX and Linux, Eclipse should automatically find the appropriate C/C++ compilers.
For windows, eclipse will require an C/C++ compiler to be installed. MinGW is a suitable package: http://www.mingw.org. In particular you should follow these instructions here:
http://www.mingw.org/wiki/Getting_Started
When you get to running the automated installer, use this command here to make sure you install both the compiler and debugger:
mingw-get install gcc gdb
Create a new C++ application, selecting the "Hello World" app from the //File->New->C++ Project// menu:
Subsequently, to run the application, just press one of the launch icons:
Project should build as above.
You may wish to experiment with the debugger: a breakpoint can be set by right clicking on the "column 0" in the editor:
Create a new Eclipe C/C++ Project and call it HelloOpenGL
Insert a new source file in to the project - call it helloopengl.cpp
Eclipse will generate an empty source file:
#ifdef WIN32
#include <GL/gl.h>
#include <GL/glu.h>
#include "freeglut.h"
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <Glut/glut.h>
#endif
Place this into the helloopengl.cpp source
Below this insert this starter application:
void renderScene(void)
{
glClear( GL_COLOR_BUFFER_BIT);
glFlush();
}
void setupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Hello OpenGL");
glutDisplayFunc(renderScene);
setupRC();
glutMainLoop();
return 0;
}
Be Sure to save the file before proceeding.
Now attempt to build...
Libraries have not been configured, so on Windows you will get the following errors:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ohelloopengl.o ..\helloopengl.cpp
..\helloopengl.cpp:4:22: freeglut.h: No such file or directory
..\helloopengl.cpp: In function `int main(int, char**)':
..\helloopengl.cpp:28: error: `glutInit' was not declared in this scope
..\helloopengl.cpp:29: error: `GLUT_SINGLE' was not declared in this scope
..\helloopengl.cpp:29: error: `GLUT_RGBA' was not declared in this scope
..\helloopengl.cpp:29: error: `glutInitDisplayMode' was not declared in this scope
..\helloopengl.cpp:30: error: `glutCreateWindow' was not declared in this scope
..\helloopengl.cpp:31: error: `glutDisplayFunc' was not declared in this scope
..\helloopengl.cpp:35: error: `glutMainLoop' was not declared in this scope
..\helloopengl.cpp:28: warning: unused variable 'glutInit'
..\helloopengl.cpp:29: warning: unused variable 'GLUT_SINGLE'
..\helloopengl.cpp:29: warning: unused variable 'GLUT_RGBA'
..\helloopengl.cpp:29: warning: unused variable 'glutInitDisplayMode'
..\helloopengl.cpp:30: warning: unused variable 'glutCreateWindow'
..\helloopengl.cpp:31: warning: unused variable 'glutDisplayFunc'
..\helloopengl.cpp:35: warning: unused variable 'glutMainLoop'
Build error occurred, build is stopped
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"helloopengl.d" -MT"helloopengl.d" -o"helloopengl.o" "../helloopengl.cpp"
Finished building: ../helloopengl.cpp
Building target: HelloOpenGL
Invoking: MacOS X C++ Linker
g++ -o "HelloOpenGL" ./helloopengl.o
Undefined symbols:
"_glFlush", referenced from:
renderScene() in helloopengl.o
"_glutDisplayFunc", referenced from:
_main in helloopengl.o
"_glutInitDisplayMode", referenced from:
_main in helloopengl.o
"_glutCreateWindow", referenced from:
_main in helloopengl.o
"_glutMainLoop", referenced from:
_main in helloopengl.o
"_glutInit", referenced from:
_main in helloopengl.o
"_glClearColor", referenced from:
setupRC() in helloopengl.o
"_glClear", referenced from:
renderScene() in helloopengl.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [HelloOpenGL] Error 1
Enter "-framework GLUT -framework OpenGL" as shown, and press Apply and Ok.
Build and execute, and the following window should appear:
On windows, you will need to make sure that the platform SDK is installed. See
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
The SDK includes OpenGL libraries, but not GLUT. A verion of GLUT is maintained here:
http://freeglut.sourceforge.net/
This is distributed as a large Visual Studio project. A prebult version, version, suitable for our purposes, is here:
Unzip this into a suitable directory, and copy the freeglut.dll into windows/system32.
In eclipse, add the freeglut directory to the path for the project:
Also place the freeglut folder on the linker search path.
Run the application - it should display a blank window:
void setupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
gluOrtho2D(-100.0, 100.0, -100, 100.0);
}
void renderScene(void)
{
glClear( GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(-25.0f, 25.0f, 25.0f, -25.0f);
glFlush();
}
Review the two projects you have created, exploring them within eclipse:
and on the file system:
Refactor the opengl project such that the source is in a src subdirectory, like the c++ application. To do this, you will need to: - Create a "source directory" called src in eclipse
Move the helloopengl.cpp file in there
clean the project, and also (perhaps) manualy delete the "debug" folder from within explorer/finder.
Your objective is to have a project structure like this:
Create a new project to contain some utility classes. Call the project "utils". It should initially contain a single leader file "libopengl.h". Put the includes from the existing open gl source into into it:
#ifdef WIN32
#include <windows.h>
#include <gl\glu.h>
#include "glut.h"
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <Glut/glut.h>
#endif
Then replace these lines in your C++ programe with:
#include "libopengl.h"
There are many ways of doing this within eclipse. Most involve exiting the project properties, and exploring the project paths for the build. The following screen here gives the game away...
Draw Several Rectangles, in different locations, in different colours
Change the co-ordinate sytem so that the screen has different virtual dimensions
Explore what happens when the screen is resized.
Browse the following documentation:
gl
glu
glut