Jump to content

  • Log In with Google      Sign In   
  • Create Account


Krishath

Member Since 02 Dec 2011
Offline Last Active Jul 25 2012 01:40 PM
-----

Posts I've Made

In Topic: Let's have a good POV..

25 July 2012 - 07:12 AM

Thanks :-)

In Topic: Let's have a good POV..

25 July 2012 - 04:29 AM

Hmmm so should I pick that book?

In Topic: Let's have a good POV..

24 July 2012 - 12:46 PM

The book Game Coding Complete is a good book for describing the overall strucutre and systems involved in a game. I've not got this latest edition, but the Second edition is very good.

So it's theory + practice at the same time? I already program so I do not really need a C++ guide (Even if I program in C, but with some web searching I'd the trick). Can I spend my 40 € without burning in anger later? :-P

In other words: being a total beginner in these area, will the book guide me through all the learning course? (basic features + advanced ones)

In Topic: First steps...

24 July 2012 - 10:22 AM

Solved this too!

In Topic: First steps...

24 July 2012 - 10:08 AM

Your image is most likely not getting loaded.

SDL_Surface * load_image ( std::string filename )
{
	SDL_Surface * loadedImage = NULL;
	SDL_Surface * optimizedImage = NULL;
	loadedImage = SDL_LoadBMP(filename.c_str());
	if (loadedImage)
	{
			optimizedImage = SDL_DisplayFormat(loadedImage);
			SDL_FreeSurface(loadedImage);
	}
	return optimizedImage;
}

If your if statement is false you will return a null pointer.

Try this:
image = load_image("background.bmp");
if(image==NULL)std::cout<<"Failed to load image";

If that message is printed you need to fix the search path for your image.

No the problem was caused by those damned parenthesis..

Got another problem though. I've installed the SDL_image library BUT it cannot load my image... (tried to make it print errors in the "loading" function and it doesn't pop up any error).

It always return -2.

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
SDL_Surface * screen = NULL;
SDL_Surface * dots = NULL;
SDL_Event event;
SDL_Rect clip[4];

bool init()
{
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
	    return false;
    if ((screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE)) == NULL)
	    return false;
    SDL_WM_SetCaption("LOL", NULL);
    return true;
}
SDL_Surface * load_image ( std::string filename )
{
    SDL_Surface * loadedImage = NULL;
    SDL_Surface * optimizedImage = NULL;
    loadedImage = IMG_Load(filename.c_str());
    if (loadedImage)
    {
	    optimizedImage = SDL_DisplayFormat(loadedImage);
	    SDL_FreeSurface(loadedImage);
    }
    return optimizedImage;
}
void apply_surface (int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip = NULL)
{
    SDL_Rect offset;
    offset.x = x;
    offset.y = y;
    SDL_BlitSurface(source, clip, destination, &offset);
}
void clean_up (SDL_Surface * dots)
{
    SDL_FreeSurface(dots);
    SDL_Quit();
}
int main (int argc, char * argv[])
{
    bool quit = false;
    clip[0].x = 0;
    clip[0].y = 0;
    clip[0].w = 100;
    clip[0].h = 100;
    clip[1].x = 100;
    clip[1].y = 0;
    clip[1].w = 100;
    clip[1].h = 100;
    clip[2].x = 0;
    clip[2].y = 100;
    clip[2].w = 100;
    clip[2].h = 100;
    clip[3].x = 100;
    clip[3].y = 100;
    clip[3].w = 100;
    clip[3].h = 100;
    if (!init())
	    return 1;
    dots = load_image("dots.png");
    if (!dots)
	    return -2;
    SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
    apply_surface(0, 0, dots, screen, &clip[0]);
    SDL_Flip(screen);
    while (!quit)
	    while (SDL_PollEvent(&event))
		    if (event.type == SDL_QUIT)
			    quit = true;
    clean_up(dots);
    return 0;
}

PARTNERS