我寫了一個簡單的應用程序,使用OpenGL,Assimp和Boost.GIL加載模型。使用Boost.GIL加載opengl紋理
我的模型包含PNG紋理。當我使用GIL加載它並通過OPENGL渲染時,我得到了錯誤的結果。感謝codeXL的powel,我發現我在OpenglGL中加載的紋理與圖像本身完全不同。
這是一個類似的問題,我遵循了它的步驟,但仍然有同樣的錯誤。
這裏是我的代碼:
// --------- image loading
std::experimental::filesystem::path path(pathstr);
gil::rgb8_image_t img;
if (path.extension() == ".jpg" || path.extension() == ".jpeg" || path.extension() == ".png")
{
if (path.extension() == ".png")
gil::png_read_and_convert_image(path.string(), img);
else
gil::jpeg_read_and_convert_image(path.string(), img);
_width = static_cast<int>(img.width());
_height = static_cast<int>(img.height());
typedef decltype(img)::value_type pixel;
auto srcView = gil::view(img);
//auto view = gil::interleaved_view(
// img.width(), img.height(), &*gil::view(img).pixels(), img.width() * sizeof pixel);
auto pixeldata = new pixel[_width * _height];
auto dstView = gil::interleaved_view(
img.width(), img.height(), pixeldata, img.width() * sizeof pixel);
gil::copy_pixels(srcView, dstView);
}
// ---------- texture loading
{
glBindTexture(GL_TEXTURE_2D, handle());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
image.width(), image.height(),
0, GL_RGB, GL_UNSIGNED_BYTE,
reinterpret_cast<const void*>(image.data()));
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
}
所有其他紋理這個模型也出錯了。
對我有幫助!!謝謝! – ChungkingExpress