Changeset b155f13 in opengl-game
- Timestamp:
- Jul 12, 2018, 3:18:00 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 92b1e90
- Parents:
- 5c02ddd
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
NewOpenGLGame.vcxproj
r5c02ddd rb155f13 163 163 <None Include="color.frag" /> 164 164 <None Include="color.vert" /> 165 <None Include="laser.frag" /> 166 <None Include="laser.vert" /> 165 167 <None Include="texture.frag" /> 166 168 <None Include="texture.vert" /> -
new-game.cpp
r5c02ddd rb155f13 104 104 void calculateObjectBoundingBox(SceneObject& obj); 105 105 106 void addLaserToScene(vec3 start, vec3 end, vec3 color, 107 GLfloat width, 108 unsigned int& num_lasers, 109 GLuint laser_points_vbo, 110 GLuint laser_colors_vbo); 111 106 112 void initializeBuffers( 107 113 GLuint* points_vbo, … … 141 147 GLuint color_sp, GLuint texture_sp, 142 148 GLuint vao1, GLuint vao2, 143 GLuint points_vbo, GLuint normals_vbo, 144 GLuint colors_vbo, GLuint texcoords_vbo, GLuint selected_colors_vbo, 149 GLuint colors_vbo, GLuint selected_colors_vbo, 145 150 SceneObject* selectedObject, 146 151 map<GLuint, BufferInfo>& shaderBufferInfo); 152 void renderLasers(GLuint sp, GLuint vao, unsigned int numLasers); 147 153 void renderSceneGui(); 148 154 … … 345 351 GLuint color_sp = loadShaderProgram("./color.vert", "./color.frag"); 346 352 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag"); 353 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 347 354 348 355 shaderBufferInfo[color_sp] = BufferInfo(); 349 356 shaderBufferInfo[texture_sp] = BufferInfo(); 357 shaderBufferInfo[laser_sp] = BufferInfo(); 350 358 351 359 SceneObject obj; … … 795 803 obj.selected_colors = { 0.0f }; 796 804 797 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1. 8f));805 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)); 798 806 R_model = rotate(mat4(1.0f), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f)); 799 807 R_model = mat4(1.0f); … … 828 836 model_mat_idx_vbo); 829 837 838 unsigned int max_num_lasers = 20; 839 unsigned int num_lasers = 0; 840 841 GLuint laser_points_vbo = 0; 842 glGenBuffers(1, &laser_points_vbo); 843 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo); 844 glBufferData(GL_ARRAY_BUFFER, max_num_lasers * 18 * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 845 846 GLuint laser_colors_vbo = 0; 847 glGenBuffers(1, &laser_colors_vbo); 848 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo); 849 glBufferData(GL_ARRAY_BUFFER, max_num_lasers * 18 * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 850 851 addLaserToScene(vec3(0.34f, -2.0f, 1.6f), vec3(0.34f, -2.0f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.04f, 852 num_lasers, laser_points_vbo, laser_colors_vbo); 853 addLaserToScene(vec3(-0.34f, -2.0f, 1.6f), vec3(-0.34f, -2.0f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.04f, 854 num_lasers, laser_points_vbo, laser_colors_vbo); 855 830 856 GLuint vao = 0; 831 857 glGenVertexArrays(1, &vao); … … 866 892 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 867 893 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0); 894 895 GLuint laser_vao = 0; 896 glGenVertexArrays(1, &laser_vao); 897 glBindVertexArray(laser_vao); 898 899 glEnableVertexAttribArray(0); 900 glEnableVertexAttribArray(1); 901 902 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo); 903 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); 904 905 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo); 906 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); 868 907 869 908 float cam_speed = 1.0f; … … 912 951 GLuint texture_sp_ub_index = glGetUniformBlockIndex(texture_sp, "models"); 913 952 953 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); 954 GLuint laser_proj_mat_loc = glGetUniformLocation(laser_sp, "proj"); 955 914 956 glUseProgram(color_sp); 915 957 glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat)); … … 925 967 glUniformBlockBinding(texture_sp, texture_sp_ub_index, ub_binding_point); 926 968 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 969 970 glUseProgram(laser_sp); 971 glUniformMatrix4fv(laser_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 972 glUniformMatrix4fv(laser_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 927 973 928 974 bool cam_moved = false; … … 1113 1159 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 1114 1160 1161 glUseProgram(laser_sp); 1162 glUniformMatrix4fv(laser_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 1163 1115 1164 cam_moved = false; 1116 1165 } … … 1129 1178 color_sp, texture_sp, 1130 1179 vao, vao2, 1131 points_vbo, normals_vbo, 1132 colors_vbo, texcoords_vbo, selected_colors_vbo, 1180 colors_vbo, selected_colors_vbo, 1133 1181 selectedObject, 1134 1182 shaderBufferInfo); 1183 renderLasers(laser_sp, laser_vao, num_lasers); 1135 1184 renderSceneGui(); 1136 1185 break; … … 1477 1526 } 1478 1527 1528 // currently only works correctly for lasers oriented along the z axis 1529 void addLaserToScene(vec3 start, vec3 end, vec3 color, GLfloat width, unsigned int& num_lasers, 1530 GLuint laser_points_vbo, GLuint laser_colors_vbo) { 1531 GLuint size_in_buffer = 18 * sizeof(GLfloat) * 3; 1532 1533 // I really need to create a direction vector and add/subtract that from start and end 1534 // to get the right coords 1535 // Also need to multiply the width times a vector perpendicular to it 1536 vec3 dir = end - start; 1537 1538 vector<GLfloat> laser_points = { 1539 end.x + width / 2, end.y, start.z - width, 1540 end.x - width / 2, end.y, start.z - width, 1541 start.x - width / 2, start.y, start.z, 1542 end.x + width / 2, end.y, start.z - width, 1543 start.x - width / 2, start.y, start.z, 1544 start.x + width / 2, start.y, start.z, 1545 end.x + width / 2, end.y, end.z + width, 1546 end.x - width / 2, end.y, end.z + width, 1547 start.x - width / 2, start.y, start.z - width, 1548 end.x + width / 2, end.y, end.z + width, 1549 start.x - width / 2, start.y, start.z - width, 1550 start.x + width / 2, start.y, start.z - width, 1551 end.x + width / 2, end.y, end.z, 1552 end.x - width / 2, end.y, end.z, 1553 start.x - width / 2, start.y, end.z + width, 1554 end.x + width / 2, end.y, end.z, 1555 start.x - width / 2, start.y, end.z + width, 1556 start.x + width / 2, start.y, end.z + width, 1557 }; 1558 1559 vec3 end_color = vec3(1.0f, 0.0f, 0.0f); // temporary 1560 vector<GLfloat> laser_colors = { 1561 end_color.x, end_color.y, end_color.z, 1562 end_color.x, end_color.y, end_color.z, 1563 end_color.x, end_color.y, end_color.z, 1564 end_color.x, end_color.y, end_color.z, 1565 end_color.x, end_color.y, end_color.z, 1566 end_color.x, end_color.y, end_color.z, 1567 color.x, color.y, color.z, 1568 color.x, color.y, color.z, 1569 color.x, color.y, color.z, 1570 color.x, color.y, color.z, 1571 color.x, color.y, color.z, 1572 color.x, color.y, color.z, 1573 end_color.x, end_color.y, end_color.z, 1574 end_color.x, end_color.y, end_color.z, 1575 end_color.x, end_color.y, end_color.z, 1576 end_color.x, end_color.y, end_color.z, 1577 end_color.x, end_color.y, end_color.z, 1578 end_color.x, end_color.y, end_color.z, 1579 }; 1580 1581 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo); 1582 glBufferSubData(GL_ARRAY_BUFFER, num_lasers * size_in_buffer, size_in_buffer, &laser_points[0]); 1583 1584 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo); 1585 glBufferSubData(GL_ARRAY_BUFFER, num_lasers * size_in_buffer, size_in_buffer, &laser_colors[0]); 1586 1587 num_lasers++; 1588 } 1589 1479 1590 void initializeBuffers( 1480 1591 GLuint* points_vbo, … … 1679 1790 GLuint color_sp, GLuint texture_sp, 1680 1791 GLuint vao1, GLuint vao2, 1681 GLuint points_vbo, GLuint normals_vbo, 1682 GLuint colors_vbo, GLuint texcoords_vbo, GLuint selected_colors_vbo, 1792 GLuint colors_vbo, GLuint selected_colors_vbo, 1683 1793 SceneObject* selectedObject, 1684 1794 map<GLuint, BufferInfo>& shaderBufferInfo) { … … 1703 1813 1704 1814 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[texture_sp].vbo_base, shaderBufferInfo[texture_sp].vbo_offset); 1815 } 1816 1817 void renderLasers(GLuint sp, GLuint vao, unsigned int numLasers) { 1818 glUseProgram(sp); 1819 glBindVertexArray(vao); 1820 1821 glDrawArrays(GL_TRIANGLES, 0, numLasers * 18); 1705 1822 } 1706 1823
Note:
See TracChangeset
for help on using the changeset viewer.