How to write first OpenGL program?

OpenGL First Program

Why I am writing this, always new student want to learn about any new programming, lot of question in their mind, suppose lets take OpenGl,

What is OpenGL?
Where to write and run the program?
How to write the first OpenGL program?

Lot of question, i am trying to solve this for them.

What is OpenGL?

OpenGL is a software interface to graphics hardware. This interface consists of about 150 distinct commands that you use to specify the objects and operations needed to produce interactive three-dimensional applications.

Where to write and run the OpenGl program?

Follow some steps:

  1. Install the software VC++ 6.0
  2. File > New > Console Application
  3. Enter Project Name and location > OK
  4. Choose Option “An Empty project” > Finish > OK
  5. Project > Settings > Link Tab Menu
  6. In the Object/Library modules > Enter the names of the three .lib files glu32.lib, glut32.lib and opengl32.lib. > OK
  7. File > New > Choose C++ Source File > Give Name > OK
  8. Type of code
  9. F7 to build
  10. CTRL+F5 to run

First Sample OpenGL Program
//Basic of opengl Programming/Programming OpenGL in C/C++




void myInit(void){

glClearColour();//set the backgroud colour

glColour3f(); //set the drawing colour



glLoadIdentity(); }
void myDisplay(void){

//have to make filled polygon

glClear(GL_COLOUR_BUFFER_BIT);//clear the screen

glBegin(GL_POLYGON); //draw the polygon with the following vertex





void main(int argc, char** argv){

glutInit(&argc,argv);//initialise the toolkit

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//set display mode



glutCreateWindow(“OpenGL Window”);




How to run OpenGL Program

  1. F7 to build
  2. CTRL+F5 to run

* Write first OpenGL program


Hi, This is R K Gupta, an IT professional and Entrepreneur. I have written many articles yet for my websites, Hope you like it. Kindly subscribe our feed for any updates. Add me in Facebook and Google+

Posted in Microsoft .Net Help, Software Development