Код: Выделить всё
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Shader
{
public:
Shader(char* vertPath, char* fragPath)
{
unsigned int vert = glCreateShader(GL_VERTEX_SHADER);
unsigned int frag = glCreateShader(GL_FRAGMENT_SHADER);
string vertCode;
ifstream fileV;
fileV.open(vertPath, ios::in);
if (fileV.is_open()) {
stringstream ss;
ss HasNormals())
{
vec.x = mesh->mNormals[i].x;
vec.y = mesh->mNormals[i].y;
vec.z = mesh->mNormals[i].z;
vertex.Normal = vec;
}
vertices.push_back(vertex);
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
for (unsigned int j = 0; j < face.mNumIndices; j++) {
indices.push_back(face.mIndices[j]);
}
}
// Buffers
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
// VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
// EBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
shader = new Shader("assets/shaders/mesh.vert", "assets/shaders/mesh.frag");
// VAO
glBindVertexArray(VAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, TexCoord));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, Normal));
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
transform = glm::mat4(1.0f);
transform = glm::translate(transform, glm::vec3(0,0,-1));
transform = glm::scale(transform, glm::vec3(0.1, 0.1, 0.1));
}
~Mesh();
void draw()
{
shader->activate();
shader->setMat4("transform", transform);
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (void*)0);
glBindVertexArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
shader->deactivate();
}
private:
Buffer VAO, VBO, EBO;
std::vector vertices;
std::vector indices;
Shader* shader;
glm::mat4 transform;
};
float moveX, moveZ;
int width, height;
void cursor_position_callback(Window window, double xpos, double ypos)
{
if (xpos >= width-30)
{
moveX = -10;
}
else if (xpos = end_point)
{
glTranslatef(0,-10,0);
movedY -= 10;
}
if (moveX != 0) {
glTranslatef(moveX,0,0);
}
else if (moveZ != 0) {
glTranslatef(0,0,moveZ);
}
model.draw();
if (glfwGetKey(GLFW_KEY_ESCAPE) == GLFW_PRESS) {
break;
}
glfwSwapBuffers(window);
glfwPollEvents();
}
return 0;
}
< /code>
vertex shader: < /p>
#version 110
attribute vec3 Position;
attribute vec2 TexCoord;
attribute vec3 Normal;
uniform mat4 transform;
void main()
{
gl_Position = transform * vec4(Position, 1);
}
< /code>
фрагментный шейдер: < /p>
#version 110
void main()
{
gl_FragColor = vec4(1, 1, 1, 1);
}
model в 3d view. />
Не существует никаких ошибок, потому что Glgeterror () всегда возвращает 0, а программа возвращает 0, когда она закрывает. Компилятор mingw-w64 (от кодовых блоков).
Моя ОС-ОС-ОС-Windows 10 (64-бит).
Ассамп строится динамически с использованием того же компилятора.
Подробнее здесь: https://stackoverflow.com/questions/796 ... ncorrectly