[SDL] Images wont display

Started by
4 comments, last by DorianC 14 years, 10 months ago
alright im still working on this program and for some reason none of the images will load. i believe im using all of the correct functions please help. here is the code so far.
#include "stdafx.h"
#include "SDL.h"
#include <string>


int _tmain(int argc, _TCHAR* argv[])
{
	if(SDL_Init(SDL_INIT_VIDEO)<0)
	{
		printf("Unable to Initialize");
		return 1;
	}
	SDL_Surface* screen=SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
	if(!screen)
	{
		printf("Unable to set video to 800x600");
		return 1;
	}
	SDL_Surface* idle=NULL;
	SDL_Surface* crouch=NULL;
	
	bool running=true; // keeps the window running
	while(running)
	{
	idle=SDL_LoadBMP("stance.bmp");
	crouch=SDL_LoadBMP("crouch.bmp");

	int x, y, w, h;

	SDL_Rect SourceRct; // where i want it to start
	SourceRct.x=0;   SourceRct.y=0;
	SourceRct.w=89; SourceRct.h=49;

	SDL_Rect DestRct; // the destination i want it to go to
	DestRct.x=72;    DestRct.y=72;
	DestRct.w=89;   DestRct.h=49;
	
	if(SDLK_DOWN)// if the DOWN arrow is hit
	{
		SDL_BlitSurface(crouch, &SourceRct, screen, &DestRct);
	}
	
	}

	return 0;
}
Advertisement
Have you tried using the error description function SDL_GetError() to determine what the problem loading the images was?

Also, you should load your images once, outside the loop. Like this:
SDL_Surface* idle = SDL_LoadBMP("stance.bmp");SDL_Surface* crouch = SDL_LoadBMP("crouch.bmp");bool running = true; // keeps the window runningwhile(running){	// ...}

You should include the error checking after the calls to SDL_LoadBMP but before the loop.
Quote:Original post by rip-off
Have you tried using the error description function SDL_GetError() to determine what the problem loading the images was?

Also, you should load your images once, outside the loop. Like this:
*** Source Snippet Removed ***
You should include the error checking after the calls to SDL_LoadBMP but before the loop.


it doesnt return an error, but it still doesnt display the picture its just a big black screen. but thanks for the help.
You don't seem to be using SDL_Flip(screen). Try putting that at the end of your loop.

Also, SDLK_DOWN is a constant, not a variable that changes value when a key is hit. You either need a SDL_PollEvent() loop or to use SDL_GetKeyState() if you want to react to keypresses.
Add

SDL_Flip(screen);

after you blit the surface.
That should get your image on the screen.

Good luck!
YAY it worked thanks alot(Mr.Roboman and rip-off)

This topic is closed to new replies.

Advertisement