/* You can notice that while resizing the window... the contents inside the window are clipped. Instead, if you wish to have images that are indipendent of the resolution, you should convert scale from [0, windowWidth] to [-1, 1] and [0, windowHeight] to [-1, 1] By doing so, you can have images that are independent of the window size and you won't get your drawings clipped by the smaller size of window NOTE: To understand this concept well.... try resizing the window (for previous tutorials) */ # include # include # define USE_HARD_WAY 1 int WindowWidth = 256; int WindowHeight = 256; void Draw(void) { float left = -1.0f; float right = 1.0f; float top = 1.0f; float bottom = -1.0f; if(USE_HARD_WAY) { left = -WindowWidth/2.0f; right = -left; top = WindowHeight/2.0f; bottom = -top; } // r g b a glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINES); glVertex2f(0.0f, bottom); glVertex2f(0.0f, top); glVertex2f(left, 0.0f); glVertex2f(right, 0.0f); glEnd(); glFlush(); } void OnWindowResize(int width, int height) { //See how the output changes if you change left and top int left = 0; int bottom = 0; glViewport(left, bottom, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(USE_HARD_WAY) { gluOrtho2D(-width/2.0, width/2.0, -height/2.0, height/2.0); WindowWidth = width; WindowHeight = height; } else { gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f); } } void OnKeyPress(unsigned char key, int x, int y) { # define ESC_Key 27 switch (key) { case ESC_Key: exit(0); break; } //printf("\nThe mouse is @..(%d, %d)\n", x, y); } int main(int argc, char** argv) { const int left = 0; const int top = 0; const char* windowTitle = "Size matters!!!"; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WindowWidth, WindowHeight); glutInitWindowPosition(left, top); glutCreateWindow(windowTitle); glutDisplayFunc(Draw); glutReshapeFunc(OnWindowResize); glutKeyboardFunc(OnKeyPress); glutMainLoop(); return 0; } /* EXERCISE: Search for some "crop circles" in google images Create them using sines or circles or triangles or what ever... */ // // MORAL of this tutorial // ~~~~~~~~~~~~~~~~~~~~~~~~ // Big or small or medium ... you should learn how to play //