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 不会复制数据,是吗?