| | |
The Jump from C++ Programming to Graphics?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 9
Reputation:
Solved Threads: 0
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
Thanks
Danny2000
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.
92% of all statistics are made up on the spot.
If you found a post helpful, please click the "give XXX reputation" link, to show your appreciation to those who helped you. Thanks! :D
If you found a post helpful, please click the "give XXX reputation" link, to show your appreciation to those who helped you. Thanks! :D
•
•
Join Date: Feb 2008
Posts: 629
Reputation:
Solved Threads: 46
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
Sorry, I don't know anything about windows GUIs in c++.
Good luck.
Dave
•
•
Join Date: Jul 2008
Posts: 45
Reputation:
Solved Threads: 1
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.
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.
>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.
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.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
•
•
Join Date: Jul 2008
Posts: 45
Reputation:
Solved Threads: 1
>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).
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).
>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.
>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.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
•
•
Join Date: Jul 2008
Posts: 45
Reputation:
Solved Threads: 1
>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>:
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.
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)
/* windows.h - main header file for the Win32 API Written by Anders Norlander <anorland@hem2.passagen.se> This file is part of a free library for the Win32 API. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef _WINDOWS_H #define _WINDOWS_H #if __GNUC__ >=3 #pragma GCC system_header #endif /* translate GCC target defines to MS equivalents. Keep this synchronized with winnt.h. */ #if defined(__i686__) && !defined(_M_IX86) #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.
>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?
Are you sure that it looks like VB?
C++ Syntax (Toggle Plain Text)
MainWindow::MainWindow() { spreadsheet = new Spreadsheet; setCentralWidget(spreadsheet); createActions(); createMenus(); createContextMenu(); createToolBars(); createStatusBar(); readSettings(); findDialog = 0; setCurrentFile(""); } ... bool MainWindow::okToContinue() { if (isWindowModified()) { tr("The document has been modified.\n" "Do you want to save your changes?"), QMessageBox::No, return save(); return false; } } return true; } ... void MainWindow::updateRecentFileActions() { QMutableStringListIterator i(recentFiles); while (i.hasNext()) { i.remove(); } for (int j = 0; j < MaxRecentFiles; ++j) { if (j < recentFiles.count()) { .arg(j + 1) .arg(strippedName(recentFiles[j])); recentFileActions[j]->setText(text); recentFileActions[j]->setData(recentFiles[j]); recentFileActions[j]->setVisible(true); } else { recentFileActions[j]->setVisible(false); } } separatorAction->setVisible(!recentFiles.isEmpty()); }
![]() |
Similar Threads
- Programming Resources (Updated 21-July-05 ) (Computer Science)
- which language ? (Computer Science)
- games programming!! in C++ (C++)
- MMORPG Developers Needed (Programming / Graphics / Etc) (Software Development Job Offers)
- Programming Resources (Computer Science)
- Switching from CS to being a Statistician? (IT Professionals' Lounge)
- Greetings (Community Introductions)
- Forum lurkers, introduce yourself ... !! (Community Introductions)
Other Threads in the C++ Forum
- Previous Thread: function to convert from arabic to roman numbers
- Next Thread: CS201_4
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






