![](/img/trans.png)
[英]Error events when CreateProcess uses a path: E0167 argument of type "char *" is incompatible with parameter of type "LPWSTR"
[英]glDeleteTextures gives error E0167 (argument of type is incompatible with parameter of type)
我寫
glDeleteTextures(1, &LocalBuffer);
它說:
E0167 argument of type "unsigned char *" is incompatible with parameter of type "const GLuint *"
它是第 52 行。我嘗試過:將其作為LocalBuffer
傳遞
代碼:
class Texture {
private:
unsigned int TextID;
std::string FilePath;
unsigned char* LocalBuffer;
int Width, Height, BytesPixel;
public:
Texture(const std::string path)
: TextID(0), FilePath(path), LocalBuffer(nullptr), Width(0), Height(0), BytesPixel(0) {
glGenTextures(1, &TextID);
glBindTexture(GL_TEXTURE_2D, TextID);
stbi_set_flip_vertically_on_load(1);
LocalBuffer = stbi_load(path.c_str(), &Width, &Height, &BytesPixel, 4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, LocalBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
if (LocalBuffer) { //if localbuffer exists
stbi_image_free(LocalBuffer);
}
}
~Texture() {
glDeleteTextures(1, LocalBuffer);
}
void Bind(unsigned int slot = 0){
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, TextID);
}
void Unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
};
您刪除的是紋理名稱,而不是紋理數據。 具體來說,無論您使用glGenTextures
,您都必須稍后使用glDeleteTextures
。
glGenTextures(1, &TextID);
glDeleteTextures(1, &TexID);
我正要說您可以在上傳圖像數據以 DMA 傳輸到圖形卡 ( glTexImage2D
) 后立即釋放它,但您已經釋放了它。 所以事實上,如果代碼通過一些重新解釋轉換,你會得到訪問沖突。 甚至不要將LocalBuffer
存儲為類中的字段,這是沒有必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.