Rabu, 19 Oktober 2016

TUGAS 2 GRAFIK KOMPUTER MEMBUAT OBJEK 3D SEGITIGA

Diposting oleh Unknown di 23.38 0 komentar
Nama Kelompok :

1. Arief Hidayat (51414566)
2. Bentar Adhityajaya Pangestu (52414134)
3. Fajar Tri Suhadi (53414889)
4. Osman Tri Prakoso (58414356)
5. Yuli Marlena (5C414531)

Kelas : 3IA12

Pada postan ini kami akan menunjukann membuat objek 3D dengan devC++ dan library openGL , kami membuat segitiga tapii dalam bentuk 3D.

kodingannya :
/*
 * OGL02Animation.cpp: 3D Shapes with animation
 */
#include <GL/glut.h>  // GLUT, include glu.h and gl.h

/* Global variables */
char title[] = "3D Shapes with animation";
GLfloat anglePyramid = 0.0f;  // Rotational angle for pyramid [NEW]
GLfloat angleCube = 0.0f;     // Rotational angle for cube [NEW]
int refreshMills = 15;        // refresh interval in milliseconds [NEW]

/* Initialize OpenGL Graphics */
void initGL() {
   glClearColor(255.0f, 255.0f, 255.0f, 1.0f); // Set background color to black and opaque
   glClearDepth(1.0f);                   // Set background depth to farthest
   glEnable(GL_DEPTH_TEST);   // Enable depth testing for z-culling
   glDepthFunc(GL_LEQUAL);    // Set the type of depth-test
   glShadeModel(GL_SMOOTH);   // Enable smooth shading
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Nice perspective corrections
}

/* Handler for window-repaint event. Called back when the window first appears and
   whenever the window needs to be re-painted. */
void display() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
   glMatrixMode(GL_MODELVIEW);     // To operate on model-view matrix


   // Render a pyramid consists of 4 triangles
   glLoadIdentity();                  // Reset the model-view matrix
   glTranslatef(0.0f, 0.0f, -6.0f);  // Move left and into the screen
   glRotatef(anglePyramid, 1.0f, 1.0f, 0.0f);  // Rotate about the (1,1,0)-axis [NEW]
  
   glBegin(GL_POLYGON);
   //Alas1
      glColor3f(0.0f, 0.0f, 1.0f);    
                  glVertex3f( 1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
                  glVertex3f(-1.0f, -1.0f,  1.0f);
     
   glEnd();   // Done drawing the pyramid

  
      glBegin(GL_POLYGON);           // Begin drawing the pyramid with 4 triangles

                //front RED
                glColor3f(255.0f, 0.0f, 128.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f, -1.0f, 1.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);


      // Back GREEN
      glColor3f(0.0f, 1.0f, 0.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);

      // Left BLUE
      glColor3f(0.0f,128.0f,255.0f);     
      glVertex3f( 0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f,-1.0f,-1.0f);
      glVertex3f(-1.0f,-1.0f, 1.0f);
     
  
   glEnd();   // Done drawing the pyramid

   glutSwapBuffers();  // Swap the front and back frame buffers (double buffering)

   // Update the rotational angle after each refresh [NEW]
   anglePyramid += 1.2f;
   angleCube -= 0.15f;
}

/* Called back when timer expired [NEW] */
void timer(int value) {
   glutPostRedisplay();      // Post re-paint request to activate display()
   glutTimerFunc(refreshMills, timer, 0); // next timer call milliseconds later
}

/* Handler for window re-size event. Called back when the window first appears and
   whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) {  // GLsizei for non-negative integer
   // Compute aspect ratio of the new window
   if (height == 0) height = 1;                // To prevent divide by 0
   GLfloat aspect = (GLfloat)width / (GLfloat)height;

   // Set the viewport to cover the new window
   glViewport(0, 0, width, height);

   // Set the aspect ratio of the clipping volume to match the viewport
   glMatrixMode(GL_PROJECTION);  // To operate on the Projection matrix
   glLoadIdentity();             // Reset
   // Enable perspective projection with fovy, aspect, zNear and zFar
   gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}

/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
   glutInit(&argc, argv);            // Initialize GLUT
   glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
   glutInitWindowSize(640, 480);   // Set the window's initial width & height
   glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
   glutCreateWindow(title);          // Create window with the given title
   glutDisplayFunc(display);       // Register callback handler for window re-paint event
   glutReshapeFunc(reshape);       // Register callback handler for window re-size event
   initGL();                       // Our own OpenGL initialization
   glutTimerFunc(0, timer, 0);     // First timer call immediately [NEW]
   glutMainLoop();                 // Enter the infinite event-processing loop
   return 0;

}/*
 * OGL02Animation.cpp: 3D Shapes with animation
 */
#include <GL/glut.h>  // GLUT, include glu.h and gl.h

/* Global variables */
char title[] = "3D Shapes with animation";
GLfloat anglePyramid = 0.0f;  // Rotational angle for pyramid [NEW]
GLfloat angleCube = 0.0f;     // Rotational angle for cube [NEW]
int refreshMills = 15;        // refresh interval in milliseconds [NEW]

/* Initialize OpenGL Graphics */
void initGL() {
   glClearColor(255.0f, 255.0f, 255.0f, 1.0f); // Set background color to black and opaque
   glClearDepth(1.0f);                   // Set background depth to farthest
   glEnable(GL_DEPTH_TEST);   // Enable depth testing for z-culling
   glDepthFunc(GL_LEQUAL);    // Set the type of depth-test
   glShadeModel(GL_SMOOTH);   // Enable smooth shading
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Nice perspective corrections
}

/* Handler for window-repaint event. Called back when the window first appears and
   whenever the window needs to be re-painted. */
void display() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
   glMatrixMode(GL_MODELVIEW);     // To operate on model-view matrix


   // Render a pyramid consists of 4 triangles
   glLoadIdentity();                  // Reset the model-view matrix
   glTranslatef(0.0f, 0.0f, -6.0f);  // Move left and into the screen
   glRotatef(anglePyramid, 1.0f, 1.0f, 0.0f);  // Rotate about the (1,1,0)-axis [NEW]
  
   glBegin(GL_POLYGON);
   //Alas1
      glColor3f(0.0f, 0.0f, 1.0f);    
                  glVertex3f( 1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
                  glVertex3f(-1.0f, -1.0f,  1.0f);
     
   glEnd();   // Done drawing the pyramid

  
      glBegin(GL_POLYGON);           // Begin drawing the pyramid with 4 triangles

                //front RED
                glColor3f(255.0f, 0.0f, 128.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f, -1.0f, 1.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);


      // Back GREEN
      glColor3f(0.0f, 1.0f, 0.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);

      // Left BLUE
      glColor3f(0.0f,128.0f,255.0f);     
      glVertex3f( 0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f,-1.0f,-1.0f);
      glVertex3f(-1.0f,-1.0f, 1.0f);
     
  
   glEnd();   // Done drawing the pyramid

   glutSwapBuffers();  // Swap the front and back frame buffers (double buffering)

   // Update the rotational angle after each refresh [NEW]
   anglePyramid += 1.2f;
   angleCube -= 0.15f;
}

/* Called back when timer expired [NEW] */
void timer(int value) {
   glutPostRedisplay();      // Post re-paint request to activate display()
   glutTimerFunc(refreshMills, timer, 0); // next timer call milliseconds later
}

/* Handler for window re-size event. Called back when the window first appears and
   whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) {  // GLsizei for non-negative integer
   // Compute aspect ratio of the new window
   if (height == 0) height = 1;                // To prevent divide by 0
   GLfloat aspect = (GLfloat)width / (GLfloat)height;

   // Set the viewport to cover the new window
   glViewport(0, 0, width, height);

   // Set the aspect ratio of the clipping volume to match the viewport
   glMatrixMode(GL_PROJECTION);  // To operate on the Projection matrix
   glLoadIdentity();             // Reset
   // Enable perspective projection with fovy, aspect, zNear and zFar
   gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}

/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
   glutInit(&argc, argv);            // Initialize GLUT
   glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
   glutInitWindowSize(640, 480);   // Set the window's initial width & height
   glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
   glutCreateWindow(title);          // Create window with the given title
   glutDisplayFunc(display);       // Register callback handler for window re-paint event
   glutReshapeFunc(reshape);       // Register callback handler for window re-size event
   initGL();                       // Our own OpenGL initialization
   glutTimerFunc(0, timer, 0);     // First timer call immediately [NEW]
   glutMainLoop();                 // Enter the infinite event-processing loop
   return 0;
}

Dan outputnya :



Rabu, 12 Oktober 2016

TUGAS 1 GRAFIK KOMPUTER MEMBUAT BENTUK DASAR DENGAN OPEN GL

Diposting oleh Unknown di 20.25 0 komentar
Nama Kelompok :
1. Arief Hidayat (51414566)
2. Bentar Adhityajaya Pangestu (52414134)
3. Fajar Tri Suhadi (53414889)
4. Osman Tri Prakoso (58414356)
5. Yuli Marlena (5C414531)

Kelas : 3IA12

Pada tugas  kali ini kami akan membuat bentuk dasar dan bangun ruang menggunakan DevC++ dengan library openGL.
 Disini kami membuat 4 garis :
  • harizontal
  • vertikal
  • diagonal
  • garis bebas
serta kami juga membuat 3 ruang :
  • Segitiga outline dan segitiga full area
  • Segiempat full area  dan segitempat outline
  • polygon full area dan polygon outline
Cara membuatnya pertama-tama kita buka aplikasi DevC++ kemudian kita buka library openGL dan ketikan kodingan dibawah ini :


1. Garis Harizontal


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();     
            glBegin (GL_LINES);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (-0.8f, 0.0f);
                                                glVertex2f (0.8f, 0.0f);        
            glEnd ();
            glPopMatrix ();
            SwapBuffers (hDC);
            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Harizontal


2. Garis Vertikal


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
          
            glBegin (GL_LINES);
            glColor3f (128.0f, 255.0f, .0f); 
                                                glVertex2f (0.0f, -0.7f);
                                                glVertex2f (0.0f, 0.7f);
         
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Vertikal

3. Diagonal

glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();
            glBegin (GL_LINES);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (-0.7f, 0.7f);
                                                glVertex2f (0.7f, -0.7f);
         
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Diagonal


4. Garis bebas


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();
            glBegin (GL_LINES);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (-0.7f, -0.1f);
                                                glVertex2f (0.7f, 0.3f);
                                              
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Garis Bebas


5.Segitiga Outline


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
          
            glBegin (GL_LINE_LOOP);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.3f, 0.5f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (0.2f, 0.0f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.3f, -0.5f);
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);
       
                }
    }

Output :
Output Seigitiga Outline


6. Segitiga Fill Area


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
          
            glBegin (GL_TRIANGLES);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.3f, 0.5f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (0.2f, 0.0f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.3f, -0.5f);
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);
       
                }
    }

Outputnya: 
Output Segitiga Full Area


7. Segiempat Outline


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
          
            glBegin (GL_LINE_LOOP);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (-0.8f, -0.8f);
                                                    glVertex2f (-0.8f, 0.8f);
                                                    glVertex2f (0.8f, 0.8f);
                                                   glVertex2f (0.8f, -0.8f);
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :


Output Segiempat Outline



8. Segiempat Full Area


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();
          
            glBegin (GL_POLYGON);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.8f, -0.8f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (-0.8f, 0.8f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (0.8f, 0.8f);
            glColor3f (128.0f, 255.0f, 0.0f);   glVertex2f (0.8f, -0.8f);
                                                glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Segiempat Full Area


9. Polygon Outline


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            glPushMatrix ();
          
            glBegin (GL_LINE_LOOP);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (0.0f, 0.8f);
            glVertex2f (-0.7f, 0.3f);
            glVertex2f (-0.4f, -0.7f);
            glVertex2f (0.3f, -0.5f);
            glVertex2f (0.8f, -0.1f);
                                                glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outputnya :
Output Polygon Outline



10. Polygon Full Area


glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
          
            glBegin (GL_POLYGON);
            glColor3f (128.0f, 255.0f, 0.0f); 
                                                glVertex2f (0.0f, 0.8f);
            glVertex2f (-0.7f, 0.3f);
            glVertex2f (-0.4f, -0.7f);
            glVertex2f (0.3f, -0.5f);
            glVertex2f (0.8f, -0.1f);
                                                glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);        }
    }

Outpuntnya :
Output Polygon Full Area






 


 

Your Life Is Your Choose Template by Ipietoon Blogger Template | Gadget Review