// Program to demonstrate how to open a window size and position it properly #include #include int wide=300, high=300; // Global Variables for Length and Width int winX=40, winY=40; // X and Y positions for window void drawAxis(); void drawAxis () { glColor3f(1.0, 0.0, 1.0); glBegin(GL_LINES); glVertex3f(0.0, -100.0, 0.0); glVertex3f(0.0, 100.0, 0.0); glVertex3f(-100.0, 0.0, 0.0); glVertex3f(100.0, 0.0, 0.0); glEnd(); } void DrawGraph() // The Drawing Routine { double x,y; glColor3f(1.0, 1.0, 0.0); // Set drawing color to yellow glBegin( GL_POINTS ); // Start drawing POINTS for (x = -100; x <= 100; x += .001) // Step from -1 to +1 by 0.001 { y = 4*x - 4*x*x + 50; // Calculate y value of parabola glVertex3f(x, y, 0.0); // Plot point at (x,y) z=0 in 2D } glEnd(); // End drawing points } void display(void) { /* clear all pixels */ glClear(GL_COLOR_BUFFER_BIT); drawAxis(); DrawGraph(); // Call my Drawing Routine glFlush(); // Force writing all pending OpenGL actions to the screen. } void myinit(void) { /* select clearing (background) color */ glClearColor(0.5, 0.5, 0.5, 0.0); // These RGB values make gray /* initialize viewing values */ glMatrixMode(GL_PROJECTION); // Select Matrix Mode glLoadIdentity(); // Provide Base Matrix glOrtho(-20.0, 20.0, -50.0, 50.0, -1.0, 1.0); // Set window dimensions // Parameters: glOrtho(Left, Right, Bottom, Top, Front, Back) } /* Declare initial window size, position, and display mode */ int main(int argc, char* argv[]) { printf("Creating window %d pixels wide and %d pixels high", wide, high); printf(" at (%d,%d).\n", winX, winY); glutInit(&argc, argv); // Call glut's initialization routine glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); // Set Single Buffer, RGB Color glutInitWindowSize(wide, high); // Initialize window size glutInitWindowPosition(winX,winY); // Position window glutCreateWindow("My Window"); // Actually create window with title myinit(); // Call my initialization routine glutDisplayFunc(display); // Call my display routine glutMainLoop(); // Fall into glut's main event loop return 0; }