Texture的原理
specify for each vertex that we have of our rectangle(顶点绘制情况) what area of the texture it should be and then the fragment shader will interpolate between that
即指定为每个顶点,rectangle(顶点绘制情况)区域的结构应该是什么,然后着色器将之间插入片段
Texture.cpp
#include "Texture.h"
#include "vendor/stb_image/stb_image.h"
Texture::Texture(const std::string& path)
:m_RendererID(0), m_FilePath(path), m_localBuffer(nullptr),
m_Width(0), m_Height(0), m_BPP(0)
{
stbi_set_flip_vertically_on_load(1);
m_localBuffer = stbi_load(path.c_str(), &m_Width, &m_Height, &m_BPP, 4);
GLCall(glGenTextures(1, &m_RendererID));
GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER/*minification filter, how our parameter resampled down*/, GL_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));//scale it up
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));//X GL_CLAMP
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));//Y
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_localBuffer));
GLCall(glBindTexture(GL_TEXTURE_2D, 0));
if (m_localBuffer)
stbi_image_free(m_localBuffer);
}
Texture::~Texture()
{
GLCall(glDeleteTextures(1, &m_RendererID));
}
void Texture::Bind(unsigned int slot /*= 0*/) const
{
GLCall(glActiveTexture(GL_TEXTURE0 + slot));
GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
}
void Texture::Unbind() const
{
GLCall(glBindTexture(GL_TEXTURE_2D, 0));
}
detail coming soon