943,542 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1396
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
May 31st, 2009
0

The Jump from C++ Programming to Graphics?

Expand Post »
I'm rather uncertain as to how you go from making programs which churn values on the Dos screen to actual graphics. I'm not asking for a lesson on this, but I am confused as to how a c++ program creates/manipulates graphics. Is it all done through widgets or is there another method I haven't come across yet?

Thanks
Danny2000
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
danny2000 is offline Offline
25 posts
since Dec 2007
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

graphics are almost always done with specialized libraries in C++. These libraries, like opengl, directx, and sdl, have their own frameworks all completely designed toward graphics. You have to learn a lot about the library to use it well, but that's how games and other graphics stuff is made.
Reputation Points: 14
Solved Threads: 22
Junior Poster
JugglerDrummer is offline Offline
138 posts
since Apr 2009
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

Sounds like he was asking more about GUI type stuff rather than 3d graphics? In linux, there are a couple of main GUI libraries like QT and GTK. I'm not sure about windows. They usually have some kind of graphical designer that you can layout buttons and textboxes and whatnot, then they use some variation on the idea of "callbacks" - an event gets triggered when the user does something in the GUI and then you have to "handle" the event in the code.

Sorry, I don't know anything about windows GUIs in c++.

Good luck.

Dave
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

There is freeware Qt for Windows now (from April 2009). There are some other freeware GUI libs for Windows - as usually, they are portable too.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

The difference between the DOS command line and the GUI is due to alot of things.

If you are programming in windows, you would use the Windows Application Programming Interface (WinAPI).

The libraries and namespaces:
GUI programs dont use the std:: namespace, because that is designed for DOS output like cin and cout. Instead of including things like <iostream>, it is <windows.h>, <commctrl.h>.
The graphics are actually controls (widgets), that are defined by window, all you do is have to call CreateWindow() or CreateWindowEx(), and store the value from that in a HWND variable. like: HWND hwnd = CreateWindow(...blah blah blah...);

You can learn more about CreateWindowEx() at: http://msdn.microsoft.com/en-us/library/ms632680.aspx

There is actually alot more to it though, but once you get started it isnt too confusing.

Take for instance, Instead of int main(int arg, char arg[]), it is
int WINAPI WinMain

The proccess goes like:

Create all global variables and processes

WinMain
--->Register the window class
--->Create the window
--->Recieve messages from the windows and controls (like when they are clicked, typed in, ect.) and send them to WndProc

WndProc
--->Process the messages, and do something with them.

You can learn how to program GUI applications using the Windows API at: http://www.winprog.org/tutorial/

I hope this helps you understand the concept of, and gets you into programming GUI applications using the Windows API.
Reputation Points: 18
Solved Threads: 2
Light Poster
killdude69 is offline Offline
45 posts
since Jul 2008
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

>If you are programming in windows, you would use the Windows Application >Programming Interface (WinAPI).
And always get struck with windows and make unportable GUIs. Well, there is a very cute library which is called wxWidget. Learn it. It will save you time as it is portable, so would not have to learn a new toolkit when porting your application to other platform.
Even QT and GTK+(which comes with the binding gtkmm for c++) are good alternative.
But please don't settle with windows MFC or any other platform-dependent toolkit.

The beauty of wxWidget is that it uses the native API for the particular platform: like WinAPI when in Windows, GTK+ when in Linux GNOME, QT when in Linux KDE. So, you always get the native feel.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

>And always get struck with windows and make unportable GUIs.
siddhant3s, you don't have to take a strike at my integrity just because you don't like my approach. I was just telling him what the jump from command lin to Windows GUI.

WinAPI is the most commonly used and best documented API there is. Just because of a few compromises doesn't mean it has to be taken out of the equation completely.

It is a matter of oppinion, let him decide which he would like to choose. Also, with QT (like another suggested) you dont really code it yourself, its approach is completely indirect. I actually don't recommend it even for beginners, because if you start with it, then you will be reluctant to ever go back to hard coding.

Like when I started with visual basic, I was completely overwhelmed when I moved on to C++.

But there is 2 sides to this, because on the otherhand, if you start with a visual drag 'n drop program, it can ease you into hard coding.

You see siddhant3s, there is problems with both.

Either way it is your choice (@ the thread owner).
Reputation Points: 18
Solved Threads: 2
Light Poster
killdude69 is offline Offline
45 posts
since Jul 2008
May 31st, 2009
0

Re: The Jump from C++ Programming to Graphics?

>siddhant3s, you don't have to take a strike at my integrity just because you don't
>like my approach.
"strike at my integrity"..... what does that means? I never 'stroked' at your integrity.
Your approach? Which approach?
>GUI programs dont use the std:: namespace, because that is designed for
>DOS output like cin and cout.
I thought toolkits don't use std namespace so that they won't clash with the names with those of std ( which is exactly why namespaces are invented).
Also, std is not designed for command-line output. It is implemented to contain the standard names.


>WinAPI is the most commonly used and best documented API there is.
I can bet you would find more documentation for QT and GTK+. Naturally, M$ cannot compete us( the open-source hackers community). So, you would never find as much quality docs as you would for an opensource toolkit.

>Just because of a few compromises doesn't mean it has to be taken out of the >equation completely.
You call non-portability a minor compromise? I would never use a proprietary toolkit and become a slave of a private firm.

>Also, with QT (like another suggested) you dont really code it yourself, its
>approach is completely indirect.
I don't code? Then who do? And its approach is perfectly fine. It is open-source. You can proceed further development of QT itself; can you proceed the development of any WinAPI yourself? No, you can't as only M$ hired developers are given the source code and not the public. You loose.

>I actually don't recommend it even for beginners, because if you start with it,
>then you will be reluctant to ever go back to hard coding.
Let me tell you one thing: hard coding isn't sexy. QT, GTKmm and wxWidget provide abstracted interface on all platform so you don't need to know what is inside. Which is a good thing. This is all encapsulation is all about. And if you want to see the inner code, you are always invited.

So, there is actually no problem. You learn a good, free, open-source toolkit and start programming GUIs on all platforms.
Yes, of course the choice is of OP.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
Jun 1st, 2009
0

Re: The Jump from C++ Programming to Graphics?

>No, you can't as only M$ hired developers are given the source code and not the public.
I have every single source code file of the windows API, provided by Dev-Cpp under the Open Source lisence.
The files were not created by MS, they are created by BloodShed developers, see this code from <windows.h>:
CPP Syntax (Toggle Plain Text)
  1. /*
  2. windows.h - main header file for the Win32 API
  3.  
  4. Written by Anders Norlander <anorland@hem2.passagen.se>
  5.  
  6. This file is part of a free library for the Win32 API.
  7.  
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11.  
  12. */
  13. #ifndef _WINDOWS_H
  14. #define _WINDOWS_H
  15. #if __GNUC__ >=3
  16. #pragma GCC system_header
  17. #endif
  18.  
  19. /* translate GCC target defines to MS equivalents. Keep this synchronized
  20.   with winnt.h. */
  21. #if defined(__i686__) && !defined(_M_IX86)
  22. #define _M_IX86 600

Siddhant, what I meant by strike at my integrity was that you were saying my approach had downsides, but yet yours did and you didn't even explain what they were, thus basically saying that any WinAPI approach was the worst ever way to go possible, so disregard anything killdude69 says. I have tried QT, it is like visual basic, you wouldn't tell a C++ programmer to go back down to VB programming would you?

I think people shouldn't be so reluctant to try and learn something new, rather than use these programs that program for you like QT. It is not a good thing if you actually plan to stick with it forever. Yes they are good for multiple OSs, but you should also learn how to design the UI yourself without the aid of Drag 'n Drops.

What if everybody didn't know how to hard code, and always used QT? Nobody would actually know how to use C++ in its native form, only being able to code with help from a program that provides indirect functionality.

People should learn multiple APIs and kits. Not just stick with a drag and drop interface that does everything for you.

If you dont know what is inside, then it is more difficult to utilise its full potential.

You can't claim you can win a race if you dont know whats under the hood. All I am saying is if you are ACTUALLY serious about programming then use something that doesn't do everything for you.

Yes, the WinAPI always has its issues, but so does every other API and kit.
Last edited by killdude69; Jun 1st, 2009 at 2:58 am.
Reputation Points: 18
Solved Threads: 2
Light Poster
killdude69 is offline Offline
45 posts
since Jul 2008
Jun 1st, 2009
0

Re: The Jump from C++ Programming to Graphics?

>I have tried QT, it is like visual basic, you wouldn't tell a C++ programmer to go back down to VB programming would you?
Are you sure that it looks like VB?
C++ Syntax (Toggle Plain Text)
  1. MainWindow::MainWindow()
  2. {
  3. spreadsheet = new Spreadsheet;
  4. setCentralWidget(spreadsheet);
  5. createActions();
  6. createMenus();
  7. createContextMenu();
  8. createToolBars();
  9. createStatusBar();
  10. readSettings();
  11. findDialog = 0;
  12. setWindowIcon(QIcon(":/images/icon.png"));
  13. setCurrentFile("");
  14. }
  15. ...
  16. bool MainWindow::okToContinue()
  17. {
  18. if (isWindowModified()) {
  19. int r = QMessageBox::warning(this, tr("Spreadsheet"),
  20. tr("The document has been modified.\n"
  21. "Do you want to save your changes?"),
  22. QMessageBox::Yes | QMessageBox::Default,
  23. QMessageBox::Cancel | QMessageBox::Escape);
  24. if (r == QMessageBox::Yes) {
  25. return save();
  26. } else if (r == QMessageBox::Cancel) {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. ...
  33. void MainWindow::updateRecentFileActions()
  34. {
  35. QMutableStringListIterator i(recentFiles);
  36. while (i.hasNext()) {
  37. if (!QFile::exists(i.next()))
  38. i.remove();
  39. }
  40. for (int j = 0; j < MaxRecentFiles; ++j) {
  41. if (j < recentFiles.count()) {
  42. QString text = tr("&%1 %2")
  43. .arg(j + 1)
  44. .arg(strippedName(recentFiles[j]));
  45. recentFileActions[j]->setText(text);
  46. recentFileActions[j]->setData(recentFiles[j]);
  47. recentFileActions[j]->setVisible(true);
  48. } else {
  49. recentFileActions[j]->setVisible(false);
  50. }
  51. }
  52. separatorAction->setVisible(!recentFiles.isEmpty());
  53. }
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: function to convert from arabic to roman numbers
Next Thread in C++ Forum Timeline: CS201_4





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC