Tuesday, 16 August 2016

Program 1: Output primitive function

Main Thing Required:
1. Header file
2. Display Function
3. Main Function

HEADER FILE :
Header file contains:
#include<GL/glut.h>
#include<windows.h>

DISPLAY FUNCTION:
Your Object Creation is done here, where you have to:
Create a display function. //eg: void display()
Declare the window color
#include<GL/glut.h>
#include<windows.h>
void display()
{
    glClearColor(0.0,0.0,0.0,0.0); //window color
    glClear(GL_COLOR_BUFFER_BIT);
}
Create your object using the output primitives i.e triangle,line,points,quads,polygon
#include<GL/glut.h>
#include<windows.h>
void display()
{
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);//object color
    glBegin(GL_QUADS);//drawing a quad 
    glVertex2f(0.0,0.0);
    glVertex2f(0.10,0.0);
    glVertex2f(0.10,0.5);
    glVertex2f(0.0,0.5);
    glEnd();
    glFlush(); //to render
}

MAIN:
In the main function declare your glut function.
create a main function:
#include<GL/glut.h>
#include<windows.h>
void display()
{
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_QUADS);
    glVertex2f(0.0,0.0);
    glVertex2f(0.10,0.0);
    glVertex2f(0.10,0.5);
    glVertex2f(0.0,0.5);
    glEnd();
    glFlush();
}
int main(int argc,char** argv)
{
}

in the main function, initialize the arguments 
int main(int argc,char** argv)
{
    glutInit(&argc, argv);
}


then, create a window and specify its size.
int main(int argc,char** argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("Prog");
    glutInitWindowSize(320,320);
}



 Now, call your display function in the main and loop it
int main(int argc,char** argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("Prog");
    glutInitWindowSize(320,320);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

  

SAMPLE: PROGRAM 1 (Objects using output primitive)
#include<GL/glut.h>
#include<windows.h>
void display()
{
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_QUADS);
    glVertex2f(0.0,0.0);
    glVertex2f(0.10,0.0);
    glVertex2f(0.10,0.5);
    glVertex2f(0.0,0.5);
    glEnd();
    glFlush();
}
int main(int argc,char** argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("Prog");
    glutInitWindowSize(320,320);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}



No comments:

Post a Comment