Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Computer Graphics

 Computer Graphics


#include <GL/gl.h>

#include <GL/glu.h>

#include <GL/glut.h>

#include <stdlib.h>

#include<string>

#include<math.h>


/*void filledCircle(float rad, float xx, float yy)

{


float thetha = 2 * 3.1415 / 20;

float x, y;

//glColor3f(1.0, 1.0, 1.0);

glLineWidth(1.0);

glBegin(GL_TRIANGLE_FAN);

for (int i = 0; i < 20; i++) {

x = rad * cos(i*thetha) + xx;

y = rad*sin(i*thetha) + yy;

float z = 0;

glVertex3f(x, y, z);

}

glEnd();

}


void filledhalfCircle(float rad, float xx, float yy)

{


float thetha = 2*3.1415 / 20;

float x, y;

//glColor3f(1.0, 1.0, 1.0);

glLineWidth(1.0);

glBegin(GL_TRIANGLE_FAN);

for (int i = 0; i <=10; i++) {

x = rad * cos(i*thetha) + xx;

y = rad*sin(i*thetha) + yy;

float z = 0;

glVertex3f(x, y, z);

}

glEnd();

}

void reverseCircle(float rad, float xx, float yy)

{


float thetha = 2*3.1415 / 20;

float x, y;

//glColor3f(1.0, 1.0, 1.0);

glLineWidth(1.0);

glBegin(GL_TRIANGLE_FAN);

for (int i = 10; i <= 20; i++) {

x = rad * cos(i*thetha) + xx;

y = rad*sin(i*thetha) + yy;

float z = 0;

glVertex3f(x, y, z);

}

glEnd();

}

*/


void display(void)

{

    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_LINE_LOOP);

    for(double theta=0; theta<=100; theta+=0.01){

        double angle=2*3.1416*theta/100;

        double x=10*cos(angle);

        double y=10*sin(angle);

        glVertex2f(x,y);

    }

    glEnd();


   // filledCircle(10, 50, 25);

   // filledhalfCircle(10, 10, 25);

   // reverseCircle(10, -80, -25);

    glutSwapBuffers();


}


void init(void)


{

    glClearColor(0.28, 0.596, 0.16, 0.0);

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    glOrtho(-100.0, 100.0, -100.0, 100.0, -1.0, 1.0);

}


int main(int argc, char** argv)

{

   glutInit(&argc, argv);

   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);

   glutInitWindowSize (900, 700);

   glutInitWindowPosition (50, 10);

   glutCreateWindow (argv[0]);

   glutDisplayFunc(display);

    init();

   glutMainLoop();

   return 0;

}

Post a Comment

0 Comments