// Computer Graphics - Amir Hesami //lines.cpp #include #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib #pragma comment(linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() #pragma comment(linker, "/subsystem:\"Windows\"" ) // set the entry point to be main() void display(void); void init(void); int main(int argc, char** argv) { glutInit(&argc, argv);// initialise glut system glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB);//set the display mode glutInitWindowSize(500, 500);// set window size glutInitWindowPosition(100,100);// set window position glutCreateWindow("LINES");// create a window with a certain name glutDisplayFunc(display); //calling the drawing function init(); glutMainLoop(); return 0; } void display(void) { glClear(GL_COLOR_BUFFER_BIT);//clear buffers glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); //line 1 glVertex2f(0.25, 0.25); glVertex2f(0.75, 0.25); //line 2 glVertex2f(0.75, 0.25); glVertex2f(0.75, 0.75); //line 3 glVertex2f(0.75, 0.75); glVertex2f(0.25, 0.75); //line 4 glVertex2f(0.25, 0.75); glVertex2f(0.25, 0.25); glEnd(); glFlush(); } void init(void) { glClearColor(1.0, 1.0, 1.0, 1.0);//Set window background color glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); }