我是OpenGL的新手,遇到了一个似乎无法破解的问题。我正在尝试向三角形添加简单的2D纹理,该纹理似乎可以很好地加载,但是正在以黑色和白色显示粒状。
质地
结果
这是我的相关代码:
main.cxx
#include <iostream>
#include "display.h"
#include "shader.h"
#include "texture.h"
#include "mesh.h"
#include <glm/glm.hpp>
#include <GLFW/glfw3.h>
int main()
{
Display display(800, 600, "project2");
Vertex vertices[] = {
Vertex(glm::vec3(-0.5f, -0.5f, 0.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(0.5f, -0.5f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.0f, 0.5f, 0.0f), glm::vec2(0.5f, 1.0f)),
};
Mesh mesh(vertices, sizeof(vertices)/sizeof(vertices[0]));
Shader shader("./shaders/shader");
Texture texture("./textures/container.jpg");
while (!display.IsClosed())
{
display.ProcessInput();
display.Clear(0.0f, 0.15f, 0.3f, 1.0f);
texture.Bind(0);
shader.Bind();
mesh.Draw();
display.Update();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
texture.cxx
#include "texture.h"
Texture::Texture(const std::string &filePath)
{
int width, height, numComponents; …Run Code Online (Sandbox Code Playgroud)