InitTexture () {
int size = 600 * 600 * 4;
float text[ 600 * 600 * 4 ];
glGenTextures (1, &texture_);
glBindTexture (GL_TEXTURE_2D, texture_);
for (int i = 0 ; i < size ; ) {
text[ i ] = 0.5f;
text[ i + 1 ] = 0.0f;
text[ i + 2 ] = 0.0f;
text[ i + 3 ] = 1.0f;
i += 4;
}
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 600, 600, 0, GL_RGBA, GL_FLOAT, text
);
glBindTexture (GL_TEXTURE_2D, 0);
Renderable::IsGLError ("InitTexture: GL Error occured ..... ");
}
具有此紋理初始化的應用程序失敗。glTexImage2D複製數據或只是指定它?
int size = 600 * 600 * 4; // global
float text[ 600 * 600 * 4 ]; // global
InitTexture () {
glGenTextures (1, &texture_);
glBindTexture (GL_TEXTURE_2D, texture_);
for (int i = 0 ; i < size ; ) {
text[ i ] = 0.5f;
text[ i + 1 ] = 0.0f;
text[ i + 2 ] = 0.0f;
text[ i + 3 ] = 1.0f;
i += 4;
}
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 600, 600, 0, GL_RGBA, GL_FLOAT, text
);
glBindTexture (GL_TEXTURE_2D, 0);
Renderable::IsGLError ("InitTexture: GL Error occured ..... ");
}
但是,當文本數組是一個全局指針,它的工作原理應該如此。這是什麼意思? glTexImage2D不復制數據,是嗎?
你的問題是什麼?你是否收到任何錯誤信息,說有問題?通常情況下,'glTexImage2D()'會將數據複製到視頻卡上。但如果出現錯誤,那麼它可能不會。 – user1118321
也許這是你的紋理邊長。它不是2的冪。嘗試使它成爲2的冪,然後看它是否有效。 – TheAmateurProgrammer
我使它成爲1024 x 1024.結果相同。 – user14416