image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

Go Back   Physics Forums > Other Sciences > Computing & Technology > Programming & Comp Sci


Reply

image Using Graphics in a C++ Code. Share It Thread Tools Search this Thread image
Old Apr23-09, 12:58 AM                  #1
Peon666

Peon666 is Offline:
Posts: 53
Using Graphics in a C++ Code.

How can I use graphics in my C++ code? I'm making a project of basic level (cricket score board) and I need to incorporate graphics in it. Are there any online tutorials etc. for graphics?

P.S. I use Visual C++ 6.0 compiler.
  Reply With Quote
Old Apr23-09, 01:01 AM                  #2
AUMathTutor

AUMathTutor is Offline:
Posts: 490
Re: Using Graphics in a C++ Code.

I assume you mean to have a GUI with graphics on it.

Well, you can use either the Windows API - it has methods for making windows and drawing on them, including lines, points, text, and basic shapes - or you can look into something called Direct Draw (maybe overkill for your application).

I think the Windows API will probably do it for you.
  Reply With Quote
Old Apr23-09, 02:24 AM                  #3
Peon666

Peon666 is Offline:
Posts: 53
Re: Using Graphics in a C++ Code.

What's windows API and how can I use it?
  Reply With Quote
Old Apr23-09, 07:59 AM                  #4
AUMathTutor

AUMathTutor is Offline:
Posts: 490
Re: Using Graphics in a C++ Code.

Here are some links to get you started.

http://en.wikipedia.org/wiki/Win32

http://www.infernodevelopment.com/c-win32-api-tutorial

http://msdn.microsoft.com/en-us/library/aa383750.aspx

http://www.relisoft.com/win32/index.htm

http://msdn.microsoft.com/en-us/libr...49(VS.85).aspx
  Reply With Quote
Old Apr24-09, 06:34 AM                  #5
daniel_i_l
 
daniel_i_l's Avatar

daniel_i_l is Offline:
Posts: 853
Recognitions:
PF Contributor PF Contributor
Re: Using Graphics in a C++ Code.

A good place to start is at nehe's opengl tutorials:
http://nehe.gamedev.net/

Instead of using win32 directly I'd recommend glut or SDL. The nehe website contains basecode for both of these options.
  Reply With Quote
Old Apr25-09, 11:15 PM                  #6
sin2beta

sin2beta is Offline:
Posts: 13
Re: Using Graphics in a C++ Code.

OpenGL is great and worth learning. But I would not recommend it for a beginning project. And I personally wouldn't use it just to make a scoreboard. I'd stick with the windows API or tk.

If this is a personal project, you might consider making a text-based version first. And if you are new to GUIs and programming in general, Python is very good to start GUI programming with. tk of wx would be more than fine.

And when learning graphics, google will bring A LOT of tutorials.

Best of luck!
  Reply With Quote
Old Apr26-09, 12:46 AM                  #7
AUMathTutor

AUMathTutor is Offline:
Posts: 490
Re: Using Graphics in a C++ Code.

And only non-computing people say "a code" or "codes". Just a little pet peeve. Try "code" without an article, in the singular, to denote the actual text representation of the source code of a program. When the code is compiled, it becomes an executable form of the program. When you run it, you get a process running the program.
  Reply With Quote
Old Apr26-09, 09:26 PM                  #8
junglebeast

junglebeast is Offline:
Posts: 428
Re: Using Graphics in a C++ Code.

Do NOT use Win32 API.

You need to find an acceptable graphics API.

The most powerful 3D graphics API that is used for all modern games is Direct3D (part of DirectX). This API is only available for Windows and XBox.

The most cross platform (but horribly out of date) 3D graphics API is OpenGL. If you use this you'll also need a window mangement program like Glut or SDL so that you DON'T have to use Win32 API which is a nightmare that nobody ever touches.

Even if your game is 2D, the most powerful API is still to use a 3D API like Direct3D (DirectDraw is deprecated).

If you are only doing 2D and you're not making a professional game, my recommendation is to use CImg which is a hell of a lot simpler than the above options. It's also cross platform. This is by far the best and simplest library for doing simple graphics in C++.
  Reply With Quote
Old Apr26-09, 10:12 PM                  #9
aCogCorroded

aCogCorroded is Offline:
Posts: 8
Re: Using Graphics in a C++ Code.

I recommend http://lazyfoo.net/SDL_tutorials/index.php. Also, SFML looks nice, but not quite as well documented (though it is supposed to be faster than SDL). Another option is the allegro game programming library. And I second staying away from the Win32 API. Blah! Unless 3d, don't worry about OpenGL or DirectX yet. Though great and fast for 2d, these two libraries will take longer to learn than the others I mentioned.
  Reply With Quote
Old Apr26-09, 10:56 PM                  #10
AUMathTutor

AUMathTutor is Offline:
Posts: 490
Re: Using Graphics in a C++ Code.

"Do NOT use Win32 API."

Why not? Did he say he was making a game? Did he say he needed fast, smooth graphics? Why make this that complicated?

Unless I'm remembering incorrectly, the Win32 API has some very simple functions for doing graphics... bitblt for drawing bitmaps, setpixel for drawing dots, also things for lines, ellipses, etc. You end up doing about the same, or more, work using fancy packages.

IMHO, DirectX and OpenGL sound like overkill.
  Reply With Quote
Old Apr26-09, 11:03 PM                  #11
signerror

signerror is Offline:
Posts: 220
Re: Using Graphics in a C++ Code.

What about Qt?

http://www.qtsoftware.com/products/

http://en.wikipedia.org/wiki/Qt_(toolkit)

Free, cross-platform, very polished.

Note there's two different things being described here. There are libraries for graphics (OpenGL, DirectX), and for graphical user interfaces (Qt, Tk, wxWidgets, the Windows APIs). The latter group gives you useful primitives for interaction (e.g. windows, widgets, layout management) and is probably what you want.

The Qt tutorials are here

http://doc.trolltech.com/4.5/tutorials.html
  Reply With Quote
Old Apr27-09, 11:39 AM                  #12
junglebeast

junglebeast is Offline:
Posts: 428
Re: Using Graphics in a C++ Code.

Originally Posted by AUMathTutor View Post
"Do NOT use Win32 API."

Why not? Did he say he was making a game? Did he say he needed fast, smooth graphics? Why make this that complicated?

Unless I'm remembering incorrectly, the Win32 API has some very simple functions for doing graphics... bitblt for drawing bitmaps, setpixel for drawing dots, also things for lines, ellipses, etc. You end up doing about the same, or more, work using fancy packages.

IMHO, DirectX and OpenGL sound like overkill.
The win32 api is highly overcomplicated and not very powerful. That's why I suggested three alternatives, the two most powerful alternatives (Direct3D and OpenGL) and one less powerful but simple alternative CImg. Regardless of his skill level or need, one of these will be superior to using the win32 api directly.
  Reply With Quote
Old Apr27-09, 01:10 PM                  #13
AUMathTutor

AUMathTutor is Offline:
Posts: 490
Re: Using Graphics in a C++ Code.

I respectfully disagree with this:"The win32 api is highly overcomplicated and not very powerful."

How is it overcomplicated? It was my understanding that to even *use* DirectX you had to create a window and manage resources... using the Win32 API. Can you use DirectX without making a window, having a message handler, and all the baggage that goes along with it?

And once you have a window, how is it hard to start drawing on it? I don't see how this is any harder than using DirectX.

As far as power goes... well yes, DirectX is more powerful, but that doesn't mean you should use it by default. I would argue that the least powerful mechanism which can get the job done should always be preferred... and I know for a *fact* that a simple scoreboard for a cricket game can be programmed with the Win32 API. To me, it sounds like a few bitmaps, a few lines, and some text drawing.

I don't have a lot of experience with OpenGL, but I suspect that you have to jump through the same Win32 API hoops no matter what...
  Reply With Quote
Old Apr27-09, 02:49 PM                  #14
junglebeast

junglebeast is Offline:
Posts: 428
Re: Using Graphics in a C++ Code.

Originally Posted by AUMathTutor View Post
I respectfully disagree with this:"The win32 api is highly overcomplicated and not very powerful."

How is it overcomplicated? It was my understanding that to even *use* DirectX you had to create a window and manage resources... using the Win32 API. Can you use DirectX without making a window, having a message handler, and all the baggage that goes along with it?
As I said in my post, Direct3D is the most complicated API but also the most powerful, making it the easiest API to use for the most complex effects, and the most difficult API to use for the least complex effects. The reason I did not suggest Direct3D was because he is a beginner and probably doesn't require all that complexity. The alternative API which I did suggest is significantly easier to use and more efficient than the Win32 API.

I don't have a lot of experience with OpenGL, but I suspect that you have to jump through the same Win32 API hoops no matter what...
You don't. That is the purpose of Glut and SDL.
  Reply With Quote
Old Apr27-09, 06:23 PM                  #15
workmad3

workmad3 is Offline:
Posts: 51
Re: Using Graphics in a C++ Code.

D3d and OGL are comparable in power and OGL is hardly 'horribly out of date'. The real problem with OGL is that Windows has no updated versions of it available meaning you have to rely on extension mechanisms in order to gain access to the up-to-date features. OGL 2.0 and 2.1 have all the same shader features as part of the standard as D3D and geometry shaders available as extensions on any graphics hardware that supports them (as opposed to D3D which restricts this to DX10 and only runs them on windows). With the new OGL 3.0 and 3.1 standards as well, it's pretty much a new game out there. Incidentally, Doom3 and Quake4 were done using OpenGL rather than D3D.

On the topic of the original topic though... firstly, upgrade your C++ compiler. Visual C++ 6 IS horribly out of date, and barely counts as a C++ compiler due to it's lack of standards compliance in so many areas. Visual C++ 2008 is available as a free download for the express version and is much improved.
Secondly, if what you want is just your basic UI widgets, then look into a UI library. QT, GTK, wxWidgets or something... those all have C++ bindings and are of varying complexity. None are as complex as trying to do the UI widgets yourself though.
If you want something more complex, then SDL or SFML are pretty decent cross-platform 2d libraries for your own drawing. SFML is designed around a more OO approach than SDL (which is a C API) and is IMO easier to use. It also uses OpenGL under the hood (SDL uses GDI calls) and takes advantage of hardware acceleration making it by default a faster 2d library and easier to integrate with 3d graphics.
  Reply With Quote
Old Apr27-09, 11:50 PM                  #16
sin2beta

sin2beta is Offline:
Posts: 13
Re: Using Graphics in a C++ Code.

As suggested qt is another good one to learn. So, I would probably start with qt, tk, or wxWidgets. In fact, give them all a shot.

I still suggest learning openGL as someone else suggested... but do it later. It is overkill for a beginning scoreboard project. An F1 racer would just become burdensome on the highway during rush hour. And when you tack on learning to drive... it just isn't the best starting point.

Learn a simple GUI that is made to just create buttons and fields. Get used to mouse events, then move onto sdl and opengl if you need them or if you are just curious. But starting trying to do that stuff early probably chases away a lot of new programmers. Walk before you run.
  Reply With Quote
image image
Reply
Thread Tools


Similar Threads for: Using Graphics in a C++ Code.
Thread Thread Starter Forum Replies Last Post
Convert latex code to fortran code? nancy2fancy1 Programming & Comp Sci 1 Dec9-07 05:20 PM
Graphics with Onboard Intel Extreme Graphics 2 on ASUS P5PE VM anantchowdhary Computing & Technology 8 May19-07 09:51 PM
matlab and graphics dervast Math & Science Software 0 Feb21-06 06:05 AM
Graphics JamesU Computing & Technology 7 Sep10-05 11:08 AM
How do you use latex graphics? dasmin5 General Math 2 Jan14-05 04:43 PM

Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image