Selasa, 03 Oktober 2017

Tugas Praktikum Grafika Komputer

Berikut ini adalah tugas praktikum :

1.
a.       Titik
Coding :
#include <GL/glut.h>
void titik ();
main(int argc, char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(600,800);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan 1");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
               
                glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
glClear(GL_COLOR_BUFFER_BIT);

glPointSize(5.5);
glBegin(GL_POINTS);

glColor3f(1.0,1.0,1.0);
glVertex2f(0.25,0.25);

glColor3f(0.1,1.0,1.0);
glVertex2f(0.5,0.5);
//glPointSize(2.0);

glEnd();
glFlush();
}

Output:



b.       Titik Banyak
Coding :
#include <GL/glut.h>
void titik ();
main(int argc, char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(600,800);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan 1");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
               
                glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(5.5);
glBegin(GL_POINTS);

glColor3f(1.0,1.0,1.0);
glVertex2f(0.25,0.25);

glColor3f(0.1,1.0,1.0);
glVertex2f(0.5,0.5);

glColor3f(1.0,0.0,0.0);
glVertex2f(0.15,0.15);

glColor3f(1.0,0.0,1.0);
glVertex2f(0.50,0.50);

glColor3f(0.0,0.0,1.0);
glVertex2f(0.85,0.85);   

glEnd();
glFlush();
}

Output :


2.  Lines
Coding :
#include<GL/glut.h>
void titik();
main(int argc,char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(800,600);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan !");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
                glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
                //glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
                glClear(GL_COLOR_BUFFER_BIT);
                glBegin(GL_LINES);
                glColor3f(1.0,1.0,1.0);
                glVertex2f(0.25,0.25);
                glColor3f(0.1,1.0,1.0);
                glVertex2f(0.5,0.5);
                glVertex2f(0.75,0.5);
                glVertex2f(0.5,0.8);
                glPointSize(50.0f);
                glEnd();
                glFlush();
}

Output :

3. Stripe
Coding :
#include<GL/glut.h>
void titik();
main(int argc,char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(800,600);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan !");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
                //glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
                glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
                glClear(GL_COLOR_BUFFER_BIT);
                glBegin(GL_LINE_STRIP);
                glColor3f(1.0,0.0,0.0);
                glVertex2f(0.25,0.25);
                glColor3f(0.1,1.0,0.0);
                glVertex2f(0.5,0.5);
                glColor3f(0.0,0.0,1.0);
                glVertex2f(0.75,0.75);
                glVertex2f(0.7,0.8);
                glPointSize(50.0f);
                glEnd();
                glFlush();
}

Output :


4.   Segitiga
Coding :
#include<GL/glut.h>
void titik();
main(int argc,char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(800,600);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan !");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
                glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
                //glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
                glClear(GL_COLOR_BUFFER_BIT);
                glBegin(GL_LINES);
                glColor3f(0.1,0.1,1.0);
                glVertex2f(0.75,0.5);
                glColor3f(0.1,1.0,0.1);
                glVertex2f(0.25,0.5);

                glColor3f(0.0,0.0,1.0);
                glVertex2f(0.75,0.5);
                glColor3f(1.0,0.1,0.1);
                glVertex2f(0.5,0.9);

                glColor3f(0.1,1.0,0.1);
                glVertex2f(0.25,0.5);
                glColor3f(1.0,0.0,0.0);
                glVertex2f(0.5,0.9);                        
                glEnd();
                glFlush();
}


Output :


5.     Kubus
Coding :
#include <GL/glut.h>
void titik();
                main(int argc, char** argv)
{
                glutInit(&argc, argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(600,600);
                glutInitWindowPosition(100,100);
                glutCreateWindow("PERCOBAAN 2");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
                glutDisplayFunc(titik);
                glutMainLoop();
}
                void titik()
                {
                                glClear(GL_COLOR_BUFFER_BIT);
                                glBegin(GL_POLYGON);
                                glColor3f(1.0,1.0,0.0); //persegi ungu
                glVertex2f(-0.5,-0.5);
               glVertex2f(-0.5,0.5);
               glVertex2f(0.5,0.5);
               glVertex2f(0.5,-0.5);
               glEnd();
                                glFlush();
                } //untuk mengeksekusi opengL infinite time

Output :



6.    Pelangi
Coding :
#include<GL/glut.h>
void titik ();
main(int argc, char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(800,600);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan 2");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
                glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
               
                glutDisplayFunc(titik);
                glutMainLoop();
}
void titik()
{
                glClear(GL_COLOR_BUFFER_BIT);
                glBegin(GL_LINES);
               
                glColor3f(1.0,0.0,0.0);
                glVertex2f(0.5,0.7);
                glColor3f(0.0,0.0,0.0);
                glVertex2f(0.5,0.9);
               
                glColor3f(0.0,1.0,0.0);
                glVertex2f(0.8,0.3);
                glColor3f(0.0,1.0,0.0);
                glVertex2f(0.2,0.2);
               
                glColor3f(0.0,0.0,1.0);
                glVertex2f(0.6,0.9);
                glColor3f(0.0,0.0,1.0);
                glVertex2f(0.4,0.4);
               
                glColor3f(1.0,5.0,0.0);
                glVertex2f(0.15,0.3);
                glColor3f(1.0,5.0,0.0);
                glVertex2f(0.7,0.7);
               
                glColor3f(0.0,5.0,0.0);
                glVertex2f(0.55,0.8);
                glColor3f(0.1,1.0,1.0);
                glVertex2f(0.10,0.9);
               
                                glColor3f(1.0,0.0,1.0);
                glVertex2f(0.3,0.9);
                glColor3f(1.0,0.0,1.0);
                glVertex2f(0.5,0.5);
               
                                glColor3f(1.0,1.0,1.0);
                glVertex2f(0.8,0.15);
                glColor3f(1.0,1.0,1.0);
                glVertex2f(0.7,0.3);
               
               
                glPointSize(50.0f);
                glEnd();
                glFlush();
}

Output :


7.    Kubus dalam kubus
Coding :
#include<GL/glut.h>
void titik();


void titik()
{
                glClear(GL_COLOR_BUFFER_BIT); //merah
                glBegin(GL_POLYGON);
                glColor3f(0.0,1.0,0.0);    
                glVertex2f(-0.7f,-0.7f);
                glVertex2f(-0.7f,0.7f);
                glVertex2f(0.7f,0.7f);
                glVertex2f(0.7f,-0.7f);
                glVertex2f(-0.7f,-0.7f);
                glPointSize(50.0f);
                glEnd();//akhir perintah OpenGL

   
                glBegin(GL_POLYGON);
                glColor3f(1.0,0.0,0.0);    
                glVertex2f(-0.3f,-0.3f);
                glVertex2f(-0.3f,0.3f);
                glVertex2f(0.3f,0.3f);
                glVertex2f(0.3f,-0.3f);
                glVertex2f(-0.3f,-0.3f);
                glPointSize(50.0f);
                glEnd();//akhir perintah OpenGL              
                glFlush();//untuk mengeksekusi openGL infinite time
}

main(int argc, char** argv)
{
                glutInit(&argc,argv);
                glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
                glutInitWindowSize(800,800);
                glutInitWindowPosition(100,100);
                glutCreateWindow("Percobaan 3");
                glClearColor(0.0,0.0,0.0,0.0);
                glMatrixMode(GL_PROJECTION);
//            glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
                glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
                glutDisplayFunc(titik);
                glutMainLoop();
}

Output :


Terima Kasih telah mengunjungi blog ini. Semoga bermanfaat bagi pembaca.

Tidak ada komentar:

Posting Komentar