Changeset 64a70f4 in opengl-game
- Timestamp:
- Mar 9, 2018, 1:27:02 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 19c9338, bc6d8f6
- Parents:
- a5b5e95
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
ra5b5e95 r64a70f4 34 34 bool clicked = false; 35 35 int colors_i = 0; 36 37 bool clicked_square = false; 36 38 37 39 mat4 view_mat; … … 239 241 clicked = insideTriangle(intersection, fp1, fp2, fp3); 240 242 cout << (clicked ? "true" : "false") << endl; 243 244 clicked_square = !clicked_square; 241 245 } 242 246 } … … 324 328 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 325 329 330 /* 326 331 GLfloat points[] = { 327 332 0.0f, 0.5f, 0.0f, … … 332 337 0.0f, 0.5f, 0.0f, 333 338 }; 334 /* 339 */ 340 335 341 GLfloat points[] = { 336 0.0f, 1.0f, 0.0f, 337 -1.0f, 0.0f, 0.0f, 338 1.0f, 0.0f, 0.0f, 339 1.0f, 0.0f, 0.0f, 340 -1.0f, 0.0f, 0.0f, 341 0.0f, 1.0f, 0.0f, 342 }; 343 */ 342 0.5f, 0.5f, 0.0f, 343 0.0f, -0.5f, 0.0f, 344 1.0f, -0.5f, 0.0f, 345 1.0f, -0.5f, 0.0f, 346 0.0f, -0.5f, 0.0f, 347 0.5f, 0.5f, 0.0f, 348 }; 344 349 345 350 // initialize global variables for click intersection test … … 349 354 350 355 GLfloat colors[] = { 351 1.0, 0.0, 0.0,352 0.0, 0.0, 1.0,353 0.0, 1.0, 0.0,354 0.0, 1.0, 0.0,355 0.0, 0.0, 1.0,356 1.0, 0.0, 0.0,356 1.0, 0.0, 0.0, 357 0.0, 0.0, 1.0, 358 0.0, 1.0, 0.0, 359 0.0, 1.0, 0.0, 360 0.0, 0.0, 1.0, 361 1.0, 0.0, 0.0, 357 362 }; 358 363 359 364 GLfloat colors_new[] = { 360 0.0, 1.0, 0.0,361 0.0, 1.0, 0.0,362 0.0, 1.0, 0.0,363 0.0, 1.0, 0.0,364 0.0, 1.0, 0.0,365 0.0, 1.0, 0.0,365 0.0, 1.0, 0.0, 366 0.0, 1.0, 0.0, 367 0.0, 1.0, 0.0, 368 0.0, 1.0, 0.0, 369 0.0, 1.0, 0.0, 370 0.0, 1.0, 0.0, 366 371 }; 367 372 … … 369 374 int numPoints = (sizeof(points) / sizeof(float)) / 3; 370 375 376 /* 371 377 GLfloat points2[] = { 372 378 0.5f, 0.5f, 0.0f, 373 379 -0.5f, 0.5f, 0.0f, 374 380 -0.5f, -0.5f, 0.0f, 375 381 0.5f, 0.5f, 0.0f, 376 382 -0.5f, -0.5f, 0.0f, 377 0.5f, -0.5f, 0.0f, 378 }; 379 380 /* 383 0.5f, -0.5f, 0.0f, 384 }; 385 */ 386 387 GLfloat points2[] = { 388 0.0f, 0.5f, 0.0f, 389 -1.0f, 0.5f, 0.0f, 390 -1.0f, -0.5f, 0.0f, 391 0.0f, 0.5f, 0.0f, 392 -1.0f, -0.5f, 0.0f, 393 0.0f, -0.5f, 0.0f, 394 }; 395 381 396 GLfloat colors2[] = { 382 0.0, 0.9, 0.9, 383 0.0, 0.9, 0.9, 384 0.0, 0.9, 0.9, 385 0.0, 0.9, 0.9, 386 0.0, 0.9, 0.9, 387 0.0, 0.9, 0.9, 388 }; 389 */ 397 0.0, 0.9, 0.9, 398 0.0, 0.9, 0.9, 399 0.0, 0.9, 0.9, 400 0.0, 0.9, 0.9, 401 0.0, 0.9, 0.9, 402 0.0, 0.9, 0.9, 403 }; 390 404 391 405 GLfloat texcoords[] = { 392 1.0f, 1.0f,393 0.0f, 1.0f,394 0.0, 0.0,395 1.0, 1.0,396 0.0, 0.0,397 1.0, 0.0406 1.0f, 1.0f, 407 0.0f, 1.0f, 408 0.0, 0.0, 409 1.0, 1.0, 410 0.0, 0.0, 411 1.0, 0.0 398 412 }; 399 413 … … 409 423 mat4 model_mat = T_model*R_model; 410 424 411 mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f));412 //mat4 T_model2 = translate(mat4(), vec3(0.0f, 0.0f, 0.0f));425 // mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f)); 426 mat4 T_model2 = translate(mat4(), vec3(0.0f, 0.0f, 0.0f)); 413 427 mat4 R_model2 = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f)); 414 428 mat4 model_mat2 = T_model2*R_model2; … … 440 454 glBufferData(GL_ARRAY_BUFFER, sizeof(points2), points2, GL_STATIC_DRAW); 441 455 442 /*443 456 GLuint colors2_vbo = 0; 444 457 glGenBuffers(1, &colors2_vbo); 445 458 glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo); 446 459 glBufferData(GL_ARRAY_BUFFER, sizeof(colors2), colors2, GL_STATIC_DRAW); 447 */448 460 449 461 GLuint vt_vbo; … … 475 487 476 488 //cam_pos = vec3(0.0f, 0.0f, 2.0f); 477 cam_pos = vec3(0. 3f, 0.0f, 0.3f);478 float cam_yaw = 45.0f * 2.0f * 3.14159f / 360.0f;489 cam_pos = vec3(0.0f, 0.0f, 0.3f); 490 float cam_yaw = 0.0f * 2.0f * 3.14159f / 360.0f; 479 491 480 492 mat4 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); … … 523 535 glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat)); 524 536 525 /*526 537 glUseProgram(shader_program2); 527 538 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat2)); 528 539 glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 529 */530 540 531 541 // glUniform1i(tex_loc, 0); … … 543 553 } 544 554 545 if (clicked) {546 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);547 548 if (colors_i == 0) {549 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW);550 colors_i = 1;551 } else {552 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);553 colors_i = 0;554 }555 556 clicked = false;557 }555 if (clicked) { 556 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 557 558 if (colors_i == 0) { 559 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW); 560 colors_i = 1; 561 } else { 562 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); 563 colors_i = 0; 564 } 565 566 clicked = false; 567 } 558 568 559 569 /* … … 571 581 glDrawArrays(GL_TRIANGLES, 0, numPoints); 572 582 573 glUseProgram(shader_program2); 574 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 575 576 glBindVertexArray(vao2); 577 578 int numPoints3 = numPoints2; 579 numPoints2 = numPoints3; 580 // glDrawArrays(GL_TRIANGLES, 0, numPoints2); 583 if (clicked_square) { 584 glUseProgram(shader_program); 585 glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat)); 586 587 glBindVertexArray(vao2); 588 589 glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo); 590 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 591 } else { 592 glUseProgram(shader_program2); 593 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 594 595 glBindVertexArray(vao2); 596 597 glBindBuffer(GL_ARRAY_BUFFER, vt_vbo); 598 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 599 } 600 601 glDrawArrays(GL_TRIANGLES, 0, numPoints2); 581 602 582 603 glfwPollEvents();
Note:
See TracChangeset
for help on using the changeset viewer.