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

Is is possible to take a database offline when doing a backup using an sql job?

Contour integration with infinite poles

What is the logical distinction between “the same” and “equal to?”

How do I introduce dark themes?

Impossible violin chord, how to fix this?

Duck, duck, gone!

About non-FTL travel and realitivistic effect for a hard sci fi novel

Can a passenger predict that an airline is about to go bankrupt?

Why most footers have a background color has a divider of section?

How to prevent pickpocketing in busy bars?

Can I pay some of the cost of an activated ability lots of times to get more out of the effect?

How do my husband and I get over our fear of having another difficult baby?

A word that refers to saying something in an attempt to anger or embarrass someone into doing something that they don’t want to do?

Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?

What would happen if I build a half bath without permits?

How deep is the liquid in a half-full hemisphere?

Is determiner 'a' needed in "one would call such a value a constant"?

GPLv3 forces us to make code available, but to who?

Why, even after his imprisonment, do people keep calling Hannibal Lecter "Doctor"?

What are one's options when facing religious discrimination at the airport?

What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?

Avoiding dust scattering when you drill

Why is a road bike faster than a city bike with the same effort? How much faster it can be?

Speed and Velocity in Russian



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;








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.










share|improve this question


























  • 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() 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

















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.










share|improve this question


























  • 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() 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













0












0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 17:43









genpfault

43.4k9 gold badges57 silver badges103 bronze badges




43.4k9 gold badges57 silver badges103 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 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() 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

















  • 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() 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
















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












1 Answer
1






active

oldest

votes


















1
















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.






share|improve this answer





























    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
    );



    );














    draft saved

    draft discarded
















    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









    1
















    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.






    share|improve this answer































      1
















      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.






      share|improve this answer





























        1














        1










        1









        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 19:53

























        answered Mar 28 at 17:47









        genpfaultgenpfault

        43.4k9 gold badges57 silver badges103 bronze badges




        43.4k9 gold badges57 silver badges103 bronze badges

































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해