Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // OpenGL02
- //
- // Created by Alexander Kevin on 3/3/16.
- // Copyright © 2016 Alexander Kevin. All rights reserved.
- //
- #ifdef WIN32
- #include <windows.h>
- #endif
- #include <stdlib.h>
- #include <iostream>
- #include <fstream>
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #else
- #include <GL/glut.h>
- #include <GL/glu.h>
- #include <GL/gl.h>
- #endif
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.0,0.0,0.5);
- glFlush();
- }
- void displaysoalsatu()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.0,0.0,0.5);
- int x=-25,y=-25,xp=-20,yl=-20;//xp=panjang, y;=lebar);
- //bikin checkboard
- while(y!=70){
- glRecti(x,y, xp, yl);
- x+=10;
- xp+=10;
- //printf("%d %d %d %d\n",x,y,xp,yl);
- if(x>=70&&y!=70){
- //printf("baris baru\n\n");
- y+=5;
- if(x==75){
- x=-20;
- xp=-15;
- }
- else{
- x=-25;
- xp=-20;
- }
- yl+=5;
- }
- }
- glFlush();
- }
- void displaysoaldua()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.5,0.5,0.5);
- int rot=0;
- glRecti(22.5,37.5,27.5,42.5);
- do{
- glTranslated(25, 25, 0);
- glRotated(30, 0, 0, 1);
- glTranslated(-25, -25, 0);
- if(rot%2==1)
- glRecti(22.5,37.5,27.5,42.5);
- else
- glRecti(23.5,38.5,26,41);
- rot++;
- }while(rot!=16);
- rot=0;
- do{
- glColor3f(0.5,0.8,0.5);
- glTranslated(25, 25, 0);
- glRotated(0.1, 0, 0, 1);
- glTranslated(-25, -25, 0);
- glRecti(24.9,39.9,25.1,40.1);
- rot++;
- }while(rot!=3600);
- glFlush();
- }
- void displaysoaltiga()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.5,0.8,0.5);
- int rot=0;
- do{
- glTranslated(25, 25, 0);
- glRotated(30, 0, 0, 1);
- glTranslated(-25, -25, 0);
- glRecti(22.5,37.5,27.5,42.5);
- rot++;
- }while(rot!=16);
- rot=0;
- do{
- glTranslated(25, 25, 0);
- glRotated(0.1, 0, 0, 1);
- glTranslated(-25, -25, 0);
- glRecti(24.9,39.9,25.1,40.1);
- glColor3f(0.5,0.5,0.5);
- rot++;
- }while(rot!=3600);
- glFlush();
- }
- void kunci(unsigned char key, int x, int y)
- {
- static int rot=0;
- switch (key)
- {
- /* aplikasi berhenti ketika tombol q ditekan */
- case 27 :
- case 'q':
- exit(0);
- break;
- case 'z':
- glTranslated(25, 25, 0);
- glRotated(1, 0, 0, 1);
- glTranslated(-25, -25, 0);
- break;
- case 'c':
- glTranslated(25, 25, 0);
- glRotated(-1, 0, 0, 1);
- glTranslated(-25, -25, 0);
- break;
- case 'w':
- glTranslated(0, 0.5, 0);
- break;
- case 'a':
- glTranslated(-0.5, 0, 0);
- break;
- case 's':
- glTranslated(0, -0.5, 0);
- break;
- case 'd':
- glTranslated(0.5, 0, 0);
- break;
- case 'p':
- glutDisplayFunc(displaysoaltiga);
- break;
- case 'i':
- glLoadIdentity();
- glTranslated(25, 25, 0);
- glRotated(45, 0, 0, 1);
- glTranslated(-25, -25, 0);
- glutDisplayFunc(displaysoalsatu);
- break;
- case 'o':
- glutDisplayFunc(displaysoaldua);
- break;
- }
- glutPostRedisplay();
- }
- void myinit()
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0.0,50.0,0.0,50.0);
- glMatrixMode(GL_MODELVIEW);
- glClearColor(1.0,1.0,1.0,1.0);
- glColor3f(0.0,0.0,0.0);
- }
- int main(int argc, char* argv[])
- {
- printf("Welcome,\n");
- printf("Press Keyboard\n");
- printf("(p) for square and circle(Case 2)\n");
- printf("(o) for improved square and circle(Case 3)\n");
- printf("(i) for checkboard(Case 1)\n");
- printf("for control use standart wasd (up,left,down,right)\n");
- printf("and z for left rotate and c for right rotate\n");
- printf("<press q to exit>\n");
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(400,400);
- glutInitWindowPosition(100,100);
- glutCreateWindow("Transform");
- glutDisplayFunc(display);
- myinit();
- glutKeyboardFunc(kunci);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement