Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Window.h"
- #include "Shader.h"
- #include "ShaderProgram.h"
- #include "Mesh.h"
- #include "Camera.h"
- #include "Time.h"
- #include <iostream>
- #include "DrawableObject.h"
- int main()
- {
- Window window(1680, 1050, "VoxelCraft", GL_FALSE);
- window.setClearColor(0.59765625f, 0.796875f, 0.99609375f, 1.0f);
- Shader vertexShader("vertexShader", GL_VERTEX_SHADER);
- Shader fragmentShader("fragmentShader", GL_FRAGMENT_SHADER);
- ShaderProgram shaderProgram(vertexShader, fragmentShader);
- shaderProgram.bind();
- Camera camera(glm::vec3(0.0f, 0.0f, 0.0f), 70.0f, (GLfloat)window.getWidth() / (GLfloat)window.getHeight(), 0.01f, 1000.0f, shaderProgram, 10.5f, 0.05f);
- /* Chunk */
- enum BlockTypes
- {
- AIR = 0,
- GRASS = 1
- };
- static const GLuint size = 16;
- GLuint blockIDs[size + 1][size + 1][size + 1];
- Mesh mesh;
- Texture texture(shaderProgram, "grass", "outTexture", 0);
- for (GLuint x = 0; x < size; x++)
- {
- for (GLuint y = 0; y < size; y++)
- {
- for (GLuint z = 0; z < size; z++)
- {
- blockIDs[x][y][z] = GRASS;
- }
- }
- }
- std::vector<glm::vec3> positions;
- for (GLuint x = 0; x < size; x++)
- {
- for (GLuint y = 0; y < size; y++)
- {
- for (GLuint z = 0; z < size; z++)
- {
- if (blockIDs[x + 1][y][z] != GRASS)
- {
- mesh.addData(glm::vec3(1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 0.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- if (blockIDs[x - 1][y][z] != GRASS)
- {
- mesh.addData(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- if (blockIDs[x][y + 1][z] != GRASS)
- {
- mesh.addData(glm::vec3(0.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 0.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- if (blockIDs[x][y - 1][z] != GRASS)
- {
- mesh.addData(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- if (blockIDs[x][y][z + 1] != GRASS)
- {
- mesh.addData(glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- if (blockIDs[x][y][z - 1] != GRASS)
- {
- mesh.addData(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f));
- mesh.addData(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec2(0.0f, 0.0f));
- mesh.addData(glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 0.0f));
- mesh.addData(glm::vec3(1.0f, 1.0f, 0.0f), glm::vec2(1.0f, 1.0f));
- positions.push_back(glm::vec3(x, y, z));
- }
- }
- }
- }
- mesh.setIndices({
- 0, 1, 2,
- 2, 3, 0,
- 4, 5, 6,
- 6, 7, 4,
- 8, 9, 10,
- 10, 11, 8,
- 12, 13, 14,
- 14, 15, 12,
- 16, 17, 18,
- 18, 19, 16,
- 20, 21, 22,
- 22, 23, 20
- });
- mesh.upload();
- DrawableObject block(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), texture, &mesh);
- /* End of chunk */
- Time time;
- while (window.isOpen())
- {
- time.startCounting();
- window.clear();
- camera.update(window, shaderProgram, time.getDeltaTime());
- for (glm::vec3 position : positions)
- {
- block.setPosition(position);
- block.draw(shaderProgram);
- }
- window.update();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement