未初始化就使用SDL曲面错误
SDL Surface Being used without being initialised error
我使用SDL加载图像并将其分配给OpenGL quad。我找到了一个教程,向我展示了如何做到这一点,但是当我去运行程序时,它说SDL表面变量(代码中的表面)正在使用而没有初始化。我不知道这是不是因为我在使用类,因为我已经使用了我从其他语言的知识来找到一个解决方案,但没有运气。
下面是一些代码:实体类(到目前为止):
//d2_entity.h
class d2Entity
{
public:
bool LoadImage(const char* fileName);
void DrawImage();
void Clear();
private:
GLuint *texture;
GLenum textureFormat;
GLint noColours;
};
//d2_entity.cpp
bool d2Entity::LoadImageW(const char* fileName)
{
SDL_Surface *surface;
if((surface == IMG_Load(fileName)))
{
// Check if image size is a power of 2
if((surface->w & (surface->w - 1)) != 0)
cout << "Opps! '" << fileName << "'s' width is not a power of 2!";
if((surface->h & (surface->h -1)) != 0)
cout << "Opps! '" << fileName << "'s' height is not a power of 2!";
// Get the No. of channels
d2Entity::noColours = surface->format->BitsPerPixel;
// Contains a alpha channel
if(d2Entity::noColours == 4)
{
if(surface->format->Rmask == 0x000000ff)
d2Entity::textureFormat = GL_RGBA;
else
d2Entity::textureFormat = GL_BGRA;
}
// No alpha channel
else if(d2Entity::noColours == 3)
{
if(surface->format->Rmask == 0x000000ff)
d2Entity::textureFormat = GL_RGB;
else
d2Entity::textureFormat = GL_BGR;
}
else
cout << "Opps! The image '" << fileName << "' is not truecolour!" << endl;
// Create an OpenGL texture
glGenTextures(1, d2Entity::texture);
glBindTexture(GL_TEXTURE_2D, *d2Entity::texture);
// Set texture streching properties
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, d2Entity::noColours, surface->w, surface->h, 0, d2Entity::textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
}
else
{
cout << "Opps! The entity image could not be loaded!" << endl;
SDL_Quit();
return false;
}
if(surface)
SDL_FreeSurface(surface);
return true;
}
SDL_Surface *surface;
if((surface == IMG_Load(fileName)))
您从未初始化surface
,然后您试图将其与IMG_Load
的结果进行比较。我很确定你是想把它赋值。
SDL_Surface *surface;
if((surface = IMG_Load(fileName)))
您在这里进行了比较而不是赋值
if((surface == IMG_Load(fileName)))
{
代码应该是:
SDL_Surface surface;
surface = IMG_Load("image.bmp");
if(surface != NULL)
{
//do stuff with surface
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- SDL 窗口不会弹出
- SDL 操纵杆按钮按下/C++
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- OpenCascade:从 IGES 读取修剪曲面
- CGAL:如何创建填充边界曲线的曲面网格?
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 如何从 3D 曲面网格中删除自相交三角形?
- SDL 映像:无法打开映像,仅显示错误消息
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- "Undefined symbols for architecture x86_64" 在 SDL 2 (macOS) 中
- 为什么 SDL 在 Mac 上比 Linux 慢得多?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- SDL在析构函数上释放曲面失败
- 纹理的SDL Renderer参数,但曲面不需要
- C++/SDL:矢量/曲面问题
- SDL中由SDL_Rect向量分割曲面的问题
- 未初始化就使用SDL曲面错误
- 释放有效的SDL曲面会导致分段故障