Kelompok.
1. Dino Arinanda (5C414929)
2. Wisnu Nirwono (5C414306)
3. M. Ridwan (56414992)
4. Ahmad Zaoharudin (5C414707)
5. Alfian Mahendra (50414412)
#include “stdafx.h”
#include <gl/glut.h>
bool fullscreen = false;
bool mouseDown = false;
float xrot = 0.0f;
float yrot = 0.0f;
float xdiff = 0.0f;
float ydiff = 0.0f;
void drawBox()
{
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(-0.2,-0.2,0.2);
glVertex3f(-0.2,-0.2,-0.2);
glVertex3f(-0.2,0.2,-0.2);
glVertex3f(-0.2,0.2,0.2);
glEnd();
//Sisi-sisi Prisma
glBegin(GL_TRIANGLES);
//Segitiga Warna Merah
glColor3f(1,0,0);
glVertex3f(-0.2,-0.2,0.2);
glVertex3f(0.8,0.0,0.0);
glVertex3f(-0.2,0.2,0.2);
//Segitiga Warna Hijau
glColor3f(0,1,0);
glVertex3f(-0.2,0.2,0.2);
glVertex3f(0.8,0.0,0.0);
glVertex3f(-0.2,0.2,-0.2);
//Segitiga Warna Biru
glColor3f(0,0,1);
glVertex3f(-0.2,0.2,-0.2);
glVertex3f(0.8,0.0,0.0);
glVertex3f(-0.2,-0.2,-0.2);
//Segitiga Warna Putih
glColor3f(1,2,1);
glVertex3f(-0.2,-0.2,-0.2);
glVertex3f(0.8,0.0,0.0);
glVertex3f(-0.2,-0.2,0.2);
glEnd();
}
bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
return true;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
drawBox();
glFlush();
glutSwapBuffers();
}
void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void idle()
{
if (!mouseDown)
{
xrot += 0.3f;
yrot += 0.4f;
}
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit(1); break;
}
}
void specialKeyboard(int key, int x, int y)
{
if (key == GLUT_KEY_F1)
{
fullscreen = !fullscreen;
if (fullscreen)
glutFullScreen();
else
{
glutReshapeWindow(500, 500);
glutPositionWindow(50, 50);
}
}
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;
xdiff = x – yrot;
ydiff = -y + xrot;
}
else
mouseDown = false;
}
void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x – xdiff;
xrot = y + ydiff;
glutPostRedisplay();
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow(“limas segitiga”);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKeyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutReshapeFunc(resize);
//glutIdleFunc(idle);
if (!init())
return 1;
glutMainLoop();
return 0;
}
No comments:
Post a Comment