c++ - SDL_BlitSurface doesn't seem to work -


resolved brainsteel. code below fixed , works. window width: 640, window height: 480

the function calling order: start()

loop()

stop() (currently commented because if loop doesn't return 0 call stop before returning 1)

the structure:

#define max_images 50  struct imagestructure{     sdl_surface* texture;     int x;     int y; };  imagestructure image[max_images]; //all image textures set null default in start function sdl_event event; sdl_surface* screen = null; 

now start function. i've cleaned out setup code

int program::start(){     for(int id = 0; id < max_images; id++){         image[id].texture = null;         image[id].x = 0;         image[id].y = 0;     }      if(loadimg(1, 0, 0) != 0){         return 1;     }      if(printtext(2, "hello world", 10, 310) != 0){         return 2;     }      return 0; } 

the loop function. cleaned out event code

int program::loop(){     while(event.type != sdl_quit){          for(int id = 0; id < max_images; id++){             if(image[id].texture != null){                 if(showimg(id) != 0){                     return 1;                 }             }         }          if(sdl_flip(screen) == -1){             return 1;         }     } } 

the loadimg function

int program::loadimg(int id, int x, int y){     sdl_surface* loadedimage = null;     switch(id){         case 0:             loadedimage = img_load("textures\\icon.jpeg");             break;         case 1:             loadedimage = img_load("textures\\test.jpeg");             break;         default:             return 1;     }     if(loadedimage != null){         image[id].texture = sdl_displayformat(loadedimage);         image[id].x = x;         image[id].y = y;     }     else{         return 1;     }     sdl_freesurface(loadedimage);     return 0; } 

the showimg function

int program::showimg(int id){     sdl_rect position;     position.x = image[id].x;     position.y = image[id].y;     sdl_blitsurface(image[id].texture, null, screen, &position);     return 0; } 

and printtext function

int program::printtext(int id, std::string text, int x, int y){     ttf_font *font = null;     sdl_color textcolor = {255, 255, 255};     font = ttf_openfont("other\\poseiaoe.ttf", 22);     if(font == null){         return 1;     }     image[id].texture = ttf_rendertext_solid(font, text.c_str(), textcolor);     image[id].x = x;     image[id].y = y;     if(image[id].texture == null){         return 1;     }     return 0; } 


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -