// OPEN_GL_test.cpp : Defines the entry point for the console application. #include "stdafx.h" #define GL_PI 3.1415f // Keep track of windows changing width and height GLfloat windowWidth; GLfloat windowHeight; // Called to draw scene void RenderScene(void) {GLfloat xRot = 0.3f; GLfloat yRot = 0.5f; GLfloat x,y,z,angle; // Storage for coordinates and angles // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt (0.3, -0.3, -1.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Call only once for all remaining points glBegin(GL_POINTS); z = -50.0f; for(angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.2f) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); // Specify the point and move the Z value up a little glVertex3f(x, y, z); z += 0.01f; } glEnd(); // Flush drawing commands glFlush(); } // Setup the rendering state void SetupRC() {glClearColor(0.0f, 0.0f, 0.0f, 1.0f );// Black background glColor3f(0.0f, 1.0f, 0.0f); // Set drawing color to green } // Called by GLUT library when the window has changed size void ChangeSize(GLsizei w, GLsizei h) { GLfloat aspectRatio; if(h == 0) h = 1; // Prevent a divide by zero glViewport(0, 0, w, h); // Set Viewport to window dimensions glMatrixMode(GL_PROJECTION); // Reset coordinate system glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) aspectRatio = (GLfloat)w / (GLfloat)h; if (w <= h) { windowWidth = 100; windowHeight = 100 / aspectRatio; glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -50.0); } else { windowWidth = 100 * aspectRatio; windowHeight = 100; glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -50.0); } } /////////////////////////////////////////////////////////// int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutCreateWindow (argv[0]); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return 0; }