SDL fails to display image?How to load JPG/PNG Textures in an SDL/OpenGL App under OSXDisplaying an .bmp image in C++/SDL2SDL2 empty transparent window in LinuxC++ Error: expected ')' in the middle of learning SDLSDL - not loading an imageImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionSDL image does not displayDisplaying a moving object in sdlWhat is an SDL renderer?SDL2 Invalid renderer on SDL_GetWindowSurface and/or SDL_CreateRenderer on OSXProblems displaying image in C++ with SDLc++ Transitioning from single source file to multiple files. error: 'blank' does not name a typeSDL won't display images after structure wrapped
How do certain apps show new notifications when internet access is restricted to them?
Make 2019 with single digits
Unable to find solution to 6 simultaneous equations
Would it be unbalanced to increase a druid's number of uses of Wild Shape based on level?
Some Prime Peerage
Work done by spring force
Importance of the current postdoc advisor's letter in TT job search
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
What organs or modifications would be needed for a life biological creature not to require sleep?
Why is it called a stateful and a stateless firewall?
geschafft or geschaffen? which one is past participle of schaffen?
Does a large scratch in an ND filter affect image quality?
Asked to Not Use Transactions and to Use A Workaround to Simulate One
Test to know when to use GLM over Linear Regression?
Why are some files not movable on Windows 10?
How to create an animated flowchart with LaTeX?
Examples of proofs by making reduction to a finite set
Bash awk command with quotes
Other than good shoes and a stick, what are some ways to preserve your knees on long hikes?
In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?
Why is the car dealer insisting on a loan instead of cash?
International Orange?
Assign every word from a line to a variable
Why don't Wizards use wrist straps to protect against disarming charms?
SDL fails to display image?
How to load JPG/PNG Textures in an SDL/OpenGL App under OSXDisplaying an .bmp image in C++/SDL2SDL2 empty transparent window in LinuxC++ Error: expected ')' in the middle of learning SDLSDL - not loading an imageImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionSDL image does not displayDisplaying a moving object in sdlWhat is an SDL renderer?SDL2 Invalid renderer on SDL_GetWindowSurface and/or SDL_CreateRenderer on OSXProblems displaying image in C++ with SDLc++ Transitioning from single source file to multiple files. error: 'blank' does not name a typeSDL won't display images after structure wrapped
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
My code doesn't display anything. All I get is a window with no image.
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
using namespace std;
SDL_Window *gWindow=NULL;
SDL_Surface *gScreenSurface=NULL;
SDL_Surface *gHelloWorld=NULL;
const int SCREEN_WIDTH=640, SCREEN_HEIGHT=480;
bool init()
bool success = true;
if(SDL_Init (SDL_INIT_VIDEO) < 0 )
printf("SDL could not initialize! SDL_Error : %s n", SDL_GetError() );
success=false;
else
gWindow = SDL_CreateWindow ( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
printf( "Window could not be created! SDL_Error: %sn", SDL_GetError() );
success=false;
else
gScreenSurface = SDL_GetWindowSurface (gWindow);
return success;
bool loadMedia()
bool success=true;
gHelloWorld = SDL_LoadBMP ( "hello_world.bmp" );
if (gHelloWorld == NULL )
printf( "Unable to load image %s! SDL Error: %sn", "hello_world.bmp", SDL_GetError() );
success=false;
return success;
void close()
SDL_FreeSurface( gHelloWorld );
gHelloWorld=NULL;
SDL_DestroyWindow( gWindow );
gWindow=NULL;
SDL_Quit();
int main(int argc, char* args[]){
if(!init())
printf( "failed to initialize!n" );
else
if( !loadMedia() )
printf ("failed to laod media! n");
else
SDL_BlitSurface( gHelloWorld, NULL, SDL_GetWindowSurface(gWindow), NULL );
SDL_UpdateWindowSurface ( gWindow );
SDL_Delay (2000);
close();
I expect it to show me a bmp image which is in the path specified here in the loadBMP()
function but all I get is an empty transparent window.
I am using KDE Konsole, if that has to do something with this.
c++ linux sdl
|
show 11 more comments
My code doesn't display anything. All I get is a window with no image.
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
using namespace std;
SDL_Window *gWindow=NULL;
SDL_Surface *gScreenSurface=NULL;
SDL_Surface *gHelloWorld=NULL;
const int SCREEN_WIDTH=640, SCREEN_HEIGHT=480;
bool init()
bool success = true;
if(SDL_Init (SDL_INIT_VIDEO) < 0 )
printf("SDL could not initialize! SDL_Error : %s n", SDL_GetError() );
success=false;
else
gWindow = SDL_CreateWindow ( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
printf( "Window could not be created! SDL_Error: %sn", SDL_GetError() );
success=false;
else
gScreenSurface = SDL_GetWindowSurface (gWindow);
return success;
bool loadMedia()
bool success=true;
gHelloWorld = SDL_LoadBMP ( "hello_world.bmp" );
if (gHelloWorld == NULL )
printf( "Unable to load image %s! SDL Error: %sn", "hello_world.bmp", SDL_GetError() );
success=false;
return success;
void close()
SDL_FreeSurface( gHelloWorld );
gHelloWorld=NULL;
SDL_DestroyWindow( gWindow );
gWindow=NULL;
SDL_Quit();
int main(int argc, char* args[]){
if(!init())
printf( "failed to initialize!n" );
else
if( !loadMedia() )
printf ("failed to laod media! n");
else
SDL_BlitSurface( gHelloWorld, NULL, SDL_GetWindowSurface(gWindow), NULL );
SDL_UpdateWindowSurface ( gWindow );
SDL_Delay (2000);
close();
I expect it to show me a bmp image which is in the path specified here in the loadBMP()
function but all I get is an empty transparent window.
I am using KDE Konsole, if that has to do something with this.
c++ linux sdl
Do you get your"Unable to load image %s! SDL Error: %sn"
error message on console?
– Scheff
Mar 28 at 12:16
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled withclang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?
– David Vereb
Mar 28 at 12:29
1
I cannot imagine thatg++
vs.clang++
has an effect on this... ;-)
– Scheff
Mar 28 at 12:35
1
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
1
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declareclose()
asextern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.
– genpfault
Mar 29 at 13:43
|
show 11 more comments
My code doesn't display anything. All I get is a window with no image.
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
using namespace std;
SDL_Window *gWindow=NULL;
SDL_Surface *gScreenSurface=NULL;
SDL_Surface *gHelloWorld=NULL;
const int SCREEN_WIDTH=640, SCREEN_HEIGHT=480;
bool init()
bool success = true;
if(SDL_Init (SDL_INIT_VIDEO) < 0 )
printf("SDL could not initialize! SDL_Error : %s n", SDL_GetError() );
success=false;
else
gWindow = SDL_CreateWindow ( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
printf( "Window could not be created! SDL_Error: %sn", SDL_GetError() );
success=false;
else
gScreenSurface = SDL_GetWindowSurface (gWindow);
return success;
bool loadMedia()
bool success=true;
gHelloWorld = SDL_LoadBMP ( "hello_world.bmp" );
if (gHelloWorld == NULL )
printf( "Unable to load image %s! SDL Error: %sn", "hello_world.bmp", SDL_GetError() );
success=false;
return success;
void close()
SDL_FreeSurface( gHelloWorld );
gHelloWorld=NULL;
SDL_DestroyWindow( gWindow );
gWindow=NULL;
SDL_Quit();
int main(int argc, char* args[]){
if(!init())
printf( "failed to initialize!n" );
else
if( !loadMedia() )
printf ("failed to laod media! n");
else
SDL_BlitSurface( gHelloWorld, NULL, SDL_GetWindowSurface(gWindow), NULL );
SDL_UpdateWindowSurface ( gWindow );
SDL_Delay (2000);
close();
I expect it to show me a bmp image which is in the path specified here in the loadBMP()
function but all I get is an empty transparent window.
I am using KDE Konsole, if that has to do something with this.
c++ linux sdl
My code doesn't display anything. All I get is a window with no image.
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
using namespace std;
SDL_Window *gWindow=NULL;
SDL_Surface *gScreenSurface=NULL;
SDL_Surface *gHelloWorld=NULL;
const int SCREEN_WIDTH=640, SCREEN_HEIGHT=480;
bool init()
bool success = true;
if(SDL_Init (SDL_INIT_VIDEO) < 0 )
printf("SDL could not initialize! SDL_Error : %s n", SDL_GetError() );
success=false;
else
gWindow = SDL_CreateWindow ( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
printf( "Window could not be created! SDL_Error: %sn", SDL_GetError() );
success=false;
else
gScreenSurface = SDL_GetWindowSurface (gWindow);
return success;
bool loadMedia()
bool success=true;
gHelloWorld = SDL_LoadBMP ( "hello_world.bmp" );
if (gHelloWorld == NULL )
printf( "Unable to load image %s! SDL Error: %sn", "hello_world.bmp", SDL_GetError() );
success=false;
return success;
void close()
SDL_FreeSurface( gHelloWorld );
gHelloWorld=NULL;
SDL_DestroyWindow( gWindow );
gWindow=NULL;
SDL_Quit();
int main(int argc, char* args[]){
if(!init())
printf( "failed to initialize!n" );
else
if( !loadMedia() )
printf ("failed to laod media! n");
else
SDL_BlitSurface( gHelloWorld, NULL, SDL_GetWindowSurface(gWindow), NULL );
SDL_UpdateWindowSurface ( gWindow );
SDL_Delay (2000);
close();
I expect it to show me a bmp image which is in the path specified here in the loadBMP()
function but all I get is an empty transparent window.
I am using KDE Konsole, if that has to do something with this.
c++ linux sdl
c++ linux sdl
edited Mar 28 at 17:43
genpfault
43.4k9 gold badges57 silver badges102 bronze badges
43.4k9 gold badges57 silver badges102 bronze badges
asked Mar 28 at 12:09
Deepak SharmaDeepak Sharma
41 bronze badge
41 bronze badge
Do you get your"Unable to load image %s! SDL Error: %sn"
error message on console?
– Scheff
Mar 28 at 12:16
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled withclang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?
– David Vereb
Mar 28 at 12:29
1
I cannot imagine thatg++
vs.clang++
has an effect on this... ;-)
– Scheff
Mar 28 at 12:35
1
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
1
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declareclose()
asextern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.
– genpfault
Mar 29 at 13:43
|
show 11 more comments
Do you get your"Unable to load image %s! SDL Error: %sn"
error message on console?
– Scheff
Mar 28 at 12:16
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled withclang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?
– David Vereb
Mar 28 at 12:29
1
I cannot imagine thatg++
vs.clang++
has an effect on this... ;-)
– Scheff
Mar 28 at 12:35
1
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
1
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declareclose()
asextern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.
– genpfault
Mar 29 at 13:43
Do you get your
"Unable to load image %s! SDL Error: %sn"
error message on console?– Scheff
Mar 28 at 12:16
Do you get your
"Unable to load image %s! SDL Error: %sn"
error message on console?– Scheff
Mar 28 at 12:16
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled with
clang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?– David Vereb
Mar 28 at 12:29
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled with
clang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?– David Vereb
Mar 28 at 12:29
1
1
I cannot imagine that
g++
vs. clang++
has an effect on this... ;-)– Scheff
Mar 28 at 12:35
I cannot imagine that
g++
vs. clang++
has an effect on this... ;-)– Scheff
Mar 28 at 12:35
1
1
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
1
1
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declare
close()
as extern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.– genpfault
Mar 29 at 13:43
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declare
close()
as extern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.– genpfault
Mar 29 at 13:43
|
show 11 more comments
1 Answer
1
active
oldest
votes
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397315%2fsdl-fails-to-display-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
add a comment
|
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
add a comment
|
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
edited Mar 28 at 19:53
answered Mar 28 at 17:47
genpfaultgenpfault
43.4k9 gold badges57 silver badges102 bronze badges
43.4k9 gold badges57 silver badges102 bronze badges
add a comment
|
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397315%2fsdl-fails-to-display-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you get your
"Unable to load image %s! SDL Error: %sn"
error message on console?– Scheff
Mar 28 at 12:16
Have you tried a different .bmp file? Your code worked fine for me after I installed sdl2 and compiled with
clang++ main.cpp `sdl2-config --libs`
. Also, I'm assuming your image is in the same directory as your executable?– David Vereb
Mar 28 at 12:29
1
I cannot imagine that
g++
vs.clang++
has an effect on this... ;-)– Scheff
Mar 28 at 12:35
1
You should have proper update loop and redraw when window manager asks you to (or just redraw unconditionally). Draw&delay is not a way to display things.
– keltar
Mar 28 at 18:55
1
@MiguelÁngelRetamozoSanchez: I think that's only an issue with C compilers or if you declare
close()
asextern "C"
so that C++ doesn't name-mangle it into the default file- or translation-unit-local anonymous namespace.– genpfault
Mar 29 at 13:43