Register to reply

Using Graphics in a C++ Code.

by Peon666
Tags: code, graphics
Share this thread:
Peon666
#1
Apr22-09, 11:58 PM
P: 110
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.
Phys.Org News Partner Science news on Phys.org
Bees able to spot which flowers offer best rewards before landing
Classic Lewis Carroll character inspires new ecological model
When cooperation counts: Researchers find sperm benefit from grouping together in mice
AUMathTutor
#2
Apr23-09, 12:01 AM
P: 490
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.
Peon666
#3
Apr23-09, 01:24 AM
P: 110
What's windows API and how can I use it?

daniel_i_l
#5
Apr24-09, 05:34 AM
PF Gold
daniel_i_l's Avatar
P: 867
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.
sin2beta
#6
Apr25-09, 10:15 PM
P: 28
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!
AUMathTutor
#7
Apr25-09, 11:46 PM
P: 490
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.
junglebeast
#8
Apr26-09, 08:26 PM
P: 462
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++.
aCogCorroded
#9
Apr26-09, 09:12 PM
P: 8
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.
AUMathTutor
#10
Apr26-09, 09:56 PM
P: 490
"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.
signerror
#11
Apr26-09, 10:03 PM
P: 223
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
junglebeast
#12
Apr27-09, 10:39 AM
P: 462
Quote Quote 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.
AUMathTutor
#13
Apr27-09, 12:10 PM
P: 490
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...
junglebeast
#14
Apr27-09, 01:49 PM
P: 462
Quote Quote 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.
workmad3
#15
Apr27-09, 05:23 PM
P: 52
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.
sin2beta
#16
Apr27-09, 10:50 PM
P: 28
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.
sin2beta
#17
Apr27-09, 10:54 PM
P: 28
Sorry for the double post, but I thought I would be kind and give a link to a tutorial

http://www.wxwidgets.org/docs/tutorials/hello.htm

Enjoy! And most of all make it fun! That's what programming should be. And if you become very ambitious and want to know comp sci in depth. The Wizard book is free online.

http://mitpress.mit.edu/sicp/

It is written by abelson and sussman, two of the greats. But that link is just something to save for later when you already know you want to program!


Register to reply

Related Discussions
Convert latex code to fortran code? Math & Science Software 1
Graphics with Onboard Intel Extreme Graphics 2 on ASUS P5PE VM Computing & Technology 8
Matlab and graphics Math & Science Software 0
Way to create graphics in C++ Computing & Technology 7
How do you use latex graphics? General Math 2