A program in C/C++ using OpenGL to draw a circle of orange colour and inside that draw a square of blue colour.

Questions A program in C/C++ using OpenGL to draw a circle of orange colour and inside that draw a square of blue colour.
akankshat.ngPublished on: 10/18/2018 5:20:55 PM

 Write a program in C/C using OpenGL to draw a circle of orange colour and inside that draw a square of blue colour.


1 Answers
Best Answer 0
admin 10/16/2018 1:24:00 AM

Ans:

#include<windows.h>
#include <gl/glut.h>
#include <math.h>
const float PI=3.14;

void drawCircle(){
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
for(int i =0; i <= 300; i ){
double angle = 2 * PI * i / 300;
double x = 5*cos(angle);
double y = 5*sin(angle);
glVertex2d(x,y);
}
glEnd();
}
void drawRect(){
glColor3f(0.0,0.0,1.0);
glRectf(-5.0,5.0,5.0,-5.0);
}
void init(void){
glClearColor(0.0,1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0,10.0,-10.0,10.0,-10.0,10.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
drawRect();
drawCircle();
glutSwapBuffers();
}

int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(320,320);
glutInitWindowPosition(50,50);
glutCreateWindow("2D Shapes");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Edit