我有一个错误,我不知道如何解决。
我创建了一个简单的程序,使用VS2012,以测试SOIL(来自SOIL网站的示例代码):
#include "SOIL.h"
#include <iostream>
#include <glew.h>
#include <freeglut.h>
int main() {
std::cout << "Started" << std::endl;
/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture
(
"img.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
/* check for an error during the load process */
if( 0 == tex_2d )
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
}
我收到错误:
Unhandled exception at 0x585727FF (msvcr110d.dll) in imageLib.exe: 0xC0000005: Access violation reading location 0x00000000.
感谢任何帮助。谢谢。
答案 0 :(得分:0)
我所做的就是确保在使用GLuint之前加载GL,就像Necrolis建议的那样。
如果你的库加载正确,这个小例子应该运行没有错误(不显示任何内容,但显示GL和SOIL的顺序:
#include "SOIL.h"
#include <iostream>
#include <glew.h>
#include <freeglut.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
void LoadTexture() {
/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture
(
"Data/img.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
/* check for an error during the load process */
if( 0 == tex_2d )
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
int main(int argc, char** argv) {
std::cout << "Started" << std::endl;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 15");
glutSwapBuffers();
LoadTexture();
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutMainLoop();
return 0;
}
答案 1 :(得分:0)
我多次面对这些问题。我认为这是由于没有错误处理SOIL库引起的。
加载图像数据时,路径可能不正确。在我的情况下,我写的路径就像那种形式;
C:/Users/User/Pictures/texture.JPG
但是当我改变这条路径时,构建项目时没有错误;)
file:///C:/Users/User/Pictures/texture.JPG