• Displaying images in C++?
    28 replies, posted
Ok so, I'm no expert programmer here. Just beginning. I've learned how to use If/Else/While statements and some variable stuff. Something I want to do is display an image I have. The image is in .jpg format. I've googled around but haven't gotten a solid answer. It seems like I might have to download some third-party plugin that's used to display images. If this is true, what might you recommend? Preferably I want the image to be displayed in full resolution, in color. So yeah, how might I display an image on the screen?
The C++ standard library doesn't contain any window creation, rendering context, image loading, nothing like that. Your best bet is to use a library like SFML to create a window and render an image to it. Other libraries in the same fashion include SDL, but the image loading only supports .bmp without a plug-in.
Well, I downloaded the SFML for Code::Blocks and tried to install it, but it didn't work out right. I tried the code they gave me but it only came up with errors. I'm almost 100% positive I installed it right too.
If you post the errors, we can try to help you out.
Here's the build log: [quote] -------------- Build: Debug in test1 --------------- Compiling: main.cpp Linking console executable: bin\Debug\test1.exe obj\Debug\main.o: In function `main': C:/Documents and Settings/******/Desktop/test1/main.cpp:7: undefined reference to `sf::Clock::Clock()' C:/Documents and Settings/******/Desktop/test1/main.cpp:10: undefined reference to `sf::Clock::GetElapsedTime() const' C:/Documents and Settings/******/Desktop/test1/main.cpp:11: undefined reference to `sf::Sleep(float)' C:/Documents and Settings/******/Desktop/test1/main.cpp:8: undefined reference to `sf::Clock::GetElapsedTime() const' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 1 seconds) 4 errors, 0 warnings [/quote] This is the code it gives to try out: [quote] #include <SFML/System.hpp> #include <iostream> int main() { sf::Clock Clock; while (Clock.GetElapsedTime() < 5.f) { std::cout << Clock.GetElapsedTime() << std::endl; sf::Sleep(0.5f); } return 0; } [/quote]
You need to link in the SFML libraries you're using. [URL="http://www.sfml-dev.org/tutorials/1.2/start-cb.php"]Go down to 'Compiling your first SFML program' on this page.[/URL] Though learning SFML would be a [b]bad[/b] idea at the point you're at. Learn the basics, then work your way up to APIs.
Ok, I did that, and now it says it can't find the sfml-system.dll
You need to put it in the same directory as your .exe file or use the static libraries (append -s).
You really, really, [b]REALLY[/b] should learn the basics before learning an API. If you don't know the basics, you're going to run into a LOT of trouble, and probably frustrate yourself immensely.
[QUOTE=-SC-Lakitu;22245636]You really, really, [B]REALLY[/B] should learn the basics before learning an API. If you don't know the basics, you're going to run into a LOT of trouble, and probably frustrate yourself immensely.[/QUOTE] I am learning the basics. I just like to mess around a bit :3 [B]Edit:[/B] Thanks Overv, that worked!
[QUOTE=-SC-Lakitu;22245636]You really, really, [b]REALLY[/b] should learn the basics before learning an API. If you don't know the basics, you're going to run into a LOT of trouble, and probably frustrate yourself immensely.[/QUOTE] Don't bother. What i've found with these people is that they will [b]NOT[/b] listen to reason, even though you are trying to save them alot of time and frustration. Just let them get on with it, happy days.
[QUOTE=layla;22246698]Don't bother. What i've found with these people is that they will [B]NOT[/B] listen to reason, even though you are trying to save them alot of time and frustration.[/QUOTE] What the hell is that supposed to mean? I already said that I am learning the basics, and that I'm just messing around with stuff like this. That comment you made really wasn't needed, saying that people like me won't listen to reason.
Protip: If you're new then you instantly are subject to flaming by people who aren't new. Been there.
[QUOTE=Chad Mobile;22247062]Protip: If you're new then you instantly are subject to flaming by people who aren't new. Been there.[/QUOTE]That didn't happen to me. :colbert:
[QUOTE=Chad Mobile;22247062]Protip: If you're new then you instantly are subject to flaming by people who aren't new. Been there.[/QUOTE] No, if you're an idiot who can't follow simple instructions you are subject to flaming. There's nothing wrong with being new if you're actually willing to listen and learn.
See, he followed Overv's help and got success with what he needed and yet he was flamed. Please explain.
[QUOTE=Chad Mobile;22250229]See, he followed Overv's help and got success with what he needed and yet he was flamed. Please explain.[/QUOTE] The idea is learning to walk before you can run.
[QUOTE=Chad Mobile;22250229]See, he followed Overv's help and got success with what he needed and yet he was flamed. Please explain.[/QUOTE]Now, how far will OP get with SFML when OP doesn't even know classes and basic OOP? Have you used SFML?
[QUOTE=Chad Mobile;22250229]See, he followed Overv's help and got success with what he needed and yet he was flamed. Please explain.[/QUOTE] He was never flamed at all please understand what you're talking about before you talk about it.
Yep. [QUOTE=layla;22246698]Don't bother. What i've found with these people is that they will [B]NOT[/B] listen to reason, even though you are trying to save them alot of time and frustration. Just let them get on with it, happy days.[/QUOTE]
Chad, you're flamed because you can't stay on one project and make nothing interesting. Also you have a stupid avatar. Nobody was flamed in this thread.
Layla was a little condescending, but still no actual flaming.
[QUOTE=166291;22251300]Chad, you're flamed because you can't stay on one project and make nothing interesting. Also you have a stupid avatar. Nobody was flamed in this thread.[/QUOTE] 1.) I've been working on 3 projects for a total of about 3 months. I work on small little things in my extra time or when I'm buzzed out from the main projects. 2.) Yes, [I]I[/I] have a stupid avatar.
[QUOTE=Chad Mobile;22251129]Yep.[/QUOTE] That is not flaming, like I said please get a clue.
Are we talking native c++ or .NET? It's pretty easy to display images using .NET c++.
Just plain C++.
Nobody ever means ".NET C++" when they say C++. They would say C++/CLI.
It's all well and good helping someone with a problem like this but it's going to causes another 100 questions about general C++ that you should know before messing with an API. But yet again my opinion has ruined a thread. Just trying to save you some time here.
[QUOTE=layla;22256412]It's all well and good helping someone with a problem like this but it's going to causes another 100 questions about general C++ that you should know before messing with an API. But yet again my opinion has ruined a thread. Just trying to save you some time here.[/QUOTE] Unfortunately your opinion is something that should be followed because I highly doubt that slayer has any real experience behind the scenes with OOP or any advanced work with using classes.
Sorry, you need to Log In to post a reply to this thread.