gpt4 book ai didi

cocoa - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER, 0);抛出 GL_INVALID_ENUM?

转载 作者:行者123 更新时间:2023-12-03 17:28:55 24 4
gpt4 key购买 nike

我正在从 NSImage( cocoa 桌面)创建 2D openGL 纹理。我从互联网上获取了一些代码,它似乎可以工作。

但是,我开始到处插入对 glGetError() 的调用来跟踪其他渲染错误,因此我跟踪了上述调用的 GL_INVALID_ENUM 错误。根据 glTexParameteri 的文档,GL_TEXTURE_2D 和 GL_TEXTURE_BORDER 似乎都是有效参数...?

有什么线索吗?

这是代码:

- (void) createOpenGLTexture
{
[_openGLContext makeCurrentContext];


if (_textureID != 0) {
glDeleteTextures(1, &_textureID);
_textureID = 0;
}

NSSize imageSize = [_originalImage size];


// .............................................................
// Flip Image Vertically

NSImage* image = [[NSImage alloc] initWithSize:imageSize];


NSRect rect = NSMakeRect(0, 0, imageSize.width, imageSize.height);

[image lockFocus];

NSAffineTransform* transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:rect.size.height];
[transform scaleXBy:+1.0 yBy:-1.0];
[transform concat];
[_originalImage drawAtPoint:NSZeroPoint
fromRect:rect
operation:NSCompositeCopy
fraction:1];
[image unlockFocus];


// Then we grab the raw bitmap data from the NSBitmapImageRep that is
// the ‘source’ of an NSImage

NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]];
[image release];


GLenum imageFormat = GL_RGBA;

imageSize = [bitmap size]; // Needed?

long sourceRowBytes = [bitmap bytesPerRow];

// This SHOULD be enough but nope
GLubyte* sourcePic = (GLubyte*) [bitmap bitmapData];

// We have to copy that raw data one row at a time….yay
GLubyte* pic = malloc( imageSize.height * sourceRowBytes );
GLuint i;
GLuint intHeight = (GLuint) (imageSize.height);

for (i = 0; i < imageSize.height; i++) {
memcpy(pic + (i * sourceRowBytes),
sourcePic + (( intHeight - i - 1 )*sourceRowBytes),
sourceRowBytes);
}

[bitmap release];

sourcePic = pic;


// .........................................................................
// Create the texture proper

glEnable(GL_TEXTURE_2D);
checkOpenGLError();

glEnable(GL_COLOR_MATERIAL);
checkOpenGLError();

glGenTextures (1, &_textureID);
checkOpenGLError();

glBindTexture (GL_TEXTURE_2D, _textureID);
checkOpenGLError();

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
checkOpenGLError();

// Here we set the basic properties such as how it looks when resized and if it's bordered
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER, 0);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
checkOpenGLError();

// Not really necessary all the time but we can also define if it can be tiled (repeating)
// Here GL_TEXTURE_WRAP_S = horizontal and GL_TEXTURE_WRAP_T = vertical
// This defaults to GL_REPEAT so we're going to prevent that by using GL_CLAMP
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
checkOpenGLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
checkOpenGLError();

// And.....CREATE
glTexImage2D(GL_TEXTURE_2D,
0,
imageFormat,
rect.size.width,
rect.size.height,
0,
imageFormat,
GL_UNSIGNED_BYTE,
sourcePic);
checkOpenGLError();

glDisable(GL_TEXTURE_2D);
checkOpenGLError();

glDisable(GL_COLOR_MATERIAL);

checkOpenGLError();
}

最佳答案

GL_TEXTURE_BORDER 不是 glTexParameter() 的有效枚举。引用:http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

您不能(也不需要)指定边框大小。 GL_TEXTURE_BORDER 只是 glGetTexLevelParameter() 的有效枚举,用于检索 opengl 驱动程序分配给特定纹理级别的边界大小。据我所知,该函数已不再使用,并且在所有较新的系统上都返回 0。

不要将它与 GL_TEXTURE_BORDER_COLOR 混淆,后者用于设置使用 GL_CLAMP_BORDER 环绕模式时渲染的颜色。

关于cocoa - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER, 0);抛出 GL_INVALID_ENUM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10207869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com