2012-09-16 48 views
0
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不復制數據,是嗎?

+2

你的問題是什麼?你是否收到任何錯誤信息,說有問題?通常情況下,'glTexImage2D()'會將數據複製到視頻卡上。但如果出現錯誤,那麼它可能不會。 – user1118321

+0

也許這是你的紋理邊長。它不是2的冪。嘗試使它成爲2的冪,然後看它是否有效。 – TheAmateurProgrammer

+0

我使它成爲1024 x 1024.結果相同。 – user14416

回答

2

glTexImage2D總是複製數據。如果出現錯誤,那麼它有另一個原因,而不是源數據緩衝區的下落。

+0

我檢查glGetError(),沒有錯誤。 – user14416

+0

@ user14416:glGetError是一件奇怪的事情;僅僅調用一次就不夠,因爲錯誤會累積起來。你必須調用glGetError是一個循環,直到它返回的GL_NO_ERROR。此外,不僅要在執行OpenGL調用之後檢查錯誤,還要確保您在清理狀態下運行。 – datenwolf

相關問題