Thread: Annoying SDL Problem
hi,
1 of sdl functions in "engine.cpp" spitting out error can't seem pinpoint. here's code.
engine.h
engine.cppcode:#ifndef engine_h #define engine_h #include "sdl/sdl.h" #include "sdl/sdl_image.h" #include "sdl/sdl_ttf.h" #include <iostream> #include <string> #include <vector> #include <map> using namespace std; class init { private: int win_width, win_height, win_bpp; //used setting window string win_caption; //the text goes in window caption int win_time; //the time window stays open ( dev purposes ) string file, handle; //the filename , image handle strings sdl_surface *nativeimage; // used loading image sdl_surface *optimizedimage; // used optimizing image string filename; // filename loadimage int xcoord, ycoord; // placesurface offsets sdl_surface *source; sdl_surface *destination; //for surface blitting public: sdl_surface *screen; // needs used outside of function init(); ~init(); void load( int win_width, int win_height, int win_bpp, string win_caption, int win_time ); sdl_surface *loadimage( string filename ); void placesurface( int xcoord, int ycoord, sdl_surface *source, sdl_surface* destination ); void quit(); }; #endif // engine_h
#include "engine.h"
code:/* constructor */ init::init() { int win_width = 640; int win_height = 480; int win_bpp = 32; string win_caption = "default caption"; int win_time = 3; sdl_surface *screen = null; string filename = " "; string handle = " "; sdl_surface *nativeimage = null; sdl_surface *optimizedimage = null; int xcoord = 0; int ycoord = 0; sdl_surface *source = null; sdl_surface *destination = null; } /* destructor */ init::~init() { } /* class functions */ void init::load( int win_width, int win_height, int win_bpp, string win_caption, int win_time ) { /* initialize subsystems */ if( sdl_init( sdl_init_everything < 0 ) ) { cerr << "failed initialize subsystems: ", sdl_geterror(); } /* set screen */ screen = sdl_setvideomode( win_width, win_height, win_bpp, sdl_swsurface ); /* make sure screen initialized */ if( screen == null ) { cerr << "failed load screen: ", sdl_geterror(); } /* set caption */ sdl_wm_setcaption( win_caption.c_str(), null ); /* convert win_time seconds milliseconds */ win_time *= 1000; /* wait win_time seconds */ sdl_delay( win_time ); } sdl_surface *loadimage( string filename ) { /* load image */ sdl_surface *nativeimage = img_load( filename.c_str() ); if( nativeimage != null ) { /* optimize image */ sdl_surface *optimizedimage = sdl_displayformat( nativeimage ); } else { cerr << "error loading image: " << sdl_geterror() << endl; } return optimizedimage; } void placesuface( int xcoord, int ycoord, sdl_surface *source, sdl_surface *destination ) { /* create rectangle */ sdl_rect surface; /* set */ surface.x = xcoord; surface.y = ycoord; /* blit surface screen */ sdl_blitsurface( source, null, destination, &surface); } void init::quit() { /* quit program (more added here later */ sdl_quit(); }and last not least, error:code:#include <iostream> #include "engine.h" int main( int argc, char** args ) { sdl_surface * image; /* create class objects */ init main_init; /* load object functions */ main_init.load( 640, 480, 32, "a test program", 3 ); image = main_init.loadimage( "image.png" ); main_init.placesurface( 0, 0, image, main_init.screen ); main_init.quit(); return 0; }
it seems think haven't declared "optimized image," though did in header in constructor...right ?code:g++ -o main main.cpp engine.cpp -lsdl -lsdl_image ~/programs/c++/syi-engine engine.cpp: in function ‘sdl_surface* loadimage(std::string)’: engine.cpp:68: error: ‘optimizedimage’ not declared in scopehave been mulling on 30 + minutes without success
.
.
-josh
hint: note word "scope".
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Annoying SDL Problem
Ubuntu
.
Comments
Post a Comment