#ifndef GLAD #define GLAD #include #endif #include #include "blockIcon.hpp" #include "chunk.hpp" #include "block.hpp" #include #include #include blockIcon::blockIcon(){} blockIcon::blockIcon(BlockID block,float x, float y, float width_height/*Width and Height are the same*/){ this->block =block; this->x =x; this->y =y; this->width_height =width_height; glGenVertexArrays(1,&VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER,VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO); glVertexAttribPointer(0,3, GL_FLOAT, GL_FALSE,8*sizeof(float),NULL); glEnableVertexAttribArray(0); glVertexAttribPointer(1,3, GL_FLOAT, GL_FALSE,8*sizeof(float),(void*)(3*sizeof(float))); glEnableVertexAttribArray(1); glVertexAttribPointer(2,2, GL_FLOAT, GL_FALSE,8*sizeof(float),(void*)(6*sizeof(float))); glEnableVertexAttribArray(2); addFaceIndicesAndVertices(block,3,Vector3f(0,0,0),indices,vertices); addFaceIndicesAndVertices(block,0,Vector3f(0,0,0),indices,vertices); addFaceIndicesAndVertices(block,5,Vector3f(0,0,0),indices,vertices); glBindBuffer(GL_ARRAY_BUFFER,VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO); //Send the vertex data to the GPU glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(float), &vertices[0], GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER,indices.size()*sizeof(int),&indices[0], GL_STATIC_DRAW); } void blockIcon::Draw(Shader shader,float screenRatio){ Matrix4f transform = //TranslationMatrix(Vector3f(-1,-0.95,0))* TranslationMatrix(Vector3f(x+0.01,y+0.05,0))* ScaleMatrix(2.0* width_height)* PerspectiveProjectionMatrix( 0.001, 800.0, screenRatio)* TranslationMatrix(Vector3f(0,0,4))* PitchRotationMatrix(M_PI/4)* //Rotate around the X-axis YawRotationMatrix(-M_PI/4); //Rotate around the Y-axis //Sends the transformation matrix to the shader shader.setUniformMat4("transform",transform); glBindVertexArray(VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO); glDrawElements(GL_TRIANGLES, indices.size(),GL_UNSIGNED_INT, 0); }