Hello in this tutorial I'm gonna show you how you can use OpenGL in DevC++, I will also show how you can add libraries and properly link them to your project.
1. First Download the file from the link below, and extract it
Download
2. There are 3 files in this folder, we have to copy these files to their proper directory
glut.h
Copy this file to X:\Dev-Cpp\include\GL
libglut32.a
Copy this file to X:\Dev-Cpp\lib
glut32.dll
Copy this file to X:\Windows\System32
(link might be different for different OS)
3. Now open up your DevC++ Compiler
4. Click on File>>New>>Project
5. Select Empty project, give your project a name and select C++ Project, and finally Click on OK
6. Now Click on File>> Source File
Now we have to link libraries So..
7. Now in the menu bar Click on project>> Project Option >>Parameters
Here we need to add libraries for our code to work, So click on "Add Library or Object"
- libopengl32.a
- libglu32.a
- libglut32.a ( All these 3 files are located in X:\Dev-Cpp\lib)
Import them in the series as they are... Final look should be like this
9. Click on OK
10. Now copy the following code in your source file
#include<windows.h>
#include<gl/Gl.h>
#include<gl/glut.h>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,00);
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);
glBegin(GL_POINTS);
glVertex2i(100,30);
glVertex2i(100,130);
glVertex2i(150,130);
glEnd();
glFlush();
}
main(int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("My First desigh");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
11. Compile and execute it,and it should work