0% found this document useful (0 votes)
20 views4 pages

Kubus: Nonik Putri/5171311006/PTM3

This document describes code for rendering 3D shapes like cubes, toruses, cones, teapots, and spheres in OpenGL. It includes functions for rendering each shape with different colors and rotations, as well as functions for handling keyboard input, window resizing, and a display timer. The key functions are renderScene() which draws the shapes, resize() for window resizing, myKeyboard() for input handling, and timer() for the display timer. Overall routines and formulas for interactive 3D rendering of basic shapes are presented.

Uploaded by

nn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Kubus: Nonik Putri/5171311006/PTM3

This document describes code for rendering 3D shapes like cubes, toruses, cones, teapots, and spheres in OpenGL. It includes functions for rendering each shape with different colors and rotations, as well as functions for handling keyboard input, window resizing, and a display timer. The key functions are renderScene() which draws the shapes, resize() for window resizing, myKeyboard() for input handling, and timer() for the display timer. Overall routines and formulas for interactive 3D rendering of basic shapes are presented.

Uploaded by

nn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Nonik Putri/5171311006/PTM3

1. KUBUS
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,0,0);
glLoadIdentity();
glTranslatef(0,0,z);
glRotatef(sudut,x1,y1,z1);
glColor3f(0,0,1);
glutWireCube(3);
glutSwapBuffers();
}

Pewarnaan Kubus:
glColor3f(0,0,1); glColor3f(0,0,0); glColor3f(0,1,0);

glColor3f(0,1,1); glColor3f(1,0,1); glColor3f(1,0,0);

glColor3f(1,1,1); glColor3f(1,1,0);
Nonik Putri/5171311006/PTM3

2. Torus (Donat)
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,1,0);
glLoadIdentity();
glTranslatef(0,0,z);
glRotatef(sudut,x1,y1,z1);
glColor3f(1,0,1);
glutWireTorus(1,3,20,40);
glutSwapBuffers();
}

3. Object Bebas

a. Kerucut
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0,0,1,0);
glLoadIdentity();
glTranslatef(0,0,z);
glRotatef(sudut,x1,y1,z1);
glColor3f(0,1,0);
glutWireCone(2,3,25,25);
glutSwapBuffers();
}
Nonik Putri/5171311006/PTM3

b. Teko
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,0,1,0);
glLoadIdentity();
glTranslatef(0,0,z);
glRotatef(sudut,x1,y1,z1);
glColor3f(0,0,0);
glutWireTeapot(4);
glutSwapBuffers();
}

c. Bola
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0,1,0,0);
glLoadIdentity();
glTranslatef(0,0,z);
glRotatef(sudut,x1,y1,z1);
glColor3f(1,0,1);
glutWireSphere(2,20,10);
glutSwapBuffers();
}
Nonik Putri/5171311006/PTM3

Rumus Lengkap:
#include <stdAfx.h> z1=0;
#include <stdlib.h> sudut+=-10;
#include <glut.h> }
int w=400, h=400, z=0; else if (key == 'z') {
int x1=0, y1=0, sudut=0, z1=0; y1=0;
void renderScene(void){ x1=0;
glClear(GL_COLOR_BUFFER_BIT | z1=1;
GL_DEPTH_BUFFER_BIT); sudut+=-10;
glClearColor(1,1,1,0); }
glLoadIdentity(); }
glTranslatef(0,0,z); void init(){
glRotatef(sudut,x1,y1,z1); glClearColor(1,1,1,1);
glColor3f(1,0,1); glEnable(GL_DEPTH_TEST);
glutWireTorus(1,3,20,40); glMatrixMode(GL_PROJECTION);
glutSwapBuffers(); glLoadIdentity();
} gluPerspective(45.0,(GLdouble)
w/(GLdouble) h, 1.0,300.0);
void resize(int w1, int h1){ glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w1,h1); }
glMatrixMode(GL_PROJECTION); void timer(int value){
glLoadIdentity(); glutPostRedisplay();
gluPerspective(45.0,(float) w1/(float) glutTimerFunc(50,timer,0);
h1, 1.0,300.0); }
glMatrixMode(GL_MODELVIEW); void main (int argc, char **argv){
glLoadIdentity(); glutInit(&argc, argv);
} glutInitDisplayMode(GLUT_DOUBLE |
void myKeyboard(unsigned char key, int GLUT_DEPTH | GLUT_RGBA);
x, int y){ glutInitWindowPosition(100,100);
if (key =='a') z+=5; glutInitWindowSize(w,h);
else if (key == 'd') z-=5; glutCreateWindow("Torus");
else if (key == 'x') { gluOrtho2D(-w/2,w/2,-h/2,h/2);
x1=1; glutDisplayFunc(renderScene);
y1=0; glutReshapeFunc(resize);
z1=0; glutKeyboardFunc(myKeyboard);
sudut+=10; glutTimerFunc(1,timer,0);
} init();
else if (key == 'y') { glutMainLoop();
y1=1; }
x1=0;

You might also like