3

I have a problem with SDL lib. I'm using VS2012 Ultimate and i was actually using this tutorial: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php to set everything and i did it step by step few times, but I still have problems this is my code, very simple:

#include <iostream> 
#include <SDL.h>

SDL_Surface * ekran = NULL;

int main (int argc, char *args [] )
{
   SDL_Init( SDL_INIT_EVERYTHING );
   ekran = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
   SDL_Flip( ekran );
   SDL_Delay( 2000 );
   SDL_Quit();
   return 0;
} 

and im having this errors:

error C3861: 'SDL_SetVideoMode': identifier not found
error C3861: 'SDL_Flip': identifier not found
3
  • What is your compile/link line? Feb 8, 2015 at 23:04
  • Which version of SDL are you using?
    – Kaslai
    Feb 9, 2015 at 0:46
  • 2
    I guess you installed SDL 2.0.3, the APIs in version 1 and 2 are very different. However, lazyfoo.net also provide guides about version 2.
    – cbel
    Feb 9, 2015 at 1:04

2 Answers 2

6

Here below is an example how to replace SDL_SetVideoMode() in SDL2. The old way to init SDL is commented and left along with the new way for comparison purposes. Basically, SDL2 creates a window with a title, then a surface attached to it, while SDL1 creates a surface alone and then calls the window manager to give it a name.

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "SDL video init failed: %s\n", SDL_GetError());
    return 1;
}

// SDL_Surface *screenSurface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);

SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;

window = SDL_CreateWindow("Sphere Rendering", 
    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
    SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

if (window == NULL) {
    fprintf(stderr, "Window could not be created: %s\n", SDL_GetError());
    return 1;
}

screenSurface = SDL_GetWindowSurface(window);

if (!screenSurface) {
    fprintf(stderr, "Screen surface could not be created: %s\n", SDL_GetError());
    SDL_Quit();
    return 1;
}

// SDL_WM_SetCaption("Sphere Rendering", NULL);
4

Take a look at that tutorial page again. Your code does not match it (e.g. SDL_SetVideoMode() no longer exists). Your code uses SDL 1.2 and the (updated) tutorial uses SDL 2.0. Are you using an old cached version of that page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.