18 April 2012

hello world of OpenGL coding

opengl logo
To run your opengl code , follow the steps below :
1. At first , you need to download the openGL library.

2. look for directory named "GL" in "C:\Program Files\Microsoft Visual Studio\VC98\Include"
(note: go to your installation folder of VS98/6.0)
If not present , then create directory named "GL".
Paste the files of the openGL library to  "C:\Program Files\Microsoft Visual Studio\VC98\Include\GL"

3. Browse the folder location "C:\Program Files\Microsoft Visual Studio\VC98\Lib" and paste all .lib files to this directory.

Done configuration .

1. Create a cpp file ,open visual studio->Visual C++ 6.0
2. Name the file "myfirst.cpp"
3. Write the code for opengl.
Sample code for hello world of openGL (myfirst.cpp):
#include <GL/glut.h>
void init()
{
    glClearColor( 0.0f,0.0f,0.0f,0.0f);
    glOrtho( -2 ,2,-2,2,-2,2);
}
void myDisplay()
{
    glClear( GL_COLOR_BUFFER_BIT);
    glColor3f(0.0f,1.0f,0.5f);
    glBegin(GL_QUADS);
    glVertex3d( 1.0 , 1.0, 0.0 );
    glVertex3d(-1.0 , 1.0, 0.0 );
    glVertex3d(-1.0 ,-1.0, 0.0 );
    glVertex3f( 1.0 ,-1.0, 0.0 );
    glEnd();
    glFlush();
}
int main()
{
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
   
//DETERMINES THE SIZE OF THE WINDOW
    glutInitWindowSize( 200 , 200);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Sample Application");
    init();
    glutDisplayFunc( myDisplay) ;
    glutMainLoop();
    return 0 ;
}


4. Before compiling the code , place "glut32.dll"(found in opengl library zip) file in your project folder, where you have created the "myfirst.cpp" file

5. Build the code, and run it . The Output will be a 2D box in the window.

Done.

(If you found this article useful then share with your friends.)

No comments: