Computer Science, asked by amlanphkn4654, 1 year ago

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

Answers

Answered by Shaizakincsem
4
#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;
}
Similar questions