All tutorials in one place.

Friday, July 15, 2016

6. Vizatime te tjera dydimensionale, koncepti i perspektives

Per  te realizuar nje vizatim ne perspektive mjafton te krijojme nje funksion I cili e vizaton objektin vetem 1 here dhe pastaj kete funksion e therrasim aq here sa duam ne funksionin Display() duke e zmadhuar ose zvogeluar ne baze te nje koeficienti per te krijuar idene e perspektives ne syrin e njeriut.
Ushtrim: Ndertoni nje program qe te vizatoje 10 peme ne perspektive

#include<gl/glut.h>
void tree(int x, int y, float size)
{
  glBegin(GL_QUADS);
  glColor3f(0.6,0.2,0.2);
  glVertex2f(x,y);
  glVertex2f(x+20*size,y);
  glVertex2f(x+20*size,y+50*size);
  glVertex2f(x,y+50*size);
  glColor3f(0.0,1.0,0.0);
  glVertex2f(x-5*size,y+60*size);
  glVertex2f(x+10*size,y+40*size);
  glVertex2f(x+25*size,y+60*size);
  glVertex2f(x+10*size,y+100*size);
  glEnd();
}
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  int x=300;
  int y=300;
  float size=0.2;
  for(int i=0;i<10;i++)
  {
  tree(x,y,size);
  x-=40*size;
  y-=40;
  size+=0.2;
  }
  glFlush();
}
void init()
{
  glClearColor(0.0,0.0,0.0,1.0);
  glViewport(0,0,500,500);
  gluOrtho2D(0.0,300.0,0.0,300.0);
}
int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(500,500);
  glutCreateWindow("Peme");
  init();
  glutDisplayFunc(Display);
  glutMainLoop();
}
Ushtrim: Ndertoni nje program qe vizaton nje yll

#include<gl/glut.h>
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_LINE_LOOP); //bashkimi I pikave me nje vije te vazhduar te mbyllur
  glColor3f(0.0,1.0,1.0);
  glVertex2f(12.0,4.0);
  glVertex2f(27.0,19.0);
  glVertex2f(45.0,4.0);
  glVertex2f(40.0,27.0);
  glVertex2f(58.0,37.0);
  glVertex2f(36.0,37.0);
  glVertex2f(29.0,60.0);
  glVertex2f(23.0,38.0);
  glVertex2f(0.0,38.0);
  glVertex2f(15.0,26.0);
  glEnd();
  glFlush();
}
void init()
{
  glClearColor(0.0,0.0,0.0,1.0);
  glViewport(0,0,320,240);
  gluOrtho2D(0.0,160.0,0.0,120.0);
}
int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(320,240);
  glutCreateWindow("Yll");
  init();
  glutDisplayFunc(Display);
  glutMainLoop();
}
Ushtrim: Ndertoni nje program ne OpenGL qe vizaton nje makine

#include<gl/glut.h>
#include<math.h>
#define PI 3.14
GLint n=100;
void rrethi2f(float x,float y, float rreze){
GLint i;
GLdouble theta;
glBegin(GL_POLYGON);
for(i=0;i<n;i++){
theta=2*PI*i/n; //kendi ne radian
glVertex2f(x+rreze*cos(theta), y+rreze*sin(theta));
}
glEnd();
}
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_QUADS);
  glColor3f(0.0,0.7,0.3);
  glVertex2f(5.0,20.0);
  glVertex2f(70.0,20.0);
  glVertex2f(70.0,30.0);
  glVertex2f(5.0,30.0);
  glColor3f(1.0,0.0,0.0);
  glVertex2f(20.0,30.0);
  glVertex2f(45.0,30.0);
  glVertex2f(45.0,40.0);
  glVertex2f(20.0,20.0);
  glColor3f(1.0,1.0,1.0);
  glVertex2f(30.0,30.0);
  glVertex2f(40.0,30.0);
  glVertex2f(40.0,35.0);
  glVertex2f(30.0,35.0);
  glEnd();
  rrethi2f(23.0,15.0,6.0);
  rrethi2f(56.0,15.0,6.0);
  glFlush();
}
void init()
{
  glClearColor(0.0,0.0,0.0,1.0);
  glViewport(0,0,320,240);
  gluOrtho2D(0.0,160.0,0.0,120.0);
}
int main(int argc,char* argv [])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(320,240);
  glutCreateWindow("Makine");
  init();
  glutDisplayFunc(Display);
  glutMainLoop();
}
Share:

0 comments:

Post a Comment

Popular Posts

Categories

Tutorials House. Powered by Blogger.

Labels