簡體   English   中英

OpenGL 紋理:如何創建圖像路徑?

[英]OpenGL Textures: how do I create an image path?

我一直試圖在這里上傳紋理:

// The FileSystem::getPath(...) is part of the GitHub repository so we can find files on any IDE/platform; replace it with your own image path.
    unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);

關於上面的評論,如何用我自己的圖片路徑替換它? 我試過這樣的事情:

unsigned char *data = stbi_load("Desktop/container.jpg").c_str(), &width, &height, &nrChannels, 0);

但它沒有用,當然,我的小腦袋現在超載了,我無法理清思路。 那么...如何指定圖像路徑?

更新:這是我收到的錯誤消息: 在此處輸入圖像描述

我找到了解決方法:確實如 Joshua 所說,“將文件移動到正確的項目目錄中,這樣相對路徑就可以工作了”。 所以在我的項目中,我創建了一個名為“Textures”的文件夾並在其中添加了紋理,我使用以下方法調用紋理:

unsigned char* data = stbi_load("Textures/container.jpg", &width, &height, &nrChannels, 0);

我想通過將 Joshua 的答案添加為正確答案來結束這篇文章,但我不知道該怎么做,所以我將添加這個,謝謝大家的幫助和見解

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM