[ 그래픽스 / 오픈젤 / Opengel ] 뒤늦은 놀이동산 만들기
2017. 3. 13. 10:38 - 커피물조절달인1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | // Include standard headers #include <stdio.h> #include <stdlib.h> // Include GLEW #include <GL/glew.h> // Include GLFW #include <glfw3.h> GLFWwindow* window; // Include GLM #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/quaternion.hpp> #include <glm/gtx/quaternion.hpp> #include <glm/gtx/euler_angles.hpp> #include <glm/gtx/norm.hpp> using namespace glm; #include <common/shader.hpp> #include <common/texture.hpp> #include <common/controls.hpp> GLfloat *makeCIrcleVertexData(GLfloat x, GLfloat y, GLfloat z, GLfloat radius, GLint numberOfSides); // 원만드는 함수 GLfloat* MakeCylinder(GLfloat *buffer1, GLfloat *buffer2, GLint num); // 원기둥 만드는 함수 - 실패 - int main(void) { // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); getchar(); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context window = glfwCreateWindow(1024, 768, "Project 76", NULL, NULL); if (window == NULL) { fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n"); getchar(); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); getchar(); glfwTerminate(); return -1; } // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // Set the mouse at the center of the screen 키보드 마우스 사용을 위한 부분. glfwPollEvents(); glfwSetCursorPos(window, 1024 / 2, 768 / 2); // 커서 위치 // Dark blue background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); // 배경색 다크블루 안건드림 // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); // Cull triangles which normal is not towards the camera glEnable(GL_CULL_FACE); GLuint VertexArrayID; glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); // 기타 설정은 건드리지 않음 // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders("TransformVertexShader.vertexshader", "ColorFragmentShader.fragmentshader"); GLuint programID2 = LoadShaders("TransformVertexShader2.vertexshader", "TextureFragmentShader.fragmentshader"); // 두번째 쉐이더로 텍스쳐 사용 용도로 불러온다. // Get a handle for our "MVP" uniform GLuint MatrixID = glGetUniformLocation(programID, "MVP"); GLuint MatrixID2 = glGetUniformLocation(programID2, "MVP"); // 마찬가지로 텍스쳐 사용을 위함 GLuint Texture = loadBMP_custom("texture001.bmp"); // 미리 텍스쳐를 불러와 가지고 있다. GLuint Texture2 = loadBMP_custom("texture002.bmp"); // 셰이더에 업로드하기 위한 핸들러 GLuint TextureID = glGetUniformLocation(programID2, "myTextureSampler"); static const GLfloat g_vertex_buffer_data[] = { -1.0f,-1.0f,-1.0f, -1.0f,-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f }; // 큐브 // 큐브 static const GLfloat boat[] = { // 9개 x 12 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, // 밑판1 -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, // 밑판2 1.0f, 0.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 3.0f, 2.0f, 1.0f, // 오른쪽 옆판 1 3.0f, 2.0f, 1.0f, 1.0f, 0.0f, -1.0f, 3.0f, 2.0f, -1.0f, // 오른쪽 옆판 2 -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, -3.0f, 2.0f, 1.0f, // 왼쪽 옆판 1 -1.0f, 0.0f, -1.0f, -3.0f, 2.0f, -1.0f, -3.0f, 2.0f, 1.0f, // 왼쪽 옆판 2 -1.0f, 0.0f, 1.0f, 3.0f, 2.0f, 1.0f, -3.0f, 2.0f, 1.0f, // 앞면 1 -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 3.0f, 2.0f, 1.0f, // 앞면 2 -1.0f, 0.0f, -1.0f, 3.0f, 2.0f, -1.0f, -3.0f, 2.0f, -1.0f, // 뒷면 1 -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 3.0f, 2.0f, -1.0f, // 뒷면 2 3.0f, 2.0f, 1.0f, -3.0f, 2.0f, 1.0f, -3.0f, 2.0f, -1.0f, // 윗면 1 3.0f, 2.0f, -1.0f, 3.0f, 2.0f, 1.0f, -3.0f, 2.0f, -1.0f, // 윗면 2 }; // 보트 // 보트모양을 위한 정점의 집합 static const GLfloat sixSide[] = { -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.42f, 1.0f, 0.0f, 1.42f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.42f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.42f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f, // 윗 육각형 -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.42f, 0.0f, 0.0f, 1.42f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f,0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.42f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.42f, 0.0f, 0.0f, -1.0f, 0.0f, -1.0f, // 밑 육각형 -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, // 1.0f, 1.0f, 1.0f, 1.42f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.42f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.42f, 0.0f, 0.0f, // 1.0f, 1.0f, -1.0f, 1.42f, 1.0f, 0.0f, 1.42f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.42f, 0.0f, 0.0f, // -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, // -1.0f, 1.0f, -1.0f, -1.42f, 1.0f, 0.0f, -1.0f, 0.0f, -1.0f, -1.42f, 1.0f, 0.0f, -1.0f, 0.0f, -1.0f, -1.42f, 0.0f, 0.0f, // -1.42f, 1.0f, 0.0f, -1.0f, 1.0f, 1.0f, -1.42f, 0.0f ,0.0f, -1.0f, 1.0f, 1.0f, -1.42f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f }; // 육각기둥 // One color for each vertex. They were generated randomly. /*static GLfloat* circle = makeCIrcleVertexData(0.0f, 0.0f, 0.0f, 1.0f, 12); static GLfloat* circle2 = makeCIrcleVertexData(0.0f, 3.0f, 0.0f, 1.0f, 12); static const GLfloat* cylinder = MakeCylinder(circle, circle2, 12);*/ static const GLfloat g_color_buffer_data[] = { 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, }; static const GLfloat g_color_buffer_data2[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.597f, 0.770f, 0.761f, 0.559f, 0.436f, 0.730f, 0.359f, 0.583f, 0.152f, 0.483f, 0.596f, 0.789f, 0.559f, 0.861f, 0.639f, 0.195f, 0.548f, 0.859f, 0.014f, 0.184f, 0.576f, 0.771f, 0.328f, 0.970f, 0.406f, 0.615f, 0.116f, 0.676f, 0.977f, 0.133f, 0.971f, 0.572f, 0.833f, 0.140f, 0.616f, 0.489f, 0.997f, 0.513f, 0.064f, 0.945f, 0.719f, 0.592f, 0.543f, 0.021f, 0.978f, 0.279f, 0.317f, 0.505f, 0.167f, 0.620f, 0.077f, 0.347f, 0.857f, 0.137f, 0.055f, 0.953f, 0.042f, 0.714f, 0.505f, 0.345f, 0.783f, 0.290f, 0.734f, 0.722f, 0.645f, 0.174f, 0.302f, 0.455f, 0.848f, 0.225f, 0.587f, 0.040f, 0.517f, 0.713f, 0.338f, 0.053f, 0.959f, 0.120f, 0.393f, 0.621f, 0.362f, 0.673f, 0.211f, 0.457f, 0.820f, 0.883f, 0.371f, 0.982f, 0.099f, 0.879f }; static const GLfloat g_color_buffer_boat[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.597f, 0.770f, 0.761f, 0.559f, 0.436f, 0.730f, 0.359f, 0.583f, 0.152f, 0.597f, 0.770f, 0.761f, 0.559f, 0.436f, 0.730f, 0.359f, 0.583f, 0.152f, 0.597f, 0.770f, 0.761f, 0.559f, 0.436f, 0.730f, 0.359f, 0.583f, 0.152f, 0.483f, 0.596f, 0.789f, 0.559f, 0.861f, 0.639f, 0.195f, 0.548f, 0.859f, 0.483f, 0.596f, 0.789f, 0.559f, 0.861f, 0.639f, 0.195f, 0.548f, 0.859f, 0.483f, 0.596f, 0.789f, 0.559f, 0.861f, 0.639f, 0.195f, 0.548f, 0.859f, 0.014f, 0.184f, 0.576f, 0.771f, 0.328f, 0.970f, 0.406f, 0.615f, 0.116f, 0.014f, 0.184f, 0.576f, 0.771f, 0.328f, 0.970f, 0.406f, 0.615f, 0.116f, 0.014f, 0.184f, 0.576f, 0.771f, 0.328f, 0.970f, 0.406f, 0.615f, 0.116f, 0.676f, 0.977f, 0.133f, 0.971f, 0.572f, 0.833f, 0.140f, 0.616f, 0.489f, 0.676f, 0.977f, 0.133f, 0.971f, 0.572f, 0.833f, 0.140f, 0.616f, 0.489f, 0.676f, 0.977f, 0.133f, 0.971f, 0.572f, 0.833f, 0.140f, 0.616f, 0.489f, 0.997f, 0.513f, 0.064f, 0.945f, 0.719f, 0.592f, 0.543f, 0.021f, 0.978f, 0.997f, 0.513f, 0.064f, 0.945f, 0.719f, 0.592f, 0.543f, 0.021f, 0.978f, 0.997f, 0.513f, 0.064f, 0.945f, 0.719f, 0.592f, 0.543f, 0.021f, 0.978f, 0.279f, 0.317f, 0.505f, 0.167f, 0.620f, 0.077f, 0.347f, 0.857f, 0.137f, 0.279f, 0.317f, 0.505f, 0.167f, 0.620f, 0.077f, 0.347f, 0.857f, 0.137f, 0.279f, 0.317f, 0.505f, 0.167f, 0.620f, 0.077f, 0.347f, 0.857f, 0.137f, 0.055f, 0.953f, 0.042f, 0.714f, 0.505f, 0.345f, 0.783f, 0.290f, 0.734f, 0.055f, 0.953f, 0.042f, 0.714f, 0.505f, 0.345f, 0.783f, 0.290f, 0.734f, 0.055f, 0.953f, 0.042f, 0.714f, 0.505f, 0.345f, 0.783f, 0.290f, 0.734f, 0.722f, 0.645f, 0.174f, 0.302f, 0.455f, 0.848f, 0.225f, 0.587f, 0.040f, 0.722f, 0.645f, 0.174f, 0.302f, 0.455f, 0.848f, 0.225f, 0.587f, 0.040f, 0.722f, 0.645f, 0.174f, 0.302f, 0.455f, 0.848f, 0.225f, 0.587f, 0.040f, 0.517f, 0.713f, 0.338f, 0.053f, 0.959f, 0.120f, 0.393f, 0.621f, 0.362f, 0.517f, 0.713f, 0.338f, 0.053f, 0.959f, 0.120f, 0.393f, 0.621f, 0.362f, 0.517f, 0.713f, 0.338f, 0.053f, 0.959f, 0.120f, 0.393f, 0.621f, 0.362f, 0.673f, 0.211f, 0.457f, 0.820f, 0.883f, 0.371f, 0.982f, 0.099f, 0.879f, 0.673f, 0.211f, 0.457f, 0.820f, 0.883f, 0.371f, 0.982f, 0.099f, 0.879f, 0.673f, 0.211f, 0.457f, 0.820f, 0.883f, 0.371f, 0.982f, 0.099f, 0.879f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, 0.532f, 0.532f, 0.543f, }; static const GLfloat g_uv_buffer_data[] = { 0.000059f, 1.0f - 0.000004f, 0.000103f, 1.0f - 0.336048f, 0.335973f, 1.0f - 0.335903f, 1.000023f, 1.0f - 0.000013f, 0.667979f, 1.0f - 0.335851f, 0.999958f, 1.0f - 0.336064f, 0.667979f, 1.0f - 0.335851f, 0.336024f, 1.0f - 0.671877f, 0.667969f, 1.0f - 0.671889f, 1.000023f, 1.0f - 0.000013f, 0.668104f, 1.0f - 0.000013f, 0.667979f, 1.0f - 0.335851f, 0.000059f, 1.0f - 0.000004f, 0.335973f, 1.0f - 0.335903f, 0.336098f, 1.0f - 0.000071f, 0.667979f, 1.0f - 0.335851f, 0.335973f, 1.0f - 0.335903f, 0.336024f, 1.0f - 0.671877f, 1.000004f, 1.0f - 0.671847f, 0.999958f, 1.0f - 0.336064f, 0.667979f, 1.0f - 0.335851f, 0.668104f, 1.0f - 0.000013f, 0.335973f, 1.0f - 0.335903f, 0.667979f, 1.0f - 0.335851f, 0.335973f, 1.0f - 0.335903f, 0.668104f, 1.0f - 0.000013f, 0.336098f, 1.0f - 0.000071f, 0.000103f, 1.0f - 0.336048f, 0.000004f, 1.0f - 0.671870f, 0.336024f, 1.0f - 0.671877f, 0.000103f, 1.0f - 0.336048f, 0.336024f, 1.0f - 0.671877f, 0.335973f, 1.0f - 0.335903f, 0.667969f, 1.0f - 0.671889f, 1.000004f, 1.0f - 0.671847f, 0.667979f, 1.0f - 0.335851f }; GLuint vertexbuffer; // 큐브 glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); GLuint colorbuffer; // 기본 컬러 버퍼 glGenBuffers(1, &colorbuffer); glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW); GLuint colors; // 회색조 바닥을 위해 만들었던 버퍼 - 텍스쳐로 인해 사용 안함 glGenBuffers(1, &colors); glBindBuffer(GL_ARRAY_BUFFER, colors); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data2), g_color_buffer_data2, GL_STATIC_DRAW); GLuint colorboat; // 보트색상을 위해 만들었던 버퍼 - 텍스쳐로 인해 보트엔 사용안하고 육면체에 적용 glGenBuffers(1, &colorboat); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_boat), g_color_buffer_boat, GL_STATIC_DRAW); GLuint boatbuffer; // 보트 랜더링 glGenBuffers(1, &boatbuffer); glBindBuffer(GL_ARRAY_BUFFER, boatbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(boat), boat, GL_STATIC_DRAW); GLuint sixSideBuffer; // 육각기둥 랜더링용 glGenBuffers(1, &sixSideBuffer); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(sixSide), sixSide, GL_STATIC_DRAW); GLuint uvbuffer; // 텍스쳐 맵핑을 위한 glGenBuffers(1, &uvbuffer); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_uv_buffer_data), g_uv_buffer_data, GL_STATIC_DRAW); double lastTime = glfwGetTime(); double lastFrameTime = lastTime; // 후에 deltaTime 을 구하기 위함 vec3 gOrientation1, gOrientation2; // 기둥의 팬듈러 운동을 위한 벡터 int viking_flag = 0; // 한쪽으로만 도는것이아닌 왓다갓다를 위한 플래그 vec3 rotation1, translation1; translation1 = { 14.0f, -11.0f, 0.0f }; vec3 rotation2, translation2, translation3, translation4, translation5, translation6; translation2 = { 14.5f, 0.0f, 0.0f }; translation3 = { 4.0f, -8.0f, 4.0f }; translation4 = { 4.0f, -8.0f, -4.0f }; translation5 = { -4.0f, -8.0f, -4.0f }; translation6 = { -4.0f, -8.0f, 4.0f }; // 컵들의 위치 및 컵의 회전을 위한 벡터들 glDisable(GL_CULL_FACE); // 마우스,키보드에 따른 컬링에 관한 설정 // 렌더링 부분 do { // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // deltaTime double currentTime = glfwGetTime(); float deltaTime = (float)(currentTime - lastFrameTime); lastFrameTime = currentTime; // deltaTime 을 구햇다 ! 현재시간 - 마지막프레임시간 = 현재 프레임 시간 해서 // 1 / 프레임 이라는 deltaTime 이 구해진다. 움직이는 것에 대해서는 곱해주는 것이 // 좋다 아니면 // 휙휙 움직여버리게 되기 때문 // Use our shader glUseProgram(programID); // 마우스 키보드 입출력 computeMatricesFromInputs(); glm::mat4 Projection = getProjectionMatrix(); glm::mat4 View = getViewMatrix(); // View 와 Projection 에 대해서 입력 받은값으로 재정의하는부분 ( 으로 생각 ) vec3 groundPosition(0.0f, -10.0f, 0.0f); // 원래 이곳의 벡터들은 While 문 밖에 위치하고 있었지만 매 프레임마다 새로 계산 되어야 하기때문에 While 문 안으로 들어오게되었다. glm::mat4 Ground = Projection * View * translate(mat4(), groundPosition) * scale(mat4(), vec3(30.0f, 0.01f, 30.0f)); //Ground 끝 // 바이킹 기둥 1 vec3 viking_pillar1(-25.0f, -5.0f, 0.0f); glm::mat4 Viking_Pillar1 = Projection * View * translate(mat4(), viking_pillar1) *eulerAngleXYZ(-0.5f, 0.0f, -0.53f) * scale(mat4(), vec3(0.3f, 10.0f, 0.3f)); // 바이킹 기둥 2 vec3 viking_pillar2(-15.0f, -5.0f, 0.0f); glm::mat4 Viking_Pillar2 = Projection * View * translate(mat4(), viking_pillar2) *eulerAngleXYZ(-0.5f, 0.0f, 0.53f) * scale(mat4(), vec3(0.3f, 10.0f, 0.3f));; // 바이킹 기둥 3 vec3 viking_pillar3(-25.0f, -5.0f, -8.3f); glm::mat4 Viking_Pillar3 = Projection * View * translate(mat4(), viking_pillar3) *eulerAngleXYZ(0.5f, 0.0f, -0.53f) * scale(mat4(), vec3(0.3f, 10.0f, 0.3f));; // 바이킹 기둥 4 vec3 viking_pillar4(-15.0f, -5.0f, -8.3f); glm::mat4 Viking_Pillar4 = Projection * View * translate(mat4(), viking_pillar4) *eulerAngleXYZ(0.5f, 0.0f, 0.53f) * scale(mat4(), vec3(0.3f, 10.0f, 0.3f)); // Ground { glUseProgram(programID2); // 텍스쳐 사용을 위한 설정 glUniformMatrix4fv(MatrixID2, 1, GL_FALSE, &Ground[0][0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture2); glUniform1i(TextureID, 0); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glVertexAttribPointer( 1, // attribute. No particular reason for 1, 2, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); // GROUND 끝 glUseProgram(programID); // 텍스쳐 사용이 끝났으므로 } // 바이킹 { // 바이킹 메인 기둥 vec3 viking_pillar_main(-20.0f, 2.0f, -4.15f); // vec3 returnto_basic(0.0f, 0.0f, -4.5f); vec3 returnto_basic(0.0f, -4.3f, 0.0f); //gOrientation1.x = 1.5707f; gOrientation1.y; // = 0.0f; gOrientation1.z; // = 0.0f; if (gOrientation1.x > 1.2f) // 계속 한방향으로 회전하는 것을 멈추기 위함 viking_flag = 1; else if (gOrientation1.x < -1.2f) // 사실 한방향으로 계속 가지도 못하지만 cos 값이 0 에 도달하면 멈춰버리기때문에 viking_flag = 0; //1.2f를 넘어가면 +, -1.2f보다 작아지면 - if (viking_flag == 1) gOrientation1.x -= 3.14159f / 2.0f * deltaTime * cos(gOrientation1.x) * cos(gOrientation1.x); // 코사인을 두번 해준것은 좀더 바뀌는 곡선을 극적으로 만들기 위함 else gOrientation1.x += 3.14159f / 2.0f * deltaTime * cos(gOrientation1.x) * cos(gOrientation1.x); // 이로써 올라갈땐 천천히 내려올땐 빨리내려오게 된다. glm::mat4 Viking_Pillar_Main = Projection * View *translate(mat4(), viking_pillar_main) * eulerAngleYXZ(gOrientation1.y, gOrientation1.x, gOrientation1.z) *translate(mat4(), returnto_basic) * scale(mat4(), vec3(0.3f, 5.0f, 0.3f)); // 행렬의 계산 // 바이킹 보트 vec3 viking_boat(0.0f, -1.2f, 0.0f); glm::mat4 Viking_Boat = Viking_Pillar_Main * translate(mat4(), viking_boat) * eulerAngleXYZ(0.0f, 1.7f, 0.0f) * scale(mat4(), vec3(5.0f, 0.3f, 5.0f)); //바이킹 기둥1 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &Viking_Pillar1[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colors); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //바이킹 기둥2 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &Viking_Pillar2[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colors); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //바이킹 기둥3 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &Viking_Pillar3[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colors); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //바이킹 기둥4 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &Viking_Pillar4[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colors); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //바이킹 메인 기둥 움직이지만 실제로 랜더링 부분은같다 그저 넘겨받는 행렬이 다를뿐 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &Viking_Pillar_Main[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colors); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } // 바이킹 보트 텍스쳐 사용을 한다. { glUseProgram(programID2); // 텍스쳐를 위한 부분 glUniformMatrix4fv(MatrixID2, 1, GL_FALSE, &Viking_Boat[0][0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture); glUniform1i(TextureID, 0); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, boatbuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 2, // size 왜냐하면! 2d 텍스쳐이므로 xy 값밖에 없기 때문이다 ! GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 3 * 12); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } } // 바이킹 glUseProgram(programID); // programID = LoadShaders("TransformVertexShader.vertexshader", "ColorFragmentShader.fragmentshader"); // 회전 컵 { rotation1.y += 3.14159f / 2.0f * deltaTime; // 바닥에 해당하는 부분 그저 돌아간다. glm::mat4 SixSideMat = Projection * View *translate(mat4(), translation1) * eulerAngleXYZ(rotation1.x, rotation1.y, rotation1.z) * scale(mat4(), vec3(5.0f, 3.0f, 6.0f)); // 위치이동하고 그자리에서 돌아갈뿐 제자리에서 rotation2.y -= 3 * 3.14159f / 2.0f * deltaTime; glm::mat4 smallSixSideMat1 = Projection * View * translate(mat4(), translation2) *eulerAngleXYZ(rotation1.x, rotation1.y, rotation1.z) *translate(mat4(), translation3) * eulerAngleXYZ(rotation2.x, rotation2.y, rotation2.z); glm::mat4 smallSixSideMat2 = Projection * View * translate(mat4(), translation2) *eulerAngleXYZ(rotation1.x, rotation1.y, rotation1.z) *translate(mat4(), translation4) * eulerAngleXYZ(rotation2.x, rotation2.y, rotation2.z); glm::mat4 smallSixSideMat3 = Projection * View * translate(mat4(), translation2) *eulerAngleXYZ(rotation1.x, rotation1.y, rotation1.z) *translate(mat4(), translation5) * eulerAngleXYZ(rotation2.x, rotation2.y, rotation2.z); glm::mat4 smallSixSideMat4 = Projection * View * translate(mat4(), translation2) *eulerAngleXYZ(rotation1.x, rotation1.y, rotation1.z) *translate(mat4(), translation6) * eulerAngleXYZ(rotation2.x, rotation2.y, rotation2.z); // 컵들이다. 자기스스로 회전하면서도 하나의 축을 기준으로 회전한다 회전하는 바닥위에서 그 주위를 돌면서 스스로 그 반대로 돌아간다. // 바닥 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &SixSideMat[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6 * 4 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } // 1번 컵 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &smallSixSideMat1[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6 * 4 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } // 2번컵 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &smallSixSideMat2[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6 * 4 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //3번컵 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &smallSixSideMat3[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6 * 4 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } //4번컵 { glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &smallSixSideMat4[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, sixSideBuffer); glVertexAttribPointer( 0, // attribute. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : colors glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorboat); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 6 * 4 * 3); // 12*3 indices starting at 0 -> 12 triangles glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); } } glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Cleanup VBO and shader glDeleteBuffers(1, &vertexbuffer); glDeleteBuffers(1, &colorbuffer); glDeleteProgram(programID); glDeleteVertexArrays(1, &VertexArrayID); // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; } // 원기둥 구현 포기...왜 안되지 GLfloat* makeCIrcleVertexData(GLfloat x, GLfloat y, GLfloat z, GLfloat radius, GLint numberOfSides) { GLint numberOfVertices = numberOfSides + 1; GLfloat doublePi = 2.0f * 3.141592f; GLfloat *circleVerticesX = new GLfloat[numberOfVertices]; GLfloat *circleVerticesY = new GLfloat[numberOfVertices]; GLfloat *circleVerticesZ = new GLfloat[numberOfVertices]; //circleVerticesX[0] = x; //circleVerticesY[0] = y; //circleVerticesZ[0] = z; for (int i = 0; i < numberOfVertices; i++) { circleVerticesX[i] = x + (radius * cos(i * doublePi / numberOfSides)); circleVerticesY[i] = y + (radius * sin(i * doublePi / numberOfSides)); circleVerticesZ[i] = z; } GLfloat *allCircleVertices = new GLfloat[numberOfVertices * 3]; for (int i = 0; i < numberOfVertices; i++) { allCircleVertices[i * 3] = circleVerticesX[i]; allCircleVertices[(i * 3) + 1] = circleVerticesY[i]; allCircleVertices[(i * 3) + 2] = circleVerticesZ[i]; } return allCircleVertices; } GLfloat* MakeCylinder(GLfloat *buffer1, GLfloat *buffer2, GLint num) { GLfloat *buf = new GLfloat[num * 3 * 2 * 2]; for (int i = 0; i < num; i++) { buf[i * 36 + 0] = buffer1[i * 9 + 0]; buf[i * 36 + 1] = buffer1[i * 9 + 1]; buf[i * 36 + 2] = buffer1[i * 9 + 2]; buf[i * 36 + 3] = buffer1[i * 9 + 3]; buf[i * 36 + 4] = buffer1[i * 9 + 4]; buf[i * 36 + 5] = buffer1[i * 9 + 5]; buf[i * 36 + 6] = buffer1[i * 9 + 6]; buf[i * 36 + 7] = buffer1[i * 9 + 7]; buf[i * 36 + 8] = buffer1[i * 9 + 8]; // 윗쪽 삼각형 buf[i * 36 + 9] = buffer2[i * 9 + 0]; buf[i * 36 + 10] = buffer2[i * 9 + 1]; buf[i * 36 + 11] = buffer2[i * 9 + 2]; buf[i * 36 + 12] = buffer2[i * 9 + 3]; buf[i * 36 + 13] = buffer2[i * 9 + 4]; buf[i * 36 + 14] = buffer2[i * 9 + 5]; buf[i * 36 + 15] = buffer2[i * 9 + 6]; buf[i * 36 + 16] = buffer2[i * 9 + 7]; buf[i * 36 + 17] = buffer2[i * 9 + 8]; // 아래 삼각형 buf[i * 36 + 18] = buffer1[i * 9 + 0]; // 중간을 잇는 삼각형 1 buf[i * 36 + 19] = buffer1[i * 9 + 1]; buf[i * 36 + 20] = buffer1[i * 9 + 2]; buf[i * 36 + 21] = buffer1[i * 9 + 3]; buf[i * 36 + 22] = buffer1[i * 9 + 4]; buf[i * 36 + 23] = buffer1[i * 9 + 5]; buf[i * 36 + 24] = buffer2[i * 9 + 0]; buf[i * 36 + 25] = buffer2[i * 9 + 1]; buf[i * 36 + 26] = buffer2[i * 9 + 2]; buf[i * 36 + 27] = buffer1[i * 9 + 3]; // 중간을 잇는 삼각형 2 buf[i * 36 + 28] = buffer1[i * 9 + 4]; buf[i * 36 + 29] = buffer1[i * 9 + 5]; buf[i * 36 + 30] = buffer2[i * 9 + 0]; buf[i * 36 + 31] = buffer2[i * 9 + 1]; buf[i * 36 + 32] = buffer2[i * 9 + 2]; buf[i * 36 + 33] = buffer2[i * 9 + 3]; buf[i * 36 + 34] = buffer2[i * 9 + 4]; buf[i * 36 + 35] = buffer2[i * 9 + 5]; } return buf; } |
버퍼를 만들어 넘겨주고, 그리고를 반복하는 오픈젤....유니티의 소중함을 깨달을수 있는 시간이었다.
회전컵( 원은 아니지만 ) , 바이킹 ( 제대로된 바이킹은 아니지만) , 텍스쳐 입히기 등을 해놓은 코드이다.
누군가에겐 도움이 되겠지
'Programing > Game Programing' 카테고리의 다른 글
| [유니티 / 게임수학] 유니티로 배우는 게임수학 -좌표계 - (0) | 2016.11.03 |
|---|---|
| 유니티로 배우는 게임수학 -삼각함수- (0) | 2016.11.02 |
| C# 유니티 VR 컨텐츠 개발 19일차 (0) | 2016.08.12 |
| C# 유니티 기반 VR 컨텐츠 개발 18일차 (0) | 2016.08.10 |
| C# 유니티 기반 VR 컨텐츠 개발 17일차 (0) | 2016.08.09 |
댓글 로드 중…