Objects using Line-Attribute, Fill-Area Attribute, Color functions of OpenGL

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

2. Create a display function where you will be drawing your shape and objects
void display()
{
}

3. Give Screen color using ClearColor
    glClearColor(0.0,0.1,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);

4. Use factor and pattern to give some styles to your line.
for more pattern click: GL_Pattern
    GLint factor=1;
    GLushort pattern=0x0c0f;

5. Enable the Stipple
    glEnable(GL_LINE_STIPPLE);// enabling the line pattern function
    glLineStipple(factor,pattern);

6.Draw the shape
    glColor3f(1.0,0.0,0.0);
    glBegin(GL_LINES);
    glVertex2f(0.0,0.0);
    glVertex2f(1.0,0.0);
    glEnd();

7.disable the stipple then flush it.
    glDisable(GL_LINE_STIPPLE);
    glFlush();

8. Main Function
int main(int argc,char** argv)

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

10. Create the window and define the size
    glutCreateWindow("PROGRAM2");
    glutInitWindowSize(320,320);

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

12. glutMainLoop();
     return 0;


CODE:
#include<GL/glut.h>
#include<windows.h>

void display()
{
    glClearColor(0.0,0.1,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    GLint factor=1;
    GLushort pattern=0x0c0f;
    glEnable(GL_LINE_STIPPLE);// enabling the line pattern function
    glLineStipple(factor,pattern);

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

    glDisable(GL_LINE_STIPPLE);
    glFlush();
}
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    //create widow, initialize window,diplay(),loop
    glutCreateWindow("Program2");
    glutInitWindowSize(320,320);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

Comments

Popular posts from this blog

OPENGL COLOR CODES

OpenGL Texture

Draw Circle in OpenGL