glTexImage2D 和加载图像的问题
我正在使用 Corona(加载图像)/C++/Glut。
我在加载纹理时遇到奇怪的问题。我知道问题出在 glTexImage2D 上,但很奇怪,当图像为 850 x 249 或 850 x 251 或 850 x 252 时一切正常。但是当它是 850 x 250 时,我在编译后收到错误:
在 0x024bfee9 处出现未处理的异常 [...].exe:0xC0000005:访问 违规读取位置 0x0265c001。
我正在使用:
glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());
发生了什么事?
编辑
edit2 - 代码
加载纹理代码:
GLuint LoadTexture(char *_filename)
{
cout<<"loading image start"<<endl;
GLuint ttemp=0;
// Load texture
cout<<"1"<<endl;
corona::Image *TextureImage = corona::OpenImage(_filename);
cout<<"2"<<endl;
if (TextureImage)
{
glGenTextures(1, &ttemp);
glBindTexture(GL_TEXTURE_2D, ttemp);
// get the format of image
GLuint TextureFormat;
switch (TextureImage->getFormat())
{
case corona::PF_B8G8R8A8:
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8A8);
TextureFormat = GL_RGBA; break;
case corona::PF_R8G8B8A8:
TextureFormat = GL_RGBA; break;
case corona::PF_B8G8R8:
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
TextureFormat = GL_RGB; break;
case corona::PF_R8G8B8:
TextureFormat = GL_RGB; break;
case corona::PF_I8: // for example gif - convert to RGB
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
TextureFormat = GL_RGB; break;
}
// Flip image
FlipImage(TextureImage, corona::CA_X);
// Generate The Texture
cout<<"3"<<endl;
cout<<"-"<<endl;
cout<<"TextureFormat " <<TextureFormat<<endl;
cout<<"TextureImage->getWidth() " <<TextureImage->getWidth()<<endl;
cout<<"TextureImage->getHeight() " <<TextureImage->getHeight()<<endl;
cout<<"TextureImage->getPixels() " <<TextureImage->getPixels()<<endl;
cout<<"-"<<endl;
glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());
cout<<"4"<<endl;
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Linear Filtering
cout<<"5"<<endl;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
cout<<"6"<<endl;
delete TextureImage;
cout<<"7"<<endl;
}
cout<<"8"<<endl;
return ttemp;
}
我这样使用它:
GLuint texttest;
texttest= LoadTexture("test.png");
I'm using Corona (to load images) / C++ / Glut.
I have strange problem with loading texture. I know that problem is with glTexImage2D, but it's strange , everything is OK when image is 850 x 249 or 850 x 251 or 850 x 252. But when it's 850 x 250 I get an error after compiling :
Unhandled exception at 0x024bfee9 in
[...].exe: 0xC0000005: Access
violation reading location 0x0265c001.
I'm using :
glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());
What's going on ?
edit
edit2 - code
Loading texture code :
GLuint LoadTexture(char *_filename)
{
cout<<"loading image start"<<endl;
GLuint ttemp=0;
// Load texture
cout<<"1"<<endl;
corona::Image *TextureImage = corona::OpenImage(_filename);
cout<<"2"<<endl;
if (TextureImage)
{
glGenTextures(1, &ttemp);
glBindTexture(GL_TEXTURE_2D, ttemp);
// get the format of image
GLuint TextureFormat;
switch (TextureImage->getFormat())
{
case corona::PF_B8G8R8A8:
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8A8);
TextureFormat = GL_RGBA; break;
case corona::PF_R8G8B8A8:
TextureFormat = GL_RGBA; break;
case corona::PF_B8G8R8:
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
TextureFormat = GL_RGB; break;
case corona::PF_R8G8B8:
TextureFormat = GL_RGB; break;
case corona::PF_I8: // for example gif - convert to RGB
TextureImage = ConvertImage(TextureImage, corona::PF_R8G8B8);
TextureFormat = GL_RGB; break;
}
// Flip image
FlipImage(TextureImage, corona::CA_X);
// Generate The Texture
cout<<"3"<<endl;
cout<<"-"<<endl;
cout<<"TextureFormat " <<TextureFormat<<endl;
cout<<"TextureImage->getWidth() " <<TextureImage->getWidth()<<endl;
cout<<"TextureImage->getHeight() " <<TextureImage->getHeight()<<endl;
cout<<"TextureImage->getPixels() " <<TextureImage->getPixels()<<endl;
cout<<"-"<<endl;
glTexImage2D(GL_TEXTURE_2D, 0, TextureFormat, TextureImage->getWidth(), TextureImage->getHeight(), 0, TextureFormat, GL_UNSIGNED_BYTE, TextureImage->getPixels());
cout<<"4"<<endl;
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Linear Filtering
cout<<"5"<<endl;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
cout<<"6"<<endl;
delete TextureImage;
cout<<"7"<<endl;
}
cout<<"8"<<endl;
return ttemp;
}
I use it this way :
GLuint texttest;
texttest= LoadTexture("test.png");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论