Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ glTexImage2D复制数据还是仅指定数据? InitTexture(){ 内部尺寸=600*600*4; 浮动文本[600*600*4]; glGenTextures(1和纹理); glBindTexture(GL_纹理_2D,纹理_); 对于(int i=0;i_C++_Opengl_Textures - Fatal编程技术网

C++ glTexImage2D复制数据还是仅指定数据? InitTexture(){ 内部尺寸=600*600*4; 浮动文本[600*600*4]; glGenTextures(1和纹理); glBindTexture(GL_纹理_2D,纹理_); 对于(int i=0;i

C++ glTexImage2D复制数据还是仅指定数据? InitTexture(){ 内部尺寸=600*600*4; 浮动文本[600*600*4]; glGenTextures(1和纹理); glBindTexture(GL_纹理_2D,纹理_); 对于(int i=0;i,c++,opengl,textures,C++,Opengl,Textures,使用此纹理初始化的应用程序失败 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 ] =

使用此纹理初始化的应用程序失败

  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;//全球的
浮动文本[600*600*4];//全球的
初始纹理(){
glGenTextures(1和纹理);
glBindTexture(GL_纹理_2D,纹理_);
对于(int i=0;i

但当文本数组是一个全局指针时,它就可以正常工作了。这是什么意思?glTexImage2D不会复制数据,是吗?

glTexImage2D总是复制数据。如果出现错误,那么除了源数据缓冲区的位置之外,还有其他原因。

您的问题是什么?您是否收到任何错误消息,表明出现了问题?通常,
glTexImage2D()
会将数据复制到视频卡。但如果有错误,那么可能没有。也许是纹理边长的问题。不是2的幂。试着把它设为2的幂,看看它是否有效。我把它设为1024x1024。同样的结果。@user14416:glGetError是一个奇怪的东西;只调用一次是不够的,因为错误会累积。必须调用GLGETRROR作为循环,直到返回GLGETRROR。此外,您不仅应该在执行OpenGL调用之后检查错误,还应该在执行之前检查错误,以确保您在干净的状态下操作。
 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 ..... " );
 }