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 ..... " );
}
使用此纹理初始化的应用程序失败。
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不会复制数据,是吗?
答案 0 :(得分:2)
glTexImage2D始终复制数据。如果有错误,那么它有另一个原因而不是源数据缓冲区的下落。