SDL_BlitSurface function

For some reason xCode is not finding the SDL_BlitSurface(). I get a build error and the build fails. There must be some reason, I can't figure out what it is though.

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
64
65
#include <iostream>
#include <SDL2/SDL.h>
#include <stdio.h>
using namespace std;

//create constant variables
const int WINDOW_HEIGHT = 600;
const int WINDOW_WIDTH = 800;

//create window
SDL_Window* gWindow;
SDL_Surface* gSurface;
SDL_Surface* image;





int main(int argc, const char * argv[]) {
    
    // Initialize SDL
    if( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) {
        printf("SDL failed to initialize. Error: %s\n", SDL_GetError() );
    }
    else {
        cout << "Initialization successful.  Creating window. \n";
        gWindow = SDL_CreateWindow("Window for game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
        
        //Create window using gWindow and test for errors
        if(gWindow == NULL){
            printf("Could not create window. Error: %s\n", SDL_GetError());
        }
    }
    
    
    
    
    //assign surface to variable
    gSurface = SDL_GetWindowSurface(gWindow);
    
    image = SDL_LoadBMP("/Users/nicklag87/Downloads/02_getting_an_image_on_the_screen-2/hello_world.bmp");
    
    
    SDL_BlitSurface(image, NULL, gWindow, NULL);
    
    
    
    // I don't know what this does
    SDL_UpdateWindowSurface(gWindow);
    
    
    
    
    //Wait 5 seconds
    SDL_Delay(5000);
    
    
    //destroy window
    SDL_DestroyWindow(gWindow);
    
    
    // Quit SDL
    SDL_Quit();
    return 0;
}
Last edited on
That doesn't make sense. What's the exact error you're getting?
On line 44 I get an error saying "No matching function for call to 'SDL_UpperBlit'"

I have another project where SDL_BlitSurface() works just fine, it's weird...
Take a look at the documentation: https://wiki.libsdl.org/SDL_BlitSurface

SDL_BlitSurface draws one SDL_Surface onto another SDL_Surface. The third argument has to be a SDL_Surface. In your program the third argument is a SDL_Window.

I don't know for sure because I haven't used SDL2 much yet but maybe you find SDL_GetWindowSurface useful.

https://wiki.libsdl.org/SDL_GetWindowSurface
Last edited on
@Peter87

I used SDL_GetWindowSurface on line 39. Thank you for going through and figuring out I used the wrong arguments! That was the problem, the build succeeds now.
I used SDL_GetWindowSurface on line 39.

Oh... yes you are :D I didn't read the code carefully enough. So it was just a case of passing the wrong variable then.
Topic archived. No new replies allowed.