c++ - IMG_Load doesn't work -
i watching series = https://www.youtube.com/watch?v=2nvghrofneg , reason guy in video code works me compiles fine doesn't load image. don't know do.
#include "sdl.h" #include <iostream> #include "sdl_image.h" sdl_texture *loadtexture(std::string filepath, sdl_renderer *rendertarget) //texture optimization function { sdl_texture *texture = nullptr; sdl_surface *surface = img_load(filepath.c_str()); if (surface == null) std::cout << "error 1" << std::endl; else { texture = sdl_createtexturefromsurface(rendertarget, surface); if (texture == null) std::cout << "error 2" << std::endl; } sdl_freesurface(surface); return texture; } int main(int, char *argv[]) { const int fps = 144; int frametime = 0; sdl_window *window = nullptr; sdl_texture *currentimage= nullptr; sdl_renderer *rendertarget = nullptr; sdl_rect playerrect; int framewidth, frameheight; int texturewidth, textureheight; sdl_init(sdl_init_video ); int imgflags = img_init_png | img_init_jpg; if (!(img_init(imgflags) != imgflags)) { std::cout << "error: " << img_geterror() << std::endl; } window = sdl_createwindow("sdl pong", sdl_windowpos_centered, sdl_windowpos_centered, 1024, 720, sdl_window_shown); rendertarget = sdl_createrenderer(window, -1, sdl_renderer_accelerated | sdl_renderer_presentvsync); currentimage = loadtexture("untitled.jpg", rendertarget); sdl_querytexture(currentimage, null, null, &texturewidth, &textureheight); sdl_setrenderdrawcolor(rendertarget, 0xff, 0, 0, 0xff); framewidth = texturewidth / 3; frameheight = textureheight / 4; playerrect.x = playerrect.y = 0; playerrect.y = framewidth; playerrect.h = frameheight; bool isrunning = true; //game loop sdl_event ev; while (isrunning) { while (sdl_pollevent(&ev) != 0) { if (ev.type == sdl_quit) isrunning = false; } frametime++; if (fps / frametime == 4) { frametime = 0; playerrect.x += framewidth; if (playerrect.x >= texturewidth) playerrect.x =0; } sdl_renderclear(rendertarget); sdl_rendercopy(rendertarget, currentimage, &playerrect, null); sdl_renderpresent(rendertarget); } sdl_destroywindow(window); sdl_destroytexture(currentimage); sdl_destroyrenderer(rendertarget); window = nullptr; rendertarget = nullptr; currentimage = nullptr; sdl_quit(); return 0; }
this error message: http://imgur.com/lhmdt5f
(i don't have enough reputation comment on main post i'll post here:)
when downloading sdl_image, multiple .dll's (http://i.imgur.com/tt9yxuw.png).
since specific error, assume didn't drop libjpeg dll directory.
i'm sdl_image needs read particular filetypes.
Comments
Post a Comment