i was following an online SDL tutorial linked here: https://lazyfoo.net/tutorials/SDL/ following the linux version with the g++ compiler.
at the end of the hello SDL course i compiled my program and nothing happened although it seemed to be doing something. i then downloaded the source files included and compiled and ran them too, which didn't open a new window or do anything it was supposed to like the program i made.
the source files are available here: https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php at the bottom of the page in a download link. and my exact code is:
/*This source code copyrighted by Lazy Foo' Productions 2004-2023
and may not be redistributed without written permission.*/
//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>
#include <iostream>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Hack to get window to stay up
SDL_Event e; bool quit = false; while( quit == false ){ while( SDL_PollEvent( &e ) ){ if( e.type == SDL_QUIT ) quit = true; } }
}
}
return 0;
}
My SDL2 was obtained through the apt package manager.
i compiled the program with this command:
g++ -Wall 01_hello_SDL.cpp -o game `sdl2-config --cflags --libs`
i am running debian 11 with a kernel version of 5.10.0-23-amd64.
I expected the executed c++ program to open a window or in fact do anything, which it did not.
I just used the provided source code from the tutorial website which still didn't open a window.
I am not very experienced with Linux or c++ so I have decided to learn both on a dedicated laptop running Debian.