Vizatimi I objektit te meposhtem eshte realizuar duke bere bashkimin e njepasnjeshem te disa kulmeve glVertex me
GL_LINE_LOOP. I njejti objekt do te mund te vizatohej duke perdorur bashkimin e disa vijave te njepasnjeshme me gGL_LINES por zgjedhja eshte ne doren tone.
Ushtrim:
Ndertoni ne OpenGl nje program qe vizaton nje objekt ne formen e shtepise
#include<gl/glut.h>
void
Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,0.0);
glVertex2f(10.0,10.0);
glVertex2f(30.0,10.0);
glVertex2f(30.0,30.0);
glVertex2f(20.0,40.0);
glVertex2f(10.0,30.0);
glEnd();
glFlush();
}
void
init()
{
glClearColor(1.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("Shtepi");
init();
glutDisplayFunc(Display);
glutMainLoop();
}
Ushtrim : Vizatoni nje shtepi me dere,dritare dhe cati
#include<gl/glut.h>
void
Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(0.0,1.0,0.0);
glVertex2f(8.0,5.0);
glVertex2f(40.0,5.0);
glVertex2f(40.0,25.0);
glVertex2f(8.0,25.0);
glColor3f(0.5,0.3,0.2);
glVertex2f(20.0,5.0);
glVertex2f(25.0,5.0);
glVertex2f(25.0,13.0);
glVertex2f(20.0,13.0);
glVertex2f(15.0,15.0);
glVertex2f(20.0,15.0);
glVertex2f(20.0,20.0);
glVertex2f(15.0,20.0);
glVertex2f(25.0,15.0);
glVertex2f(30.0,15.0);
glVertex2f(30.0,20.0);
glVertex2f(25.0,20.0);
glEnd();
glBegin(GL_TRIANGLES);
glVertex2f(2.0,25.0);
glVertex2f(45.0,25.0);
glVertex2f(25.0,40.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(300,300);
glutCreateWindow("Shtepi");
init();
glutDisplayFunc(Display);
glutMainLoop();
}
0 comments:
Post a Comment