Section (2) - WordPress.com

wireanticipatedSoftware and s/w Development

Dec 14, 2013 (3 years and 4 months ago)

77 views

1


Section (
2
)

Draw Line:


#include

"glut.h"

// to call open GL



void

myDisplay();

// header

void

myInit();

// header

void

main(
int

ag,
char
** argv)

{


glutInit(& ag,argv);


glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(600,400);


glutInitWindowPosition(100,100);


glutCreateWindow(
"my window"
);


glutDisplayFunc(myDisplay);


myInit();


glutMainLoop();

}


void

myInit()

{


glClearColor(1.0,1.0,1.0,0.0);


glLoadIdentity();


gluOrtho2D(0,600,0,400);

}


void

myDisplay()

{


glClear(GL_COLOR_BUFFER_BIT);

// to clear the buffer


glPointSize(7.0);


glBegin(GL_LINES);


//First Line


glColor3f(1.0,0.0,0.0
);
//Red


glVertex2i(100,300);
// top


glVertex2i(200,200);
//botton


//Second Line


glColor3f(0.0,1.0,0.0);
//Green


glVertex2i(
500,200);
//top


glVertex2i(400,100);
//botton


glEnd();


glFlush();

}


2


Draw Line Strip:


#include

"glut.h"

void

myDisplay();

void

myInit();

void

main(
int

ag,
char
** argv)

{


glutInit(& ag,argv);


glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);


glutInitWindowSize(600,400);


glutInitWindowPosition(100,100);


glutCreateWindow(
"my window"
);


glutDisplayFunc(myDisplay);


myInit();


glutMainLoop();

}


void

myInit()

{


glClearColor(1.0,1.0,1.0,0.0);


glLoadIdentity();


gluOrtho2D(0,600,0,400);

}


void

myDisplay()

{


glClear(GL_COLOR_BUFFER_BIT);


glColor3f(1.0,0.0,0.0);


glPointSize(7.0);


glBegin(GL_LINE_STRIP);


glVertex2i(100,100);
//A



glVertex2i(100,200);
//B


glVertex2i(200,300);
//C


glVertex2i(300,200);
//D


glVertex2i(200,100);
//E


glEnd();


glFlush();

}



3


Draw Line
Loop
:


#include

"glut.h"

void

myDisplay();

void

myInit();


void

main(
int

ag,
char
** argv)

{


glutInit(& ag,argv);


glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);


glutInitWindowSize(600,400);


glutInitWindowPosition(100,100);


glutCreateWindow(
"my window"
);


glutDisplayFunc(myDisplay);


myInit();


glutMainLoop();

}


void

myInit()

{


glClearColor(1.0,1.0,1.0,0.0);


glLoadIdentity();


gluOrtho2D(0,600,0,400);

}


void

myDisplay()

{


glClear(GL_COLOR_BUFFER_BIT);


glColor3f(1.0,0.0,0.0);


glPointSize(7.0);


glBegin(GL_LINE_LOOP);


glVertex2i(100,300);


glVertex2i(300,200);


glVertex2i(200,400);


glVertex2i(400,200);


glVertex2i(200,100);



glEnd();


glFlush();

}