SDL Help!

I've been learning SDL through a YouTube video series (CodingMadeEasy). I have a problem with the window and drawing things to it: When I make the window it shows up white and the console displays the error "Window creation failed!" but with no error, just blank. Then when I draw the bitmap to it nothing happens.

Whole code below:

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
#include <iostream>
#include <SDL.h>

int main(int argc, char *argv[])
{
	//Create objects
		SDL_Window *window = nullptr;
		SDL_Surface *windowSurface = nullptr;
		SDL_Surface *imageSurface = nullptr;

	//Initialise everything and display window
		if (SDL_Init(SDL_INIT_VIDEO) < 0)
		{
			std::cout << "SDL Failed to initialise!" << std::endl;
			std::cout << "Error code: " << SDL_GetError() << std::endl;
		}
		else
		{
			SDL_CreateWindow("No Name Yet", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
			if (window == NULL)
			{
				std::cout << "Window creation failed! " << std::endl;
				std::cout << "Error code: " << SDL_GetError() << std::endl;
			}
		}

	//Create surfaces
		windowSurface = SDL_GetWindowSurface(window);
		imageSurface = SDL_LoadBMP("TEU.bmp");
		
	//Check For errors
		if (imageSurface == NULL)
		{
			std::cout << "Error creating surface!" << std::endl;
			std::cout << "Error code: " << SDL_GetError() << std::endl;
		}
	//Draw
			SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
			SDL_Delay(10000);
	//Destroy and exit
		SDL_DestroyWindow(window);

		SDL_Quit();
		return 0;
}

assign window to SDL_CreateWindow() call. And btw try to use nullptr only, without NULL macro.
Sorry, I was just following the tutorial when it came to the NULL. May I ask what I would use instead? just nullptr?

Also it shows no error now, but it still doesn't show the bitmap?
Last edited on
HI there just a piece of advice:
use SFML not SDL. Here is why:
https://www.quora.com/Which-one-is-better-SDL-or-SFML

that is how to set up SFML: http://www.sfml-dev.org/tutorials/2.3/start-vc.php

and here is one nice tutorial: http://www.dreamincode.net/forums/topic/230524-c-tile-engine-from-scratch-part-1/

Note:
The tutorial has multiple errors, normally they are all resolved in the comments so look carefully
Last edited on
HI there just a piece of advice:
use SFML not SDL. Here is why:
https://www.quora.com/Which-one-is-better-SDL-or-SFML

"Use something else" because "link that gives no good reason" is hardly ever good advice.

OP: If you're using a version of SDL earlier than 2.0, use SDL_Flip after the blit. There are quite a few informative links if you bother to google.
Nanyo, I already know SFML and was looking to extend my knowledge.

Also I want to make something in 3d, which SFML can't do.
Sdl is for 2d games. If you want 3d you will probably just use opengl with sdl portable helper functions. Also you might want to check out that series: https://www.youtube.com/watch?v=FxCC9Ces1Yg.
well I'm an idiot :|

Thank's for the help
Topic archived. No new replies allowed.