draw objects using OpenGL output primitive functions

1. Load the Libraries:
#include<GL/glut.h>
#include<windows.h>

2. Make a display function where you can draw your objects.
void display()
{
}

3. Inside the display function give the color of your screen.
    glClearColor(r,g,b);
    glClear(GL_COLOR_BUFFER_BIT);
where you are defining the intensity of the colors i.e the intensity of your Red, Green and Blue color.

4. Then draw you objects inside the display function.
Eg:  For Line
    glColor3f(r,g,b);
    glBegin(GL_LINES);
    glVertex2f(x,y);
    glVertex2f(x,y);
    glEnd();
for more click:output primitives

5. Render the Objects
    glFlush(); 
then close the display function.

6. now comes the main function
int main(int argc,char** argv)

7.  Iitialize the Arguments.
glutInit(&argc,argv);

8. Create the window and define the size
    glutCreateWindow("PROGRAM1");
    glutInitWindowSize(320,320);

9. use the glutDisplayFunc() to display your object.
    glutDisplayFunc(display);

10. glutMainLoop();
    return 0;

Basic Structure:

#include<GL/glut.h>
#include<windows.h>
void display()
{
   glClearColor(0.0,0.0,1.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0,0.0,0.0);
    glBegin(GL_LINES);
    glVertex2f(0.0,0.0);
    glVertex2f(1.0,0.0);
    glEnd();

    glFlush();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("PROGRAM1");
    glutInitWindowSize(320,320);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

Comments

Popular posts from this blog

OPENGL COLOR CODES

OpenGL Texture

Draw Circle in OpenGL