Witam, program się uruchamia i nie ma żadnych błędów lecz pomimo że próbowałem na różne sposoby przemieszczać widok nic nie widze, może ktoś z was snajdzie czas i mi pomoże
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm\glm.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <glm\gtc\type_ptr.hpp>
#include <iostream>
#include <string>
#define ASSERT(x) if (!(x)) __debugbreak();
#define GLCall(x) GLClearError();\
x;\
ASSERT(GLLogCall(#x, __FILE__, __LINE__))
void GLClearError()
{
while (glGetError() != GL_NO_ERROR);
}
bool GLLogCall(const char* function, const char* file, int line)
{
while (GLenum error = glGetError())
{
std::cout << "[OpenGL Error] (" << error << "): " << function <<
" " << file << ":" << line << std::endl;
return false;
}
return true;
}
#define CX 16
#define CY 16
#define CZ 16
void checkCompileErrors(unsigned int shader, std::string type);
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec4 aPos;\n"
"uniform mat4 mvp;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vec4(aPos.xyz, 1.0);\n"
"}\0";
const char *fragmentShaderSource = "#version 330 core\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
"}\n\0";
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
typedef glm::tvec4<GLbyte> byte4;
struct chunk
{
uint8_t blk[CX][CY][CZ];
unsigned int vbo, vao;
int elements;
bool changed;
chunk() {
memset(blk, 0, sizeof(blk));
elements = 0;
changed = true;
GLCall(glGenBuffers(1, &vbo));
GLCall(glGenVertexArrays(1, &vao));
}
~chunk() {
GLCall(glDeleteBuffers(1, &vbo));
}
uint8_t get(int x, int y, int z) {
return blk[x][y][z];
}
void set(int x, int y, int z, uint8_t type) {
blk[x][y][z] = type;
changed = true;
}
void update() {
changed = false;
byte4 vertex[CX * CY * CZ * 6 * 6];
int i = 0;
for (int x = 0; x < CX; x++) {
for (int y = 0; y < CY; y++) {
for (int z = 0; z < CZ; z++) {
uint8_t type = blk[x][y][z];
// Empty block?
if (!type)
continue;
// View from negative x
vertex[i++] = byte4(x, y, z, type);
vertex[i++] = byte4(x, y, z + 1, type);
vertex[i++] = byte4(x, y + 1, z, type);
vertex[i++] = byte4(x, y + 1, z, type);
vertex[i++] = byte4(x, y, z + 1, type);
vertex[i++] = byte4(x, y + 1, z + 1, type);
// View from positive x
vertex[i++] = byte4(x + 1, y, z, type);
vertex[i++] = byte4(x + 1, y + 1, z, type);
vertex[i++] = byte4(x + 1, y, z + 1, type);
vertex[i++] = byte4(x + 1, y + 1, z, type);
vertex[i++] = byte4(x + 1, y + 1, z + 1, type);
vertex[i++] = byte4(x + 1, y, z + 1, type);
// View from negative y
vertex[i++] = byte4(x, y, z, type);
vertex[i++] = byte4(x + 1, y, z, type);
vertex[i++] = byte4(x, y, z + 1, type);
vertex[i++] = byte4(x + 1, y, z, type);
vertex[i++] = byte4(x + 1, y, z + 1, type);
vertex[i++] = byte4(x, y, z + 1, type);
// View from positive y
vertex[i++] = byte4(x, y + 1, z, type);
vertex[i++] = byte4(x, y + 1, z + 1, type);
vertex[i++] = byte4(x + 1, y + 1, z, type);
vertex[i++] = byte4(x + 1, y + 1, z, type);
vertex[i++] = byte4(x, y + 1, z + 1, type);
vertex[i++] = byte4(x + 1, y + 1, z + 1, type);
// View from negative z
vertex[i++] = byte4(x, y, z, type);
vertex[i++] = byte4(x, y + 1, z, type);
vertex[i++] = byte4(x + 1, y, z, type);
vertex[i++] = byte4(x, y + 1, z, type);
vertex[i++] = byte4(x + 1, y + 1, z, type);
vertex[i++] = byte4(x + 1, y, z, type);
// View from positive z
vertex[i++] = byte4(x, y, z + 1, type);
vertex[i++] = byte4(x + 1, y, z + 1, type);
vertex[i++] = byte4(x, y + 1, z + 1, type);
vertex[i++] = byte4(x, y + 1, z + 1, type);
vertex[i++] = byte4(x + 1, y, z + 1, type);
vertex[i++] = byte4(x + 1, y + 1, z + 1, type);
}
}
}
elements = i;
GLCall(glBindVertexArray(vao));
GLCall(glBindBuffer(GL_ARRAY_BUFFER, vbo));
GLCall(glBufferData(GL_ARRAY_BUFFER, elements * sizeof *vertex, vertex, GL_STATIC_DRAW));
}
void render() {
if (changed)
update();
// If this chunk is empty, we don't need to draw anything.
if (!elements)
return;
GLCall(glBindBuffer(GL_ARRAY_BUFFER, vbo));
GLCall(glBindVertexArray(vao));
GLCall(glEnableVertexAttribArray(0));
GLCall(glVertexAttribPointer(0, 4, GL_UNSIGNED_INT, GL_FALSE, 0, 0));
GLCall(glDrawArrays(GL_TRIANGLES, 0, elements));
}
};
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (glewInit() != GLEW_OK)
std::cout << "Error\n";
{
//-------------------S_H_A_D_E_R_S---------------------------
GLuint vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
checkCompileErrors(vertexShader, "VERTEX");
GLuint fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
checkCompileErrors(vertexShader, "FRAGMENT");
GLuint shaderProgram;
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
checkCompileErrors(vertexShader, "PROGRAM");
GLCall(glUseProgram(shaderProgram));
//--------------------------------------------------
chunk chunk;
for (int x = 0; x < CX; x++) {
for (int y = 0; y < CY; y++) {
for (int z = 0; z < CZ; z++) {
chunk.set(x, y, z, 1);
}
}
};
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
GLCall(glUseProgram(shaderProgram));
glm::mat4 model = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
glm::mat4 view = glm::mat4(1.0f);
glm::mat4 projection = glm::mat4(1.0f);
/*model = glm::rotate(model, glm::radians((float)glfwGetTime() * 55.0f), glm::vec3(0.0f, 1.0f, 0.0f));
view = glm::translate(view, glm::vec3(0.0f, 0.0f, 0.0f));
//view = glm::scale(view, glm::vec3(0.5, 0.5, 0.5));
projection = glm::perspective(glm::radians(50.0f), 640.f / 480.f, 0.1f, 100.0f);
glm::mat4 mvp = projection * view * model;*/
float angle = (float)glfwGetTime() / 1000.0f * 45; // 45° per second
glm::vec3 axis_y(0, 1, 0);
glm::mat4 anim = glm::rotate(glm::mat4(1.0f), glm::radians(angle), axis_y);
model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0, 0.0, -4.0));
view = glm::lookAt(glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0));
projection = glm::perspective(45.0f, 1.0f*640 / 480, 0.1f, 10.0f);
glm::mat4 mvp = projection * view * model * anim;
glUseProgram(shaderProgram);
GLuint transformLoc = glGetUniformLocation(shaderProgram, "mvp");
GLCall(glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(mvp)));
chunk.render();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
}
glfwTerminate();
return 0;
}
void checkCompileErrors(unsigned int shader, std::string type)
{
int success;
char infoLog[1024];
if (type != "PROGRAM")
{
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
else
{
glGetProgramiv(shader, GL_LINK_STATUS, &success);
if (!success)
{
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}