SDL 和 SDL_image 程序在 Eclipse 中什么都不做
SDL and SDL_image program doing nothing in Eclipse
我一直在尝试让 PNG 图像出现在我的 SDL window 的屏幕上。我正在使用 Eclipse CDT。 SDL.h 和 SDL_image.h 似乎都已正确链接,因为这些函数在编译器上弹出时带有颜色。但是,当我 运行 我的代码时,实际上什么也没有发生。编译器中没有错误,没有注释,什么都没有。 window 没有出现。如果有人能帮助我解决这个问题,我将不胜感激。
此外,SDL 之前曾在我的计算机上运行过(未使用 SDL_image)- 我在其中 运行 进行了完美运行的粒子模拟。
我的代码:
#include <iostream>
#include "SDL.h"
#include "SDL_image.h"
using namespace std;
SDL_Window *m_window; //Window upon which the game will be displayed.
SDL_Renderer *m_renderer; //Renderer used to draw the objects on the window.
SDL_Texture *playerTex;
int SCREEN_WIDTH = 600;
int SCREEN_HEIGHT = 600;
int main(int argc, char* args[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "Video init failed" << endl;
return 1;
}
//Creates the actual SDL-window and stores it in the m_window variable.
m_window = SDL_CreateWindow("Marko Beocanin SDD Project",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_FULLSCREEN);
//Error-checking method that determines if SDL could not create a window - returns false if unsuccessful.
if (m_window == NULL) {
cout << "Window Creation failed" << endl;
SDL_Quit();
IMG_Quit();
return 2;
}
//Creates an SDL-Renderer: a tool used to actually draw objects on the Window
m_renderer = SDL_CreateRenderer(m_window, -1, 0);
//Error-checking method that determines if SDL could not create a renderer - returns false if unsuccessful.
if (m_renderer == NULL) {
cout << "Renderer creation failed." << endl;
SDL_DestroyWindow(m_window);
SDL_Quit();
IMG_Quit();
return 3;
}
SDL_Surface *tmpSurface = IMG_Load("img.png");
playerTex = SDL_CreateTextureFromSurface(m_renderer, tmpSurface);
SDL_FreeSurface(tmpSurface);
SDL_RenderClear(m_renderer);
SDL_RenderCopy(m_renderer, playerTex, NULL, NULL);
SDL_RenderPresent(m_renderer);
SDL_Delay(2000);
SDL_DestroyWindow(m_window);
SDL_Quit();
IMG_Quit();
return 0;
}
我遇到的问题是因为我使用了错误的 SDL_image 库 - 我使用的是 x64 而不是 x86,这意味着它本身并没有抛出错误,只是不起作用适当地!
我一直在尝试让 PNG 图像出现在我的 SDL window 的屏幕上。我正在使用 Eclipse CDT。 SDL.h 和 SDL_image.h 似乎都已正确链接,因为这些函数在编译器上弹出时带有颜色。但是,当我 运行 我的代码时,实际上什么也没有发生。编译器中没有错误,没有注释,什么都没有。 window 没有出现。如果有人能帮助我解决这个问题,我将不胜感激。
此外,SDL 之前曾在我的计算机上运行过(未使用 SDL_image)- 我在其中 运行 进行了完美运行的粒子模拟。
我的代码:
#include <iostream>
#include "SDL.h"
#include "SDL_image.h"
using namespace std;
SDL_Window *m_window; //Window upon which the game will be displayed.
SDL_Renderer *m_renderer; //Renderer used to draw the objects on the window.
SDL_Texture *playerTex;
int SCREEN_WIDTH = 600;
int SCREEN_HEIGHT = 600;
int main(int argc, char* args[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "Video init failed" << endl;
return 1;
}
//Creates the actual SDL-window and stores it in the m_window variable.
m_window = SDL_CreateWindow("Marko Beocanin SDD Project",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_FULLSCREEN);
//Error-checking method that determines if SDL could not create a window - returns false if unsuccessful.
if (m_window == NULL) {
cout << "Window Creation failed" << endl;
SDL_Quit();
IMG_Quit();
return 2;
}
//Creates an SDL-Renderer: a tool used to actually draw objects on the Window
m_renderer = SDL_CreateRenderer(m_window, -1, 0);
//Error-checking method that determines if SDL could not create a renderer - returns false if unsuccessful.
if (m_renderer == NULL) {
cout << "Renderer creation failed." << endl;
SDL_DestroyWindow(m_window);
SDL_Quit();
IMG_Quit();
return 3;
}
SDL_Surface *tmpSurface = IMG_Load("img.png");
playerTex = SDL_CreateTextureFromSurface(m_renderer, tmpSurface);
SDL_FreeSurface(tmpSurface);
SDL_RenderClear(m_renderer);
SDL_RenderCopy(m_renderer, playerTex, NULL, NULL);
SDL_RenderPresent(m_renderer);
SDL_Delay(2000);
SDL_DestroyWindow(m_window);
SDL_Quit();
IMG_Quit();
return 0;
}
我遇到的问题是因为我使用了错误的 SDL_image 库 - 我使用的是 x64 而不是 x86,这意味着它本身并没有抛出错误,只是不起作用适当地!