Rabu, 07 Oktober 2015

graf lanjut 3

/*Praktikum 03
* Membuat objek 3D dengan OpenGL
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>

void drawCubic()
{
GLfloat p=3.0f;
glBegin(GL_QUADS); //
//up
glColor3f(0.0f, 1.0f, 0.0);
glVertex3f(-p, p, p);
glVertex3f(p, p, p);
glVertex3f(p, p, -p);
glVertex3f(-p, p, -p);
//bottom
glColor3f(0.0f, 0.0f, 0.0);
glVertex3f(-p, -p, p);
glVertex3f(p, -p, p);
glVertex3f(p, -p, -p);
glVertex3f(-p, -p, -p);
//right
glColor3f(1.0f, 0.0f, 0.0);
glVertex3f(p, p, p);
glVertex3f(p, p, -p);
glVertex3f(p, -p, -p);
glVertex3f(p, -p, p);
//left
glColor3f(0.0f, 0.0f, 1.0);
glVertex3f(-p, p, p);
glVertex3f(-p, p, -p);
glVertex3f(-p, -p, -p);
glVertex3f(-p, -p, p);
//d
glColor3f(0.0f, 1.0f, 1.0);
glVertex3f(-p, p, p);
glVertex3f(p, p, p);
glVertex3f(p, -p, p);
glVertex3f(-p, -p, p);
//b
glColor3f(1.0f, 1.0f, 1.0);
glVertex3f(-p, p, -p);
glVertex3f(p, p, -p);
glVertex3f(p, -p, -p);
glVertex3f(-p, -p, -p);

glEnd();
}
void display(void)
{
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glColor3f(1.0f, 0.0f, 0.0f); //Defining color
 //glutWireTeapot(3.0);// Creates a Tea Pot
 drawCubic();
 glFlush ();
}
void init (void)
{
 glClearColor (0.5, 0.5, 0.5, 0.0);
 glEnable(GL_DEPTH_TEST); //enabling z-buffer
 glMatrixMode (GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(35.0, 1.0, 1.0, 100.0);
 glMatrixMode (GL_MODELVIEW);
 glLoadIdentity();
 gluLookAt (-10.0, -5.0, -10.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
}
int main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
 glutInitWindowSize (600, 600);
 glutInitWindowPosition (300, 300);
 glutCreateWindow ("Pamungkas Bayu Aji_12018050_postest");
 init ();
 glutDisplayFunc(display);
 glutMainLoop();
 return 0;
}

0 comments:

Posting Komentar

"bayuaji-master.blogspot.com". Diberdayakan oleh Blogger.