Reputation: 65
I am trying to setup a SDL2 project on Eclipse on Mac.
I tried the following code and I have no errors reported. However, the window does not open but the icon of a "ghost" program that opens.
The "ghost" program:
#include <stdio.h>
#include <SDL2/SDL.h>
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Failed to initialize the SDL (%s)\n",SDL_GetError());
return -1;
}
{
SDL_Window* pWindow = NULL;
pWindow = SDL_CreateWindow("My first SDL2 application",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN);
if( pWindow )
{
SDL_Delay(3000);
SDL_DestroyWindow(pWindow);
}
else
{
fprintf(stderr,"Error creating the window: %s\n",SDL_GetError());
}
}
SDL_Quit();
return 0;
}
Upvotes: 1
Views: 212
Reputation: 8299
SDL overwrites the main but it expects main to be declared as
int main(int argc, char* argv[])
if you declare it as char** instead of char* argv[], the template will not be picked up.
The delay won't do very much: all you will get is a title and a frame. Change the SDL_Delay to an event handler like this
bool running = true;
while (running)
{
SDL_Event e;
while (SDL_PollEvent(&e) != 0)
{
if (e.type == SDL_QUIT)
{
running = false;
break;
}
}
}
You can then drag the window around. It will contain the the background.
Upvotes: 2