-
Download graphics header file from here.
-
Download and install tdm-gcc 32bit compiler.
-
Copy files from include and lib folder from graphics folder file you downloaded in step 1 to include and lib folder of tdm-gcc 32bit.
-
Open VS Code and create a new project folder and open C/C++ configuration.
-
In the configuration setting set compiler path to C:/TDM-GCC-32/bin/g++.exe (this location may be different).
-
Paste following to compiler arguments. -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
-
Set C++ standard to c++11
-
Write some codes and build the code with followin config:
-
Then you are good to go.
-
Download the above BGI file from thefunkydude/ComputerGraphicsLab.
-
Copy the file to path c:/dev.
-
Make sure that mingw is added to the environment variables.
-
Open your sublime text and follow the setps: tools->Build system->New build system.
-
Copy the following code and paste it to the new build system:
{ "shell_cmd": "g++ -std=c++17 \"${file}\" -IC:\\dev\\BGI -LC:\\dev\\BGI -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -o \"${file_path}/${file_base_name}\" && start cmd /c \"title ${file_base_name}.exe && \"${file_path}/${file_base_name}\" && echo. && echo. && pause\"", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c++", }
-
Save the build system with extension .sublime-build.
-
Select the build system you just saved from the tools menu and you are good to go.
-
Check with a testfile.cpp as:
#include<graphics.h> int main() { initwindow(400,400,"TEST FILE"); rectangle(50,100,200,250); //your code getch(); closegraph(); }
- Build code for now:
{
"shell_cmd": "g++ -std=c++17 \"${file}\" ‐IC:\\freeglut\\include ‐LC:\\freeglut\\lib ‐w ‐Wl,‐subsystem,windows ‐lOpenGL32 ‐lglu32 ‐lfreeGLUT -o \"${file_base_name}\" && start cmd /c \"title ${file_base_name}.exe && \"${file_path}/${file_base_name}\" && echo. && echo. && pause\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++",
}
- A test code drawing a triangle taken from This site.
#include<Gl/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(-0.6, -0.75, 0.5);
glVertex3f(0.6, -0.75, 0);
glVertex3f(0, 0.75, 0);
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 80);
glutInitWindowSize(400, 300);
glutCreateWindow("A Simple Triangle");
glutDisplayFunc(display);
glutMainLoop();
}
- Download free glew and glut from here.
- Extract the files in a folder you desire.(you need the folder so never delete it unless you donot want to do opengl anymore)
- Open Visual Studio and create a C++ solution/project.
- Go to the properties of your project.
- Inside properties go to C/C++ and in additional include directories include the include folders from the files you dowloaded before.
- Go to general of linker section and in additional library directories include the lib folders from the files you downloaded before.
- In the input of linker section add following in additional dependencies.
(freeglut.lib
, glew32.lib)
- Copy and paste following files you downloaded before in System32 folder. (freeglut.dll , glew32.dll)
- Now copy the code and build your project and run it, then you are good to go.
#include<Gl/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(-0.6, -0.75, 0.5);
glVertex3f(0.6, -0.75, 0);
glVertex3f(0, 0.75, 0);
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 80);
glutInitWindowSize(400, 300);
glutCreateWindow("A Simple Triangle");
glutDisplayFunc(display);
glutMainLoop();
}