Changeset 9f9f9a7 in opengl-game for new-game.cpp
- Timestamp:
- Jul 17, 2018, 3:21:12 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- fd6f465
- Parents:
- 6877ef3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r6877ef3 r9f9f9a7 40 40 * -The textures should be grayscale and have transparency 41 41 * -The laser shader should take an input color to blend with the texture to give the lasers color 42 * -DONE 42 43 * -The lasers should be SceneObjects and drawn like all other objects 43 44 * -DONE 44 45 * -Make lasers shoot from the ends of the ship's wings when the user presses a button and disappear after a second or so 46 * 47 * NOTE: Asteroid movement currently depends on framerate, fix this in a generic/reusable way 45 48 */ 46 49 … … 233 236 #endif 234 237 235 glfwWindowHint(GLFW_SAMPLES, 4);238 glfwWindowHint(GLFW_SAMPLES, 16); 236 239 237 240 GLFWwindow* window = NULL; … … 304 307 printf("OpenGL version supported %s\n", version); 305 308 309 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 310 306 311 glEnable(GL_DEPTH_TEST); 307 312 glDepthFunc(GL_LESS); … … 311 316 // glFrontFace(GL_CW); 312 317 318 /* 313 319 int x, y; 314 320 unsigned char* texImage = loadImage("test.png", &x, &y); … … 320 326 } 321 327 322 GLuint te x = 0;323 glGenTextures(1, &te x);328 GLuint testTex = 0; 329 glGenTextures(1, &testTex); 324 330 glActiveTexture(GL_TEXTURE0); 325 glBindTexture(GL_TEXTURE_2D, tex); 331 glBindTexture(GL_TEXTURE_2D, testTex); 332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage); 333 334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 336 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 337 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 338 */ 339 340 int x, y; 341 unsigned char* texImage = loadImage("laser.png", &x, &y); 342 if (texImage) { 343 cout << "Laser texture loaded successfully!" << endl; 344 cout << x << endl; 345 cout << y << endl; 346 printf("first 4 bytes are: %i %i %i %i\n", texImage[0], texImage[1], texImage[2], texImage[3]); 347 } 348 349 GLuint laserTex = 0; 350 glGenTextures(1, &laserTex); 351 glActiveTexture(GL_TEXTURE0); 352 glBindTexture(GL_TEXTURE_2D, laserTex); 326 353 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage); 327 354 … … 948 975 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); 949 976 GLuint laser_proj_mat_loc = glGetUniformLocation(laser_sp, "proj"); 977 GLuint laser_color_loc = glGetUniformLocation(laser_sp, "laser_color"); 950 978 951 979 glUseProgram(color_sp); … … 963 991 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 964 992 993 965 994 glUseProgram(laser_sp); 966 995 glUniformMatrix4fv(laser_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 967 996 glUniformMatrix4fv(laser_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 997 glUniform3f(laser_color_loc, 0.2f, 1.0f, 0.2f); 968 998 969 999 bool cam_moved = false; … … 1533 1563 1534 1564 obj.points = { 1535 start.x + width / 2, start.y, start.z - width ,1536 start.x - width / 2, start.y, start.z - width ,1565 start.x + width / 2, start.y, start.z - width / 2, 1566 start.x - width / 2, start.y, start.z - width / 2, 1537 1567 start.x - width / 2, start.y, start.z, 1538 start.x + width / 2, start.y, start.z - width ,1568 start.x + width / 2, start.y, start.z - width / 2, 1539 1569 start.x - width / 2, start.y, start.z, 1540 1570 start.x + width / 2, start.y, start.z, 1541 end.x + width / 2, end.y, end.z + width ,1542 end.x - width / 2, end.y, end.z + width ,1543 start.x - width / 2, start.y, start.z - width ,1544 end.x + width / 2, end.y, end.z + width ,1545 start.x - width / 2, start.y, start.z - width ,1546 start.x + width / 2, start.y, start.z - width ,1571 end.x + width / 2, end.y, end.z + width / 2, 1572 end.x - width / 2, end.y, end.z + width / 2, 1573 start.x - width / 2, start.y, start.z - width / 2, 1574 end.x + width / 2, end.y, end.z + width / 2, 1575 start.x - width / 2, start.y, start.z - width / 2, 1576 start.x + width / 2, start.y, start.z - width / 2, 1547 1577 end.x + width / 2, end.y, end.z, 1548 1578 end.x - width / 2, end.y, end.z, 1549 end.x - width / 2, end.y, end.z + width ,1579 end.x - width / 2, end.y, end.z + width / 2, 1550 1580 end.x + width / 2, end.y, end.z, 1551 end.x - width / 2, end.y, end.z + width ,1552 end.x + width / 2, end.y, end.z + width ,1581 end.x - width / 2, end.y, end.z + width / 2, 1582 end.x + width / 2, end.y, end.z + width / 2, 1553 1583 }; 1554 1584 … … 1575 1605 }; 1576 1606 1607 obj.texcoords = { 1608 1.0f, 0.5f, 1609 0.0f, 0.5f, 1610 0.0f, 0.0f, 1611 1.0f, 0.5f, 1612 0.0f, 0.0f, 1613 1.0f, 0.0f, 1614 1.0f, 0.51f, 1615 0.0f, 0.51f, 1616 0.0f, 0.49f, 1617 1.0f, 0.51f, 1618 0.0f, 0.49f, 1619 1.0f, 0.49f, 1620 1.0f, 1.0f, 1621 0.0f, 1.0f, 1622 0.0f, 0.5f, 1623 1.0f, 1.0f, 1624 0.0f, 0.5f, 1625 1.0f, 0.5f, 1626 }; 1627 1577 1628 obj.num_points = obj.points.size() / 3; 1578 1629 … … 1752 1803 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 1753 1804 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]); 1754 1755 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 1756 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]); 1757 1805 } 1806 1807 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 1808 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]); 1809 1810 if (obj.type != TYPE_LASER) { 1758 1811 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 1759 1812 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.normals.size() * sizeof(GLfloat), &obj.normals[0]); … … 1809 1862 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[texture_sp].vbo_base, shaderBufferInfo[texture_sp].vbo_offset); 1810 1863 1864 glEnable(GL_BLEND); 1865 1811 1866 glUseProgram(laser_sp); 1812 glBindVertexArray( color_vao);1867 glBindVertexArray(texture_vao); 1813 1868 1814 1869 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 1870 1871 glDisable(GL_BLEND); 1815 1872 } 1816 1873
Note:
See TracChangeset
for help on using the changeset viewer.