在尝试执行OpenGL SuperBible第5版的示例时,我遇到了很多问题。来自第09章/hdr_bloom。
问题是由链接OpenEXR库引起的,所以我已经手动构建了它们,并将它们替换为来自作者的libs。
现在,我可以设法运行程序,但当我尝试加载用作纹理的HDR图像时,会出现未处理的异常错误。
这是用于加载HDR纹理的代码的一部分,如果我将其全部注释掉,程序运行时没有问题,但我的对象上没有纹理。
bool LoadOpenEXRImage(char *fileName, GLint textureName, GLuint &texWidth, GLuint &texHeight)
{
// The OpenEXR uses exception handling to report errors or failures
// Do all work in a try block to catch any thrown exceptions.
try
{
Imf::Array2D<Imf::Rgba> pixels;
Imf::RgbaInputFile file(fileName); // UNHANDLED EXCEPTION
Imath::Box2i dw = file.dataWindow();
texWidth = dw.max.x - dw.min.x + 1;
texHeight = dw.max.y - dw.min.y + 1;
pixels.resizeErase(texHeight, texWidth);
file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * texWidth, 1, texWidth);
file.readPixels(dw.min.y, dw.max.y);
GLfloat* texels = (GLfloat*)malloc(texWidth * texHeight * 3 * sizeof(GLfloat));
GLfloat* pTex = texels;
// Copy OpenEXR into local buffer for loading into a texture
for (unsigned int v = 0; v < texHeight; v++)
{
for (unsigned int u = 0; u < texWidth; u++)
{
Imf::Rgba texel = pixels[texHeight - v - 1][u];
pTex[0] = texel.r;
pTex[1] = texel.g;
pTex[2] = texel.b;
pTex += 3;
}
}
// Bind texture, load image, set tex state
glBindTexture(GL_TEXTURE_2D, textureName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, texWidth, texHeight, 0, GL_RGB, GL_FLOAT, texels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
free(texels);
}
catch (Iex::BaseExc & e)
{
std::cerr << e.what() << std::endl;
//
// Handle exception.
//
}
return true;
}它的名称如下:
LoadOpenEXRImage("window.exr", windowTexture, texWidth, texHeight);请注意我的标记,它显示未处理异常的确切位置。
如果我试图运行它,就会得到以下错误:
0x77938E19 (ntdll.dll)处的未处理异常( hdr_bloom.exe: 0xC0000005:访问冲突写入位置0x00000014 )。
我的调试器指向以下代码:
virtual void __CLR_OR_THIS_CALL _Lock()
{ // lock file instead of stream buffer
if (_Myfile)
_CSTD _lock_file(_Myfile); // here
}它是fstream的一部分
我的声明如下:
#include <ImfRgbaFile.h> // OpenEXR headers
#include <ImfArray.h>
#ifdef _WIN32
#pragma comment (lib, "half.lib")
#pragma comment (lib, "Iex.lib")
#pragma comment (lib, "IlmImf.lib")
#pragma comment (lib, "IlmThread.lib")
#pragma comment (lib, "Imath.lib")
#pragma comment (lib, "zlib.lib")
#endif
#pragma warning( disable : 4244)我不知道这是否重要,但是当我第一次尝试运行它时,我得到了关于我的zlib.lib的SAFESEH错误,所以我在Linker->Advanced中关闭了SAFESEH。
作者提供的项目是在VisualStudio2008中创建的,在这里我使用了更新的版本,并在打开时对其进行了转换。
另外,我使用的是Windows 7 64位和2013终极版。
如果需要的话,让我知道,我会发布更详细的信息,我已经试着保持它尽可能短。
发布于 2015-01-01 17:25:29
我终于找到了这个问题,尽管我不知道它是如何发生的。
为了解决这个问题,我不得不创建一个全新的项目,只需复制原始项目中的所有内容,所以我的预测是,在原项目转换过程中的某个地方,一些项目属性发生了更改,这导致了一些错误。
我发现,这种转换的项目可能不允许在某些目录中写入或读取文件,这就是为什么我从fstream中得到了未处理的异常。
因此,对于有类似问题的未来人员,与其转换项目,不如创建一个全新的项目,只需复制您需要的内容,在我的示例中,我只需复制Library并包含目录:)。
https://stackoverflow.com/questions/27731622
复制相似问题