Image Display

Pages: 12
I learned some console application and win32, now I want to learn how to display an image. I don't know how to do it and what compiler to use. Can you please teach me step by step? Thanks.
Do you mean with WinAPI?

Is this on a Form/Dialog? Or do you have a normal window with a client area that you want to draw to?
Sorry, I don't understand what you're saying.
I just want to learn, no matter what it takes, to display an image using C++.
Disch is saying that your question is way, way, WAY to broad and evidently you don't quite understand that fact yet. That's OK, you'll get there. You said you've "Learned some win32" so let's build from there: http://msdn.microsoft.com/en-us/library/dd162487(v=vs.85).aspx
How you draw an image to a window depends on what kind of window you have.

Is your window a dialog like with pushbuttons?

Or is it a normal window with a blank canvas (kind of like notepad).

EDIT:

no matter what it takes, to display an image using C++.


Here's a full program using SFML to create a window, run a message loop, and display an onscreen image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    // Create a 640x480 window with "My Program" for the title that updates no faster than 60 FPS
    sf::RenderWindow window( sf::VideoMode(640,480), "My Program" );
    window.setFramerateLimit(60);

    // Load our image into a texture
    sf::Texture texture;
    texture.loadFromFile("splashscreen.png");       // load an image file

    // Put our texture in a 'Sprite' -- an on-screen entity
    sf::Sprite sprite(texture);

    // Run the program loop
    bool running = true;
    while(running)
    {
        // Process incoming messages/events
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed) // does the user want to close the program?
                running = false;                // if yes, indicate we want the program loop to stop

            // we don't care about other events for now
        }

        // Now, we update the screen
        window.clear();         // first, clear whatever is on it
        window.draw(sprite);    // then draw our sprite
        window.display();       // then display everything we have drawn
    }
}

Last edited on
Hi, sorry, my account got reported and I can't use it anymore. I'm still Richard 4234.
Do you have to download the library?
For SFML? Yes.
Just to help you - I spent weeks trying to display an image. Then, last night, I used Qt and did it in several seconds. I advise you to do the same. It is cross platform. And I tried to use SFML, and I couldn't get it to work without any unhandled exceptions. If you want to use Win32 or SFML.... good luck. I sure needed luck...
And I tried to use SFML, and I couldn't get it to work without any unhandled exceptions.


Sounds like you were using the wrong libs. Did you post a thread about it?


But yeah... QT is another lib you can use.
Disch wrote
Sounds like you were using the wrong libs. Did you post a thread about it?


Actually, yes. Several. The people on the SFML forums were useless and just said "This is on the wrong subforum" or "Do more searching".

Finally, I got it to work, using some random youtube vid. But, if I try to use any other stuff other than a basic window, I get an unhandled exception. I quit with it really... But, that is irrelevant, so... moving on.

Qt isn't my go to for game developing (nothing is now, really. In fact I just use Unity), and SFML is from what I've heard ideal for it, but for game devving I am gonna just learn DirectX or OpenGL... probably OpenGL.

As for regular GUI stuff, Qt == Amazing
Actually, yes. Several. The people on the SFML forums were useless and just said "This is on the wrong subforum" or "Do more searching".


Yeah the SFML forums seem pretty lame. Did you post anything here?

Finally, I got it to work, using some random youtube vid. But, if I try to use any other stuff other than a basic window, I get an unhandled exception


Doesn't sound like you got it to work to me. =P

As for regular GUI stuff, Qt == Amazing


I've never actually tried Qt... but I've used wx. It's pretty good. Does Qt require you to use a custom IDE? I heard that from somewhere and I don't know if it's true or not. It always scared me away from it.
Yeah the SFML forums seem pretty lame. Did you post anything here?

Yes, here is the link: http://www.cplusplus.com/forum/lounge/136211/
I did get good advice, but not necessarily a solution. I archived it since it hadn't been any activity on it for a week and a half.

Doesn't sound like you got it to work to me. =P

Well... half working.... 1/4 working... not really. I can just get it to build, not run, is what I meant

I've never actually tried Qt... but I've used wx. It's pretty good. Does Qt require you to use a custom IDE? I heard that from somewhere and I don't know if it's true or not. It always scared me away from it.

No it doesn't. Most people use it just to avoid having to go through the troubles of linking it to a project, but no. I don't like it, only because you can't go into the project file path and run the .exe from there without doing a bunch of stuff. There is a library for it to link to Visual Studio and other IDEs, just like SFML or SDL. I plan on downloading that tonight, actually.
Can you give me the link to download it?
You must download the library
I know that, I need the link to download it.
So you reported him? lol.

I don't mean to be a dick or anything but if you are trying to download a library the best place to look at would be the libraries site. http://lmgtfy.com/?q=sfml

http://sfml-dev.org/download/sfml/2.1/

By the way if you are having a hard time setting it up the tutorials are pretty nice. http://sfml-dev.org/tutorials/2.1/#getting-started --Getting Started w.e IDE you use.
Last edited on
Which one do I download?
That is impossible to say without knowing which operating system and which compiler you are using. Though they are pretty descriptive tbh.
Pages: 12