Which line of code do i need to change to get the circle shape?

This is a discussion on Which line of code do i need to change to get the circle shape? within the C++ Programming forums, part of the General Programming Boards category; Hello everyone... Below is a complete sample application in OpenGL C ++. How can i get the same output but ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    1

    Unhappy Which line of code do i need to change to get the circle shape?

    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

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    76
    ewwww... lol GLAUX functions... I'd learn glut instead... but even glut is kinda being outdated...

    and where in your code are you using any functions from math.h?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 10:21 PM
  2. Newbie- having trouble with functions
    By bnmwad in forum C Programming
    Replies: 7
    Last Post: 02-22-2005, 03:41 PM
  3. how do you change the ctrl+C exit code?
    By Golden Bunny in forum Windows Programming
    Replies: 0
    Last Post: 04-09-2002, 02:18 PM
  4. how to line change in a console application
    By new2c++ in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2002, 08:20 PM
  5. What's wrong in this line of code?
    By marCplusplus in forum C++ Programming
    Replies: 12
    Last Post: 12-12-2001, 08:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21