OpenGL sample

#include <GLUT/glut.h>

#include <OpenGL/gl.h>

 

void myInit(void)

{

glClearColor(1.0,1.0,1.0,0.0); // set white background color

glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color

glPointSize(4.0); // a ‘dot’ is 4 by 4 pixels

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0, 640.0, 0.0, 480.0);

}

 

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the screen

//First Line

glLineWidth(8.0f);

glBegin(GL_LINE_STRIP);

glColor3ub(255, 0, 0);

glVertex2i(40, 380);

glColor3ub(0, 255, 0);

glVertex2i(600, 380);

glEnd();

//Second Line

glLineWidth(8.0f);

glBegin(GL_LINE_STRIP);

glColor3ub(0, 0, 255);

glVertex2i(40, 250);

glColor3ub(0, 255, 0);

glVertex2i(600, 250);

glEnd();

//Third Line

glLineWidth(8.0f);

glBegin(GL_LINE_STRIP);

glColor3ub(255, 0, 0);

glVertex2i(40, 120);

glColor3ub(0, 0, 255);

glVertex2i(600, 120);

glEnd();

glFlush(); // send all output to display

}

 

int main(int argc, char** argv)

{

 

//GLUT & OpenGL

glutInit(&argc, argv); // initialize the toolkit

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode

glutInitWindowSize(640,480); // set window size

glutInitWindowPosition(100, 150); // set window position on screen

glutCreateWindow(“my first attempt”); // open the screen window

glutDisplayFunc(myDisplay); // register redraw function

myInit();

glutMainLoop(); // go into a perpetual loop

 

}