• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

97 Neutral

About DashProject

  • Rank
  1. [font=Verdana, sans-serif]I am a beginner-to-intermediate C++ programmer in the process of teaching himself SDL, using a series of decent tutorials by Lazy Foo[/font][font=Verdana, sans-serif]. I got through the first lesson just fine, but then when I got to lesson two, "Optimized Surface Loading and Blitting[/font][font=Verdana, sans-serif]," a small amount of the terminologies started to confuse me, as some of it was over my head.[/font] [font=Verdana, sans-serif]The program is supposed to display a tiled background with a message in the center, delay for two seconds then quit. But when I went to run the program it compiled just fine, with no errors and no warnings, only it just exits as soon as it starts, and I don't see the images loaded or anything. I want to make it very clear that 'sdl.dll' [i]is[/i] in the program's directory, and so are the files 'img_bg.bmp' and 'img_message.bmp' so it's not a matter of missing files. [/font] [font=Verdana, sans-serif]My only theory as to why it's not displaying the images and waiting for 2000 milliseconds is because it ran into an error and one of the [i]return[/i][/font][font=Verdana, sans-serif] statements (see my code below,) and as such returned a one to exit the program. I don't know what else it could be, and I would love some help debugging my program.[/font] [font=Verdana, sans-serif][url="http://www.lazyfoo.net/SDL_tutorials/lesson02/index.php"]http://www.lazyfoo.n...son02/index.php[/url] - Here's the tutorial I was following[/font] [font=Verdana, sans-serif]My code is below, but it's rather tl;dr at the moment, so if you think you can help me without looking at the code, be my guest. I had to include the whole file because I don't know what line is causing the crash[/font] [font=Verdana, sans-serif][b]PROTIP:[/b] If you are going to be a sarcastic prick and tell me something like 'rtfm' or 'lrn 2 debug' then I will not appreciate it. Instead, say it nicely and I will gladly go out and research what I need to in order to solve my own problem, at is, if you are disgusted with a beginner who is utterly lost and does not know where to go next (even some pointers, not the programming kind, to what I can do next on my own would be most helpful) and prefer to take your disgust out on me, it will not be tolerated.[/font] [CODE] /***************************************** * OPTIMIZED SURFACE LOADING AND BLITTING * * by Nick Hagen * * 6/3/2012 * ****************************************** * * Followed Lazy Foo's SDL tutorial here: * http://www.lazyfoo.net/SDL_tutorials/lesson02/index.php * * Made with SDL 1.2.15 * and Code::Blocks 10.05 */ /// *** INIT SECTION ************************************ // Required headers #include "SDL/SDL.h" #include <string> /* 'string' included because Lazy Foo prefers 'string' to 'char' */ using namespace std; // Screen attributes, as global constants const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; /* In all of Lazy Foo's tutorials, 32 BPP will be used */ /* I can sorta see how putting these constants into functions would be preferably to typing '640' and '480' and '32' over and over again. */ // Now we're declaring all the surfaces we will be using SDL_Surface *message = NULL; // Foreground image SDL_Surface *background = NULL; // Background image SDL_Surface *screen = NULL; /* Wait...I thought declaring global variables was bad programming practice! I guess not in this case... */ /// *** FUNCTION DEFS *********************************** /* Apparently 'loadImage()' is already a taken function name. I will have to settle for calling it 'loadImages()' instead. Also, notice the asterisk. I think that means that the function 'loadImages()' returns a pointer to a variable of type 'SDL_Surface', but I could be wrong. Anyways onwards! */ /// -- loadImages() ------------------------------------- SDL_Surface *loadImages(string filename) { // The argument 'filename' will hold the path of the image to be loaded SDL_Surface* loadedImage = NULL; // This pointer stores the first loaded image SDL_Surface* optimizedImage = NULL; // This one is for the optimized image // Load the image (not QUITE sure about the '.c_str()' at the end of 'filename' loadedImage = SDL_LoadBMP(filename.c_str()); /* My guess is that the '.c_str()' appends a filetype which is a C-string to the end of the 'filename' string variable, but I could be mistaken. */ // If nothing went wrong in loading the image if(loadedImage != NULL) { // Create an optimized image optimizedImage = SDL_DisplayFormat(loadedImage); /* What 'SDL_DisplayFormat()' does is convert whatever BPP the loaded image was to the BPP of the screen, in this case 32 BPP. Otherwise if you don't convert the image's BPP when you load them here, SDL tries to convert on- the-fly, which costs you speed and processing power. This, it's a much better idea to convert images when you first load them.THAT is what 'optimize' means, by the way. */ SDL_FreeSurface(loadedImage); // Get rid of the old, non-32 BPP image from memory } // End 'if' statement return optimizedImage; // Return the new image, optimized at 32 BPP } // End function definition /// -- applySurface() ----------------------------------- void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination) { // Takes in the coordinates of where you want to blit the surface, what surface to blit, and what surface to blit to SDL_Rect offset; // 'SDL_Rect' is either a struct or a class. This instance will hold the offsets offset.x = x; offset.y = y; // Actually blit the surface SDL_BlitSurface(source, NULL, destination, &offset); /* The fourth argument holds the offsets to where on the destination the source is going to be applied. I'm not sure why it has a '&' in front of it though... */ } // End function definition /// *** MAIN FUNCTION *********************************** int main(int argc, char* args[]) { /// -- Initializations ------------------------------ /* Initialize all SDL subsystems (I guess putting it in an 'if' statement still works...) NOTES: SDL subsystems are things like the video, audio, timers, etc that are the individual engine components used to make a game. */ if( SDL_Init(SDL_INIT_EVERYTHING) == -1){ return 1; /* If SDL can't initialize, it returns -1. In this case we handle the error by returning 1, which will end the program */ } // End 'if' statement SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); // Set up the screen if(screen == NULL){ return 1;} //If there was an error in setting up the screen, end the program SDL_WM_SetCaption("Hello, world!", NULL); // Set the window caption /// -- Load and Apply ------------------------------- message = loadImages("img_hello.bmp"); background = loadImages("img_bg.bmp"); // Apply the background images! Tile them! applySurface(0, 0, background, screen); applySurface(320, 0, background, screen); applySurface(0, 240, background, screen); applySurface(320, 240, background, screen); // Apply the message image! applySurface(180, 140, message, screen); // Flip the buffers, and update the screen if(SDL_Flip(screen) == -1){ return 1;} // If there's an error then end the program SDL_Delay(2000); // Wait 2 seconds /// -- Finishing Up --------------------------------- SDL_FreeSurface(message); SDL_FreeSurface(background); SDL_Quit(); // Quit SDL return 0; // End of the program } [/CODE]
  2. Having trouble finding game engine to fit my needs

    [quote name='Serapth' timestamp='1318876650' post='4873574'] [quote name='DASH Project' timestamp='1318876371' post='4873573'] [quote name='Serapth' timestamp='1318875602' post='4873570'] [url="http://www.ogre3d.org"]Ogre3D[/url] + [url="http://www.ambiera.com/irrklang/features.html"]irrKlang[/url] [/quote] Wow quick reply! Hmm...Ogre 3D does 2D as well? Or perhaps do you mean use Ogre for my 3D bits and some other 2D engine for the rest? I'm not quite sure what you mean by this. But irrKlang looks amazing! Anyways, keep 'em coming, I'm sure other people may have some suggestions as well. [/quote] Well, any 3d engine can do 2d. In the case of OGRE [url="http://www.ogre3d.org/tikiwiki/SpriteManager2d&structure=Cookbook"]http://www.ogre3d.or...ucture=Cookbook[/url] [/quote] I dunno...using a full-fledged 3D engine just to do 2D seems kinda bloated imho...but if it's THE ONLY way then I guess I have no choice. Is there any other way?Are there any other 2D game engines that work with irrKlang?
  3. Having trouble finding game engine to fit my needs

    [quote name='Serapth' timestamp='1318875602' post='4873570'] [url="http://www.ogre3d.org"]Ogre3D[/url] + [url="http://www.ambiera.com/irrklang/features.html"]irrKlang[/url] [/quote] Wow quick reply! Hmm...Ogre 3D does 2D as well? Or perhaps do you mean use Ogre for my 3D bits and some other 2D engine for the rest? I'm not quite sure what you mean by this. But irrKlang looks amazing! I seem to recall SDL Mixer supporting module/tracker files as well, but that could be an older version that has since been discontinued. But please clarify on whether or not Ogre can do 2D stuff or not. I'd like more in-depth responses than just a couple of links, if that's not too difficult. Anyways, keep 'em coming, I'm sure other people may have some suggestions as well.
  4. Hey all, I've been looking for a game engine that supports the following things: [list][*]Sprite scaling and rotation[*]Alpha transparency channel[*]Rudimentary "vector" style 3D (flat-shaded or wireframe, like in old Amiga demos or the SNES's FX chip)[*]Tracker music format (*MOD, *XM, *IT, etc...this is [i]extremely[/i] crucial!)[*]Needs to be written in C or C++[*]Needs to be cross-platform (PC, Mac and Linux)[/list] I have not had much luck. I [i]did[/i] find Haaf's Game Engine, which supports tracker music as well as 2D scaling and rotation, but it's Windows-only as it uses DirectX. I found a lot of 2D game engines available, but not a whole lot of cross-platform ones written in C/C++, which is a shame because C is the language I have been teaching myself, on-and-off since early 2009, and I really want to write a game in that language. I cannot stress enough how [i]crucial[/i] it is that this game engine must support the tracker music format, preferably *IT (Impulse Tracker.) This is for several reasons. First-off, I intend to write some or all of the music for this game, and I am most comfortable composing music in Modplug tracker, using the *IT format because it gives me the most freedom and the least amount of technical limitations. Second, I want to be able to use code to speed up or slow down the tempo of the music, or switch between sections/patterns/parts of the song, which is easiest with a realtime-sequenced format like MIDI or tracker, as opposed to a prerendered format like *OGG or *MP3. Third, filesize is a bit of a constraint, as I want to challenge myself to see how small I can get the total size of the game and its assets. Finally and [b]most importantly[/b], I want my games to make a statement by using the more elegant (in my opinion) realtime-sequenced music like how older gamed from the 90s did, going against the grain of modern games, most of which seem to just use prerecorded *OGG, *WAV or *MP3 music, which to me seems bloated and inefficient, especially for retro-style 2D games. Finally, I can see how the retro "vector" style 3D might be a pain, as I'm not sure modern computers can even do 3D like that in the first place anymore. So I guess the 3D bit is optional, at least for now. Initially all these points might not seem that important, but bear in mind I intend to start working, with help from a commissioned programmer, on a rather ambitious 2D game project hopefully at the beginning of next year (which is around the time when I foresee being done with the design doc for it,) that will hopefully use all of the above features. I need to write the tech specs for this game in the design doc, including what engine the game will use, and having to resort to saying the game will use its own scratch-built engine just doesn't seem like a good idea, as it may scare away potential programmers. Plus in the meantime I want to use this engine to work on smaller game projects myself as practice. Does that make any sense? Thanks for reading, and sorry for the length of this post.
  • Advertisement