c++ - cannot load multiple textures in SDL 2.0 -


i trying load multiple texture images in sdl app cannot load or render second image on screen. see grass.bmp being displayed. cannot load bob.bmp. have no idea error have implemented properly

my header file

#include <sdl.h> #include <sdl_image.h>  #ifndef gamewindow_h #define gamewindow_h  class gamewindow{ private:     bool _running;     sdl_window* _screen;     sdl_renderer* _renderer;     sdl_texture* _grasstexture;     sdl_texture* _bobtexture;     sdl_rect _grassrect;     sdl_rect _bobrect; ...... 

my .cpp file

void gamewindow::loadsprites(){     _grasstexture = img_loadtexture(_renderer,"grass.bmp");     _grassrect.x = 0;     _grassrect.y = 0;     _grassrect.w = 600;     _grassrect.h = 500;      _bobtexture = img_loadtexture(_renderer,"bob.bmp");     _bobrect.x = 150;     _bobrect.y = 150;     _bobrect.w = 80;     _bobrect.y = 50; } void gamewindow::initialize(){     if(sdl_init(sdl_init_everything) == -1)         _running = false; } void gamewindow::setupscreen(){     _screen = sdl_createwindow("my game window",                           100,                           100,                           640, 480,                           sdl_window_shown | sdl_window_resizable);      if(_screen == null){        _running = false;     }     _renderer = sdl_createrenderer(_screen,-1,sdl_renderer_accelerated);     gamewindow::loadsprites(); } void gamewindow::update(){  } void gamewindow::render(){     sdl_renderclear(_renderer);     sdl_rendercopy(_renderer,_bobtexture,null,&(_bobrect));     sdl_rendercopy(_renderer,_grasstexture,null,&(_grassrect));      sdl_renderpresent(_renderer); } 

all see grass.bmp. cannot render second image. image fine. tried debugging same grass.bmp in place of bob.bmp still not show. first image gets rendered , second not!! hope spot error. had no problems in sdl 1.2 after switching 2.0 creating whole lot of errors , confusion!!

ok, you've got 2 issues.

first. hard @ last line of _bobrect initialization. guess value _bobrect.h parameter have? (hint, it's 0 :)

_bobrect.x = 150; _bobrect.y = 150; _bobrect.w = 80; _bobrect.y = 50; 

second, since copy _grasstexture on top of _bobtexture , it's larger hide _bobtexture unless it's transparent. change order background gets copied first this

sdl_rendercopy(_renderer,_grasstexture,null,&(_grassrect)); sdl_rendercopy(_renderer,_bobtexture,null,&(_bobrect)); 

then should fine.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -