Sign in to follow this  

[SDL] Images wont display

This topic is 3110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
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 running

while(running)
{
// ...
}


You should include the error checking after the calls to SDL_LoadBMP but before the loop.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this