| 651 | "}"; |
| 652 | |
| 653 | static void |
| 654 | gears_init(void) |
| 655 | { |
| 656 | GLuint v, f, program; |
| 657 | const char *p; |
| 658 | char msg[512]; |
| 659 | |
| 660 | glEnable(GL_CULL_FACE); |
| 661 | glEnable(GL_DEPTH_TEST); |
| 662 | |
| 663 | /* Compile the vertex shader */ |
| 664 | p = vertex_shader; |
| 665 | v = glCreateShader(GL_VERTEX_SHADER); |
| 666 | glShaderSource(v, 1, &p, NULL); |
| 667 | glCompileShader(v); |
| 668 | glGetShaderInfoLog(v, sizeof msg, NULL, msg); |
| 669 | printf("vertex shader info: %s\n", msg); |
| 670 | |
| 671 | /* Compile the fragment shader */ |
| 672 | p = fragment_shader; |
| 673 | f = glCreateShader(GL_FRAGMENT_SHADER); |
| 674 | glShaderSource(f, 1, &p, NULL); |
| 675 | glCompileShader(f); |
| 676 | glGetShaderInfoLog(f, sizeof msg, NULL, msg); |
| 677 | printf("fragment shader info: %s\n", msg); |
| 678 | |
| 679 | /* Create and link the shader program */ |
| 680 | program = glCreateProgram(); |
| 681 | glAttachShader(program, v); |
| 682 | glAttachShader(program, f); |
| 683 | glBindAttribLocation(program, 0, "position"); |
| 684 | glBindAttribLocation(program, 1, "normal"); |
| 685 | |
| 686 | glLinkProgram(program); |
| 687 | glGetProgramInfoLog(program, sizeof msg, NULL, msg); |
| 688 | printf("info: %s\n", msg); |
| 689 | |
| 690 | /* Enable the shaders */ |
| 691 | glUseProgram(program); |
| 692 | |
| 693 | /* Get the locations of the uniforms so we can access them */ |
| 694 | ModelViewProjectionMatrix_location = glGetUniformLocation(program, "ModelViewProjectionMatrix"); |
| 695 | NormalMatrix_location = glGetUniformLocation(program, "NormalMatrix"); |
| 696 | LightSourcePosition_location = glGetUniformLocation(program, "LightSourcePosition"); |
| 697 | MaterialColor_location = glGetUniformLocation(program, "MaterialColor"); |
| 698 | |
| 699 | /* Set the LightSourcePosition uniform which is constant throught the program */ |
| 700 | glUniform4fv(LightSourcePosition_location, 1, LightSourcePosition); |
| 701 | |
| 702 | { |
| 703 | GLfloat LightSourcePosition_copy[4]; |
| 704 | glGetUniformfv(program, LightSourcePosition_location, LightSourcePosition_copy); |
| 705 | for (uint32_t i = 0; i < 4; ++i) { |
| 706 | assert(LightSourcePosition[i] == LightSourcePosition_copy[i]); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /* make the gears */ |
no test coverage detected