Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Write a program in C/C++ using OpenGL to draw a circle of red colour inside of a
triangle of blue colour on a background of yellow colour.
Progam:
#include <gl.h>
#include <glu.h>
#include <glut.h>
void initGL()
{
glClearColor(1.0f, 1.0f, 0.0f);// Set background clearing color to yellow
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current
clearing color
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 1.0f); // Magenta
glVertex2f(0.1f, -0.6f);
glVertex2f(0.7f, -0.6f);
glVertex2f(0.4f, -0.1f);
Program
*/- Line clipping using cohen- sutherland algo -*/
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void main()
{
float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;
int gd,gm;
detectgraph (&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
cout<<"\n\n\t Enter the co-ordinates of Line :";
cout"\n\n\tX1 Y1 : ";
cin>>x1>>y1;
cout<<"\n\n\tX2 Y2 :";
cin>>x2>>y2;
cout<<"\n\tEnter the co_ordinates of window :\n ";
cout<<"\n\txwmin , ywmin : ";
cin>> xwmin>>ywmin ;
cout<<"\n\txwmax , ywmax : ";
cin>>xwmax>>ywmax ;
line(x1,y1,x2,y2);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();
cleardevice();
lineclipping(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax ); //calling clipping function
getch();
closegraph();
}
Solution
#include <gl.h>
#include <glu.h>
#include <glut.h>
init GL( );
glvertex 3f (-1. 0 f , - 0.5 f , - 4.0f);
glvertex 3f (1. 0 f , - 0.5 f , - 4.0f);
glvertex 3f (0. 0 f , - 0.5 f , - 4.0f);
glvertex 3f (0. 0 f , - 0.9 f , - 4.0f);
glvertex 3f (1. 0 f, - 0.0f, 0.0f);
glvertex 2f (-1. 8 f , - 0.1f );
glvertex 2f (-1. 2 f , - 0.1f );
glvertex 2f (-1. 2 f , - 0.7f );
glvertex 2f (-1. 8 f , - 0.7f );
glvertex 2f (-3.0 f , - 2.9f );
glEnd ( );
}
Q u e s: 4
Write a program in C/C++ using OpenGL to perform a 3-Dimensional transformation,
such as translation ,rotation and reflection, on a given rectangle.
Program:
#include <iostream.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
void draw3d(int ,int [ ] ,int[ ],int ,int ,int );
void draw3d(int fs,int x[20],int y[20],int tx , int ty, int d)
{
int i,j,k=0;
for(j=0;j<2;j++)
{
for(i=0;i<fs;i++)
{
if(i!=fs-1)
line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k);
else
line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k);
}
k=d;
}
for(i=0;i<fs;i++)
{
line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d);
}
}
void main()
{
int gd=DETECT,gm;
int x[20],y[20],tx=0,ty=0,i,fs,d;
initgraph(&gd,&gm,"");
cout<<"no of sides (front view only) : ";
cin>>fs;
cout<<"co-ordinates : ";
for(i=0;i<fs;i++)
{
cout<<i<<i;
cin>>x[i]>>y[i];
}
cout<<"Depth :";
cin>>d;
draw3d(fs,x,y,tx,ty,d);
cout<<"translation (x,y)";
cin>>tx>>ty;
draw3d(fs,x,y,tx,ty,d);
getch();
}