Sign in to follow this  
Anth420

From Java to C++

Recommended Posts

I work full time as a J2EE developer and I have done a fair amount of game programming in Java on my own (multiplayer server-client stuff with database for persistence). One of my co-workers and I want to pick up C++, more specifically 2d game programming, and we are having trouble with where to start. There doesn't seem to be a lot of good tutorials or books answering some basic questions. OpenGL vs DirectDraw vs DirectX vs XNA vs WinAPI vs ??? I am a fairly good programmer, so I'm not worried about the basics of C++. I am just looking for a good tutorial or book to get my foot in the door and some guidance on which API is recommended for basic 2d graphics.

Share this post


Link to post
Share on other sites
Using C++ it is generally OpenGL and DirectX.

DirectX:
+Full featured library
+Updated more often then OpenGL
+Has better driver support
-Windows only
-Large learning curve (from what I gather)

OpenGL:
+Easier to learn
+Cross-platform
-What you learn may not be them right thing to do (OpenGL3 fixes this a little)
-Bad driver support

Ultimately if you do want to do graphical work though, you may be better off getting a 2D engine in your case. Just use Google to find one.

Share this post


Link to post
Share on other sites
It depends on what basic questions you need answers to. If it's questions relating to c++ then simply post em here, but if you feel like you've got some grounds in the languge then there are millionz of tutorials out there. Check out This if you want to start with DirectX, or this NeHe if you prefer to start with OpenGl.

Share this post


Link to post
Share on other sites
Quote:
Original post by KodeNerd
Using C++ it is generally OpenGL and DirectX.

DirectX:
+Full featured library
+Updated more often then OpenGL
+Has better driver support
-Windows only
-Large learning curve (from what I gather)

OpenGL:
+Easier to learn
+Cross-platform
-What you learn may not be them right thing to do (OpenGL3 fixes this a little)
-Bad driver support

Ultimately if you do want to do graphical work though, you may be better off getting a 2D engine in your case. Just use Google to find one.


Yeah, D3D10 learning curve is alot steeper than there of D3D9 and OpenGL. OpenGL is alot easier to learn. But both are good at its own expense and functionality. You can achieve pretty equality of what both present. The only thing is you gotta deal with the hungarian code D3D9/10/Win32api/mfc give to you.

I have better driver support of OpenGL then I do on Windows. Using nVidia 177.80 in Linux I got higher FPS about 1000 more drawing a MD2 model. Using CgFX shaders only and my custom Matrix class in C++. And OpenGL has alot more api support than DirectX does also.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anth420
I work full time as a J2EE developer and I have done a fair amount of game programming in Java on my own (multiplayer server-client stuff with database for persistence). One of my co-workers and I want to pick up C++, more specifically 2d game programming, and we are having trouble with where to start. There doesn't seem to be a lot of good tutorials or books answering some basic questions.

OpenGL vs DirectDraw vs DirectX vs XNA vs WinAPI vs ???

I am a fairly good programmer, so I'm not worried about the basics of C++. I am just looking for a good tutorial or book to get my foot in the door and some guidance on which API is recommended for basic 2d graphics.


One thing that may surprise you is that compared to Java, the C++ language is a much bigger deal. In Java, your approach makes perfect sense. Picking up the language is easy, so all you really need to focus on is find the API you need, and use it.

The problem with C++ is that unless you really learn it, you're going to shoot yourself in the foot again and again. There are so many pitfalls, and so many idioms and tricks you should know to solve a lot of otherwise trivial problems. I'd recommend spending time on the language itself first. Buy a good book on the language. Of course, having prior programming experience makes it somewhat easier to pick up, but in the case of C++, it's still not a task that should be underestimated.

As for API, let's take the ones you listed.
The Windows API is probably hard to avoid. Pretty much anything that depends on the OS in some form will use the Windows API. (Of course there are plenty of wrappers to hide it, but it's probably not a bad idea to get used to the API to begin with). (Unlike Java, which does almost everything in the standard class library, C++ has pretty much nothing. No support for graphics, no support for reading mouse input, network communication, threads, sounds or anything else. All that is provided by the OS, and on Windows, that means the Win32 API.)

For advanced graphics, you'll want either OpenGL or Direct3D (note, both are aimed at 3d graphics, but you can use them for 2D as well, and since DirectDraw is deprecated, D3D is Microsoft's official recommendation as far as I know.)
You *can* do the graphics through GDI (the 2d graphics part of the Windows API), but I suspect that'll be just as painful to work with as D3D or OpenGL.

XNA is for .NET and managed code only, so not much point in using it with C++.

As for the inevitable OpenGL vs D3D comparison, eh.... D3D has by far the best tool support available, is well supported and generally very up to date with the latest GPU features. It's also a pretty clean and sensibly designed API.

OpenGL is the opposite. No tools to speak of, sometimes years behind with feature support and a mishmash of assorted functions accumulated over the last 20 years. Still, it's pretty straightforward to use, there are lots of tutorials covering it, and of course, it allows you to run on other platforms than Windows.
Great games have been made with both, so pick whichever you prefer.

But once again, don't assume that you can just pick up the C++ language just like that. If you're going to use C++ (Why, by the way? It's perfectly possible to write 2d games in Java), do yourself a favor and take time to learn the language.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anth420
... some guidance on which API is recommended for basic 2d graphics.


If I were you, I'd steer away from re-inventing the wheel. [smile]

Here's some good libraries that I've used in the past:

Allegro
+ Simple
+ Cross platform
+ Good blend functions (multiply, add, subtract, and other custom ones)
- Software rendering

HGE
+ Fast
+ Hardware acceleration (DX8)
- Windows only (AFAIK)
- No shader support
- Uses singleton pattern / can only use one window (ie, no MDI)

SFML
+ Cross platform
+ Strong OOP
+ Hardware acceleration (OpenGL)
+ Shader support
+ Also supplies (but you don't have to use) Audio, Networking, and Input
- May not be as fast as HGE


As for the java to C++: C++ is very different yet very similar to Java. Make sure you know the C++ concepts before diving in too deep.

Make sure you understand the pointer concept, how to handle dynamic memory, and make sure you know how to handle includes correctly and efficently [smile]

Share this post


Link to post
Share on other sites
Thanks to everyone's input. It gives me a lot to get started with.

Quote:
Original post by Spoonbender
If you're going to use C++ (Why, by the way? It's perfectly possible to write 2d games in Java), do yourself a favor and take time to learn the language.


I have written games in Java, but I know Java well enough to know its downfalls. I really want to take the time to expand my knowledge to other languages. Having a lot of experience in Java doesn't fit well into today's gaming market and thats where I want to head.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this