Hello everyone...
Below is a complete sample application in OpenGL C ++.
How can i get the same output but the shape must be circle??
which line of coding do i need to change?
Please help me here.
It is urgent.
Thanks alot
Ram
----------------------------------------------------------------
Code:#include <windows.h> #include <gl\gl.h> #include <gl\glaux.h> #include<math.h> //initial square position and its size GLfloat x=250.0f; GLfloat y=0.0f; GLsizei rsize=50; GLfloat x2=0.0f; GLfloat y2=0.0f; GLfloat x3=250.0f; GLfloat y3=250.0f; GLfloat x4=0.0f; GLfloat y4=250.0f; //step size in x and y directions //number of pixels to move each time GLfloat xstep=0.10f; GLfloat ystep=0.10f; GLfloat x2step=0.10f; GLfloat y2step=0.10f; GLfloat x3step=0.10f; GLfloat y3step=0.10f; GLfloat x4step=0.10f; GLfloat y4step=0.10f; //keep track of window's changing width and height GLfloat windowWidth; GLfloat windowHeight; //called by AUX library when the windows has changed size void CALLBACK ChangeSize(GLsizei w, GLsizei h) { //prevent a divide by zero. when window is too short // you cannot make a window zero width if(h==0) h=1; //set the viewport to be the entire window glViewport(0,0,w,h); //Reset the coordinate system before modifying glLoadIdentity(); //keep the square square, this time, save calculated width and height for later use if(w<=h) { windowHeight=250.0f*h/w; windowWidth=250.0f; } else { windowWidth=250.0f * w/h; windowHeight=250.0f; } //set the clipping volume glOrtho(1.0f, windowWidth, 0.01, windowHeight, 1.0f, -1.0f); } //called by AUX library to update window void CALLBACK RenderScene(void) { glClearColor(0.0f,0.0f,1.0f,0.0f); glClear(GL_COLOR_BUFFER_BIT); //set drawing color to red and draw rectangle at current position glColor3f(0.0f,1.0f,0.0f); glRectf(x2,y2,x2+rsize,y2+rsize); glColor3f(1.0f,0.0f,0.0f); glRectf(x3,y3,x3+rsize,y3+rsize); glColor3f(1.0f,0.0f,0.0f); glRectf(x4,y4,x4+rsize,y4+rsize); glColor3f(1.0f, 1.0f, 0.0f); glRectf(x,y,x+rsize,y+rsize); glFlush(); } //called by AUX library when idle(window not being resized or moved) void CALLBACK IdleFunction(void) { //reverse direction when you reach let or right edge if(x>windowWidth-rsize || x<0) xstep=-xstep; //reverse direction when you reach top or bottom edge if(y>windowHeight-rsize || y<0) ystep=-ystep; //check bounds. This is in case the window is made smaller and the retangle is outside the new clipping volume if(x>windowWidth-rsize) x=windowWidth-rsize-1; if(y>windowHeight-rsize) y=windowHeight-rsize-1; //Actually move the square x+=xstep; y+=ystep; //reverse direction when you reach left or right edge if(x2>windowWidth-rsize || x2<0) x2step=-x2step; //reverse direction when you reach top or bottom edge if(y2>windowHeight-rsize || y2<0) y2step=-y2step; //check bounds. This is in case the window is made smaller and the rectangle is outside the new clipping volume if(x2>windowWidth-rsize) x2=windowWidth-rsize-1; if(y2>windowHeight-rsize) y2=windowHeight-rsize-1; if(x3>windowWidth-rsize || x3<0) x3step=-x3step; //reverse direction when you reach top or bottom edge if(y3>windowHeight-rsize || y3<0) y3step=-y3step; //check bounds. This is in case the window is made smaller and the rectangle is outside the new clipping volume if(x3>windowWidth-rsize) x3=windowWidth-rsize-1; if(y3>windowHeight-rsize) y3=windowHeight-rsize-1; if(x4>windowWidth-rsize || x4<0) x4step=-x4step; //reverse direction when you reach top or bottom edge if(y4>windowHeight-rsize || y4<0) y4step=-y4step; //check bounds. This is in case the window is made smaller and the rectangle is outside the new clipping volume if(x4>windowWidth-rsize) x4=windowWidth-rsize-1; if(y4>windowHeight-rsize) y4=windowHeight-rsize-1; //Actually move the square x2+=x2step; y2+=y2step; x3+=x3step; y3+=y3step; x4+=x4step; y4+=y4step; //redraw the scene with new coordinates RenderScene(); } //main body of the program void main(void) { //aux window setup and initialization auxInitDisplayMode(AUX_DOUBLE || AUX_RGBA); auxInitPosition(100,100,250,250); auxInitWindow("Assignment 1"); //set function to call when window is resized auxReshapeFunc(ChangeSize); auxIdleFunc(IdleFunction); //start main loop auxMainLoop(RenderScene); } //GLAUX.LIB GLU32.LIB glut32.lib glut.lib OPENGL32.LIB



LinkBack URL
About LinkBacks


