LoadBMP SDL Issue - Help!

Trying to Load a BMP Image in SDL and running into an issue. The black screen loads and everything seems to be running correctly. However, I put debug code to show that the image is loading correctly, but I keep returning very strange values for the Width and Height? Can anyone help me with this? Here is an image of the output http://imgur.com/DfeRXI8 Nothing is drawn to the black screen as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
SDL_Surface* pTempSurface = SDL_LoadBMP("assets/rider.bmp");
	m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer,pTempSurface);
	SDL_FreeSurface(pTempSurface);
	SDL_QueryTexture(m_pTexture, NULL,NULL,&m_pSourceRect.w, &m_pSourceRect.h);
	//DEBUGXX
	std::cout << m_pSourceRect.w<<std::endl;
	std::cout <<m_pSourceRect.h<<std::endl;
	std::cout << m_pSourceRect.x<<std::endl;
	std::cout <<m_pSourceRect.y<<std::endl;

	m_pDestinationRect.x = m_pSourceRect.x = 0;
	m_pDestinationRect.y = m_pSourceRect.y = 0;
	m_pDestinationRect.w = m_pSourceRect.w;
	m_pDestinationRect.h = m_pSourceRect.h;

	std::cout << m_pDestinationRect.w<<std::endl;
	std::cout <<m_pDestinationRect.h<<std::endl;
	std::cout << m_pDestinationRect.x<<std::endl;
	std::cout <<m_pDestinationRect.y<<std::endl;

	int flags = 0;	
	if(fullScreen)
	{
		flags = SDL_WINDOW_FULLSCREEN;
	}
	if(SDL_Init(SDL_INIT_EVERYTHING) ==0)
	{
		std::cout << "SDL Init Success\n";
		m_pWindow = SDL_CreateWindow(title,xpos,ypos,width,height,flags);
		if(m_pWindow != 0)
		{
			std::cout << "Window creation success!\n";
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);

			if(m_pRenderer !=0)
			{
				std::cout <<  "renderer creation success\n";
				SDL_SetRenderDrawColor(m_pRenderer,0,0,0,255);

			}
			else
			{
				std::cout << "Renderer creation failed\n";
				return false;
			}
		}
		else
		{
			std::cout<< "SDL init fail\n";
			return false;
		}

	}
	else
	{
	std::cout << "SDL Init Fail\n";
	return false;
	}
	std::cout << "Init Success\n";
	m_bRunning = true;
	
	return true;
}
Narrowed down the issue to so:

1
2
3
4
5
6
7
8
9
	SDL_Surface* pTempSurface = SDL_LoadBMP("assets/test.bmp");
	m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer,pTempSurface);
	SDL_FreeSurface(pTempSurface);
	SDL_QueryTexture(m_pTexture, NULL,NULL,&m_pSourceRect.w, &m_pSourceRect.h);

	m_pDestinationRect.x = m_pSourceRect.x = 0;
	m_pDestinationRect.y = m_pSourceRect.y = 0;
	m_pDestinationRect.w = m_pSourceRect.w;
	m_pDestinationRect.h = m_pSourceRect.h;


No idea why its not pulling in the right values when I run SDL_QueryTexture
You can't do any graphic operations before you initialize the graphics.

You are attempting to load a texture on line 2... yet you don't initialize the graphics until line 26.
You are my hero, and I feel like an idiot.


Thanks so much!!!
Hey there!

I am not trying to be "that guy" but I just want to suggest that if your problem is solved, you should mark it with the button at the top of the post.
Thank you :)
Last edited on
Thanks for being that guy! New to the forum and will mark any problems solved going forward. Thanks for the help!
Topic archived. No new replies allowed.