er

Saturday 31 January 2015

Primitve Object 3D OpenGL

#include <Windows.h>
#include <iostream>
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\glut.h>
#include <math.h>
void renderScene(void){

 glClear(GL_COLOR_BUFFER_BIT);

 // Draw a white torus of outer radius 3, inner radius 0.5 with 15 stacks
 // and 30 slices.
 glColor3f(1.0, 1.0, 1.0);
 //glutWireTorus(0.5, 3, 15, 30);
 glutWireCube(1.3);

 // Draw a red x-axis, a green y-axis, and a blue z-axis. Each of the
 // axes are ten units long.
 glBegin(GL_LINES);
 glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(10, 0, 0);
 glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 10, 0);
 glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 10);
 glEnd();

 glFlush();
}
void kunci(unsigned char key, int x, int y) {
 switch (key)
 {
 case 27 :
 case 'q':
 exit(0);
 break;
 }
 glutPostRedisplay();
}
void init() {

 // Set the current clear color to black and the current drawing color to
 // white.
 glClearColor(0.0, 0.0, 0.0, 1.0);
 glColor3f(1.0, 1.0, 1.0);

 // Set the camera lens to have a 60 degree (vertical) field of view, an
 // aspect ratio of 4/3, and have everything closer than 1 unit to the
 // camera and greater than 40 units distant clipped away.
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(60.0, 4.0/3.0, 1, 40);

 // Position camera at (4, 6, 5) looking at (0, 0, 0) with the vector
 // <0, 1, 0> pointing upward.
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 gluLookAt(4, 6, 5, 0, 0, 0, 0, 1, 0);
}

int main(int argc, char *argv[])
{
 glutInit(&argc, argv);
 glutInitWindowSize(800,600);
 glutInitWindowPosition(100,100);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutCreateWindow("Primitive Object");
 glutDisplayFunc(renderScene);
 glutKeyboardFunc(kunci);
 init();
 glutMainLoop();
 return 0;
}

Screenshot :



Comments
0 Comments

0 comments:

Post a Comment

Berkomentarlah dengan kata-kata yang sopan, tidak spam, dan bijak ^.^
Terima Kasih telah berkunjung