First, you need to have Free glut and GNU C/C++ compilers installed. This command should do:
sudo apt-get install freeglut3 freeglut3-dev gcc g++
If it all goes well, this command should show an output:
g++ --version
Next, you need to have eclipse CDT or Eclipse for C/C++ installed. You can download the latest eclipse C/C++ helios package (32-bit) from this link. It might give the illusion that u need to compile from souce since it's a .tar.gz archive but It's totally non-necessary. You can simply extract it anywhere and run the file named "eclipse" which will be inside the extracted folder.
Now, you are ready for your first eclipse Project:
- File -> New -> c++ Project.
- Enter a name for you project. Maybe Hello OpenGL. Then click finish.
Now, you are ready for your first eclipse Project:
- File -> New -> c++ Project.
- Enter a name for you project. Maybe Hello OpenGL. Then click finish.
- Right click your project main folder from the project explorer and click properties.
- From the left menu expand C/C++ build and click settings.
- From the submenu that appears Click Libraries, which is found under GCC C++ linker add the following libraries using the tiny add button at the top: "glut" , "GLU" (That caps DO MATTER). Then finally, click ok.
- From the left menu expand C/C++ build and click settings.
- From the submenu that appears Click Libraries, which is found under GCC C++ linker add the following libraries using the tiny add button at the top: "glut" , "GLU" (That caps DO MATTER). Then finally, click ok.
Note that u'll need to repeat these steps for every project you create. Now, eclipse is properly configured with freeglut. The next thing u need to do is creating a new c++ source file so: File -> New ->Source file. Then enter a name for you new file. Maybe test.cpp.
Copy and paste the following code and hit the green run button at the top or press ctrl + F11.
Copy and paste the following code and hit the green run button at the top or press ctrl + F11.
#include <GL/freeglut.h> void myInit(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(0.0f, 0.0f, 0.0f); glPointSize(4.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //First Line glLineWidth(8.0f); glBegin(GL_LINE_STRIP); glColor3ub(255, 0, 0); glVertex2i(40, 380); glColor3ub(0, 255, 0); glVertex2i(600, 380); glEnd(); //Second Line glLineWidth(8.0f); glBegin(GL_LINE_STRIP); glColor3ub(0, 0, 255); glVertex2i(40, 250); glColor3ub(0, 255, 0); glVertex2i(600, 250); glEnd(); //Third Line glLineWidth(8.0f); glBegin(GL_LINE_STRIP); glColor3ub(255, 0, 0); glVertex2i(40, 120); glColor3ub(0, 0, 255); glVertex2i(600, 120); glEnd(); glFlush(); } int main(int argc, char** argv) { //GLUT & OpenGL glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 150); glutCreateWindow("Hello OpenGL"); glutDisplayFunc(myDisplay); myInit(); glutMainLoop(); }
If you did it right, you should see the following output: