Tuesday, 16 August 2016

Program 2: Write a program to draw objects using Line-Attribute, Fill-Area Attribute, Color functions of OpenGL.

PROGRAM 2: (Line, fill, color attributes)
1.      Header File : same as the previous prog. link: http://simplifiedopengl.blogspot.in/2016/08/simplified-output-primitive-function.html
2.      Display Function
//LINE ATTRIBUTES: line colour, stipple, width.
    GLint factor=1;
    GLushort pattern=0x00ff;
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(factor,pattern);
//then create the object.
glDisable(GL_LINE_STIPPLE);

//COLOR FUNCTION: gradient color and solid color.
Gradient: Give, glColor3f(0.0,0.0,1.0); before every vertex;
Solid: glColor3f(0.0,0.0,1.0); before the object creation.

//POLYGON FILL
//declare: GLubyte mask[128]; outside the display function
GLubyte Lines[] = {
    0x00, 0x00, 0x00, 0x00,
    0xff, 0xff, 0xff, 0xff,
    };
    glEnable(GL_POLYGON_STIPPLE);
     glPolygonStipple(Lines);
//draw polygon
    glDisable(GL_POLYGON_STIPPLE);

3.      Main function same as the firs program.











SAMPLE: PROGRAM 2
//header file: windows and glut
GLubyte mask[128];
void display()
{
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    //LINE ATRRIBUTES:
    GLint factor=1;
    GLushort pattern=0x00ff;
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(factor,pattern);
    glColor3f(1.0,1.0,1.0); //solid line color
    glBegin(GL_LINES);
    glVertex2f(0.0,0.0);
    glVertex2f(0.40,0.0);
    glLineWidth(10.0f);// line attribute
    glEnd();
    glDisable(GL_LINE_STIPPLE);
    //COLOR FUNCTION: gradient
    glBegin(GL_LINES);
    glColor3f(0.0,0.0,1.0); //blue
    glVertex2f(0.0,0.10);
    glColor3f(1.0,1.0,0.0);//yellow
    glVertex2f(0.40,0.10);
    glEnd();
    //Fill area:POLYGON FILL
    GLubyte Lines[] = {
    0x00, 0x00, 0x00, 0x00,
    0xff, 0xff, 0xff, 0xff,
    };
    glEnable(GL_POLYGON_STIPPLE);
     glPolygonStipple(Lines);
    glColor4f(1.0f, 0.0f, 0.0f, 0.0f);//red
    glBegin(GL_POLYGON);
    glVertex2f(-0.44,0.45);
    glVertex2f(-0.57,0.45);
    glVertex2f(-0.65,0.10);
    glVertex2f(-0.90,-0.60);
    glVertex2f(-0.10,-0.60);
    glEnd();
    glDisable(GL_POLYGON_STIPPLE);
    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