SDL_2加载图像不起作用
SDL_2 load image not working
所以我最近下载了SDL_2库和所有组件,并希望创建一个简单的GUI/UI,其中包含一个带有图片的"按钮"。我查找了一些指南,也复制和重写了很多代码。但是我发现最新的代码示例是 C 语言,它不包含类并且非常混乱。所以我把它重写成C++但由于某种原因,它不想加载图像。
我故意没有发布任何析构函数或任何我 99% 确定不是导致问题的功能。对于帖子,为了不让它太长,我相信错误出在 const void clear 函数中,但我不确定。
有什么想法吗?长期以来一直在努力解决这个问题,感谢您的任何建议/帮助:)
窗口.h:
#pragma once
#include <SDL.h>
class Window
{
public:
Window(const char* title, int width, int height);
~Window();
void getEvents();
const void clear();
inline const bool isClosed() { return _closed; }
private:
const char* _title = "SDL_6";
int _width = 480;
int _height = 720;
bool _closed = false;
bool init();
SDL_Window *_window = nullptr;
SDL_Renderer *_renderer = nullptr;
SDL_Surface *_surface = nullptr;
};
窗口.cpp:
#include "Window.h"
#include <iostream>
#include <SDL_image.h>
#define IMG_PATH "D:\Picture\Bowser\star.jpg"
Window::Window(const char *title, int width, int height) :
_title(title), _width(width), _height(height)
{
_closed = !init();
}
const void Window::clear()
{
int w = 120;
int h = 120;
SDL_Texture *img = NULL;
SDL_Rect texr;
texr.x = 120;
texr.y = 120;
texr.h = 120;
texr.w = 120;
const char* file = "D:\Pictures\bowser\star.jpg";
SDL_Surface *IMG_Load(const char* file);
SDL_RenderClear(_renderer);
SDL_RenderCopy(_renderer, img, NULL, &texr);
img = IMG_LoadTexture(_renderer, IMG_PATH);
SDL_QueryTexture(img, NULL, NULL, &w, &h);
SDL_RenderPresent(_renderer);
}
主.cpp
#include "Window.h"
int main(int argc, char* argv[])
{
Window window("SDL_6", 720, 480);
while (!window.isClosed())
{
window.getEvents();
window.clear();
}
return 0;
}
所以答案是不声明:SDL_Surface IMG_Load(常量字符文件(;但要调用它,还更改了代码在: const void Window::clear(( 函数中的顺序。谢谢你的回答奥尼尔:-(
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- glTexImage2D 不起作用,但将 FragColor 设置为 vec4(1.0, 0, 0, 1.0) 会给我红色图像
- 与 alpha 通道的图像重叠在 QT 上不起作用
- SDL_2加载图像不起作用
- 使用16位签名格式打开CV不起作用..裁剪图像并重新调整图像大小
- 旋转图像不起作用
- 将opencv图像转换为gdi位图不起作用取决于图像大小
- 为什么我的 OpenCL 3D 图像查找不起作用?
- 使用VideoCapture读取目录中的图像不起作用
- 我的加载图像不起作用 - 我需要知道为什么
- 从资源加载图像不起作用(C++ Dll)