Changeset 6877ef3 in opengl-game for new-game.cpp
- Timestamp:
- Jul 15, 2018, 8:44:16 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 9f9f9a7
- Parents:
- 92b1e90
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r92b1e90 r6877ef3 41 41 * -The laser shader should take an input color to blend with the texture to give the lasers color 42 42 * -The lasers should be SceneObjects and drawn like all other objects 43 * -DONE 43 44 * -Make lasers shoot from the ends of the ship's wings when the user presses a button and disappear after a second or so 44 45 */ … … 116 117 GLuint normals_vbo, 117 118 GLuint ubo, 118 GLuint model_mat_idx_vbo, 119 GLuint laser_points_vbo, 120 GLuint laser_colors_vbo); 119 GLuint model_mat_idx_vbo); 121 120 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 122 121 … … 132 131 GLuint* normals_vbo, 133 132 GLuint* ubo, 134 GLuint* model_mat_idx_vbo, 135 GLuint* laser_points_vbo, 136 GLuint* laser_colors_vbo); 133 GLuint* model_mat_idx_vbo); 137 134 138 135 void populateBuffers(vector<SceneObject>& objects, … … 144 141 GLuint normals_vbo, 145 142 GLuint ubo, 146 GLuint model_mat_idx_vbo, 147 GLuint laser_points_vbo, 148 GLuint laser_colors_vbo); 143 GLuint model_mat_idx_vbo); 149 144 150 145 void copyObjectDataToBuffers(SceneObject& obj, … … 156 151 GLuint normals_vbo, 157 152 GLuint ubo, 158 GLuint model_mat_idx_vbo, 159 GLuint laser_points_vbo, 160 GLuint laser_colors_vbo); 153 GLuint model_mat_idx_vbo); 161 154 162 155 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); … … 167 160 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 168 161 GLuint color_sp, GLuint texture_sp, GLuint laser_sp, 169 GLuint color_vao, GLuint texture_vao, GLuint laser_vao,162 GLuint color_vao, GLuint texture_vao, 170 163 GLuint colors_vbo, GLuint selected_colors_vbo, 171 164 SceneObject* selectedObject); … … 180 173 GLuint normals_vbo, 181 174 GLuint ubo, 182 GLuint model_mat_idx_vbo, 183 GLuint laser_points_vbo, 184 GLuint laser_colors_vbo); 175 GLuint model_mat_idx_vbo); 185 176 186 177 float getRandomNum(float low, float high); … … 850 841 851 842 GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo, 852 normals_vbo, ubo, model_mat_idx_vbo , laser_points_vbo, laser_colors_vbo;843 normals_vbo, ubo, model_mat_idx_vbo; 853 844 854 845 initializeBuffers( … … 859 850 &normals_vbo, 860 851 &ubo, 861 &model_mat_idx_vbo, 862 &laser_points_vbo, 863 &laser_colors_vbo); 852 &model_mat_idx_vbo); 864 853 865 854 populateBuffers(objects, … … 871 860 normals_vbo, 872 861 ubo, 873 model_mat_idx_vbo, 874 laser_points_vbo, 875 laser_colors_vbo); 862 model_mat_idx_vbo); 876 863 877 864 GLuint color_vao = 0; … … 913 900 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 914 901 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0); 915 916 GLuint laser_vao = 0;917 glGenVertexArrays(1, &laser_vao);918 glBindVertexArray(laser_vao);919 920 glEnableVertexAttribArray(0);921 glEnableVertexAttribArray(1);922 923 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo);924 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);925 926 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo);927 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);928 902 929 903 float cam_speed = 1.0f; … … 1066 1040 normals_vbo, 1067 1041 ubo, 1068 model_mat_idx_vbo, 1069 laser_points_vbo, 1070 laser_colors_vbo); 1042 model_mat_idx_vbo); 1071 1043 1072 1044 elapsed_seconds_spawn -= 0.5f; … … 1201 1173 renderScene(shaderBufferInfo, 1202 1174 color_sp, texture_sp, laser_sp, 1203 color_vao, texture_vao, laser_vao,1175 color_vao, texture_vao, 1204 1176 colors_vbo, selected_colors_vbo, 1205 1177 selectedObject); … … 1457 1429 GLuint normals_vbo, 1458 1430 GLuint ubo, 1459 GLuint model_mat_idx_vbo, 1460 GLuint laser_points_vbo, 1461 GLuint laser_colors_vbo) { 1431 GLuint model_mat_idx_vbo) { 1462 1432 addObjectToSceneDuringInit(obj); 1463 1433 … … 1475 1445 normals_vbo, 1476 1446 ubo, 1477 model_mat_idx_vbo, 1478 laser_points_vbo, 1479 laser_colors_vbo); 1447 model_mat_idx_vbo); 1480 1448 } else { 1481 1449 copyObjectDataToBuffers(objects.back(), shaderBufferInfo, … … 1486 1454 normals_vbo, 1487 1455 ubo, 1488 model_mat_idx_vbo, 1489 laser_points_vbo, 1490 laser_colors_vbo); 1456 model_mat_idx_vbo); 1491 1457 } 1492 1458 } … … 1621 1587 GLuint* normals_vbo, 1622 1588 GLuint* ubo, 1623 GLuint* model_mat_idx_vbo, 1624 GLuint* laser_points_vbo, 1625 GLuint* laser_colors_vbo) { 1589 GLuint* model_mat_idx_vbo) { 1626 1590 *points_vbo = 0; 1627 1591 glGenBuffers(1, points_vbo); … … 1644 1608 *model_mat_idx_vbo = 0; 1645 1609 glGenBuffers(1, model_mat_idx_vbo); 1646 1647 *laser_points_vbo = 0;1648 glGenBuffers(1, laser_points_vbo);1649 1650 *laser_colors_vbo = 0;1651 glGenBuffers(1, laser_colors_vbo);1652 1610 } 1653 1611 … … 1660 1618 GLuint normals_vbo, 1661 1619 GLuint ubo, 1662 GLuint model_mat_idx_vbo, 1663 GLuint laser_points_vbo, 1664 GLuint laser_colors_vbo) { 1620 GLuint model_mat_idx_vbo) { 1665 1621 GLsizeiptr points_buffer_size = 0; 1666 1622 GLsizeiptr textures_buffer_size = 0; … … 1721 1677 shaderBufferInfo[shaderIt->first].ubo_base = lastShaderUboCount * 2; 1722 1678 1723 if (shaderIt->first == 9) { // hack to check for laser_sp1724 shaderBufferInfo[shaderIt->first].vbo_base = 0;1725 shaderBufferInfo[shaderIt->first].ubo_base = 0; // unused now anyway1726 }1727 1728 1679 cout << "shader: " << shaderIt->first << endl; 1729 1680 cout << "point counts: " << shaderCounts[shaderIt->first] << endl; … … 1764 1715 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 1765 1716 glBufferData(GL_ARRAY_BUFFER, model_mat_idx_buffer_size, NULL, GL_DYNAMIC_DRAW); 1766 1767 unsigned int max_num_lasers = 20;1768 1769 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo);1770 glBufferData(GL_ARRAY_BUFFER, max_num_lasers * 18 * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW);1771 1772 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo);1773 glBufferData(GL_ARRAY_BUFFER, max_num_lasers * 18 * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW);1774 1717 1775 1718 for (it = objects.begin(); it != objects.end(); it++) { … … 1781 1724 normals_vbo, 1782 1725 ubo, 1783 model_mat_idx_vbo, 1784 laser_points_vbo, 1785 laser_colors_vbo); 1726 model_mat_idx_vbo); 1786 1727 } 1787 1728 } … … 1795 1736 GLuint normals_vbo, 1796 1737 GLuint ubo, 1797 GLuint model_mat_idx_vbo, 1798 GLuint laser_points_vbo, 1799 GLuint laser_colors_vbo) { 1738 GLuint model_mat_idx_vbo) { 1800 1739 BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program]; 1801 1740 … … 1803 1742 obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset; 1804 1743 1805 if (obj.type == TYPE_LASER) { 1806 glBindBuffer(GL_ARRAY_BUFFER, laser_points_vbo); 1807 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); 1808 1809 glBindBuffer(GL_ARRAY_BUFFER, laser_colors_vbo); 1810 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.colors[0]); 1811 } else { 1812 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 1813 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); 1814 1815 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 1816 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]); 1817 1744 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 1745 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); 1746 1747 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 1748 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]); 1749 1750 1751 if (obj.type != TYPE_LASER) { 1818 1752 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 1819 1753 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]); … … 1851 1785 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 1852 1786 GLuint color_sp, GLuint texture_sp, GLuint laser_sp, 1853 GLuint color_vao, GLuint texture_vao, GLuint laser_vao,1787 GLuint color_vao, GLuint texture_vao, 1854 1788 GLuint colors_vbo, GLuint selected_colors_vbo, 1855 1789 SceneObject* selectedObject) { … … 1876 1810 1877 1811 glUseProgram(laser_sp); 1878 glBindVertexArray( laser_vao);1812 glBindVertexArray(color_vao); 1879 1813 1880 1814 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); … … 1980 1914 GLuint normals_vbo, 1981 1915 GLuint ubo, 1982 GLuint model_mat_idx_vbo, 1983 GLuint laser_points_vbo, 1984 GLuint laser_colors_vbo) { 1916 GLuint model_mat_idx_vbo) { 1985 1917 SceneObject obj = SceneObject(); 1986 1918 obj.type = TYPE_ASTEROID; … … 2101 2033 normals_vbo, 2102 2034 ubo, 2103 model_mat_idx_vbo, 2104 laser_points_vbo, 2105 laser_colors_vbo); 2035 model_mat_idx_vbo); 2106 2036 } 2107 2037
Note:
See TracChangeset
for help on using the changeset viewer.