Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Graphics in C and C++
Index -> Programming, C++ -> C++ Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mazer




PostPosted: Fri Sep 02, 2005 1:52 pm   Post subject: Graphics in C and C++

I'm too cool for Turing!
Did that get your attention? I'm not here to judge whether or not your coolness does indeed surpass that maximum coolness threshold for legal usage of the Turing programming language. I'm here because I'm assuming that you're here for a reason that goes along the lines of the large statement made in the beginning of the post.

We here at compsci.ca see alot of folks who want to make C++ programs with graphics. And who the hell can blame them? You were t3h roxxor at Turing, weren't you? And all of the leetest ownzors use C++, am I right? THIS IS JUST LOGIC!

So, without further ado:

How can I make graphics in my C++ programs?
Don't get too excited (or angry?) when I say that I'm not answering the question right away. It seems to me (and many others, I am sure) that most of not all of the users that come in here asking about graphics in C++ thinking it'll be something like Turing except faster and cooler.

It's completely different. I know what you're thinking "OK, I understand that it will be different. Now answer my question!" Have you made any programs in C++? Do you understand the concepts? If no, go get a book! If yes, I might advise getting a book anyways.

C++ is a complex language. Anyone here could tell you that, and many of them already have so I won't waste my bandwidth saying it again.

What are my options for graphics?
No, seriously, C++ isn't like-- just kidding. Generally, there's two big players for graphics APIs (you damn well better know what an API is if you hope to gain anything from this!)
-OpenGL
-DirectX

What are the differences? Hell, I honestly couldn't tell you all, or even many of them. Here's what it boils down to for ME:
I can use OpenGL in Windows, and also Linux. And even OSX, and several others if I thought it necessary.

I can only use DirectX in Windows. It's owned by Microsoft, so as a stupid fool I might think that this makes it evil. But my main beef is the non-crossplatformness. I feel I should mention, that DirectX isn't graphics. It's a collection of Direct3D, DirectInput, DirectSound, DirectPlay, and possibly others that are all useful for making games.

So now what?
Well, you've got a crapload of resources. That's the magic of the Intertron: information as far as you can click.
Here's some popular tutorials for OpenGL
And here's one off the top of my head, for DirectX.

That's IT?! Those are my only choices?
No, just the major (IMO) ones. The next best would be SDL (or, for the Python's among us, PyGame).
SDL (Simple Directmedia Layer) is a simple (haha) way to get graphics. It allows you to draw 2D shapes (yes, you can use sprites) to the screen. It also gives you a handy way to take care of other stuff:
- window creation/handling (C++ isn't Turing)
- keyboard/mouse/joystick input
- music
- image loading
- networking

Oh yeah, and it's crossplatform too. Oh, and you can use OpenGL with it.

So now what?
Go and read. And misunderstand. And be confused. Then read more, and ask questions of people who know a great deal about this stuff (not necessarily people on compsci.ca) and begin to understand.
Understand, once again, that C++ is completely different from Turing. You don't slap some code into your "C++ window" and hit F1. Your programs are compiled. Whether you use OpenGL, or DirectX, or SDL, or SDL/OpenGL you will need to link to libraries in your programs. Not always the most fun thing to have to do. And since it's going to be different for whatever compiler and IDE you will be using, asking us here will likely just lead to more confusion.
It's not that we don't want to help you (in most cases) it's just that even for people who know loads about C++, graphics is a huge and mostly separate topic. And while not everyone here has been interested in learning about graphics, those who have may not be able to answer specific questions. There are websites and forums dedicated to helping people learn that stuff! Good luck!

Appendix A: Game engines
Let's not kid ourselves. You're hear asking about graphics because you think you're going to make a game and you know it. Nobody believes for a second that you mean to make a statistical graphing program! Well, maybe your pet rock, but let's face it, he was always a bit thick headed.
There are many graphics engines available to help you make games:
iD software has released the source for the Quake3 engine. Yes Quake3 is still cool, you nerd.
Irrlicht is another free (speech/beer) 3D engine. The testing screenshots look like garbage, but some users have made some pretty impressive visuals with it.
CrystalSpace is another slick 3D engine.

I haven't got the time/patience/knowledge to list them all, but they're out there. Sorry!

Resources
Google Very Happy
OpenGL.org lots of information that I could never dream of understanding completely
Nehe's OpenGL tutorials these can get you started, but can still be QUITE complicated. NOTE: the tutorials are written for Windows, but most have ports for other platforms and languages
DirectX The DirectX homepage
"DirectX NeHe style" used to be a bunch of tutorials like nehe, if I recall correctly, but seems to have become a sort of wiki now
SDL downloads, tutorials, etc
GameDev.net lots of articles and information for games programming. Don't ask them about making mmorpgs
DevMaster.net info for graphics with a focus on game development
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Sep 02, 2005 6:54 pm   Post subject: (No subject)

Great tutorial, great Smile. Now just move it into the tutorials section Wink.

One reason why I don't like DirectX is because as far as I know, it doesn't allow you to minimize your graphics/game which can get annoying.

Just a note, that most of the OpenGL tutorials on nehe.gamedev use a 'depreciated' library which is difficult to find. Some of their tutorials have been updated to not use this library, but the beginning few still use it. In any case, I will post it here later if anyone needs it (it's not on this computer).
TokenHerbz




PostPosted: Sat Sep 03, 2005 3:10 am   Post subject: (No subject)

Smile
Mazer




PostPosted: Sat Sep 03, 2005 7:05 am   Post subject: (No subject)

[Gandalf] wrote:
Great tutorial, great Smile. Now just move it into the tutorials section Wink.

Glad you like it. I considered the tutorial section, but I thought it might be better here for some reason. And since I can't remember what that reason was... *moved!*

[Gandalf] wrote:
One reason why I don't like DirectX is because as far as I know, it doesn't allow you to minimize your graphics/game which can get annoying.

I haven't worked with DirectX personally, but what you're saying sounds familiar. When to minimize or Alt+Tab out of your game, it needs to release the rendering context, and when you go back to the game it needs to be reinitialized. I'd like to point out that if what I just said was wrong, it's only because I have next to no idea what I'm talking about.

[Gandalf] wrote:
Just a note, that most of the OpenGL tutorials on nehe.gamedev use a 'depreciated' library which is difficult to find.

Am I correct in thinking you mean Glaux? I know they use it initially for loading bitmaps, but there might have been some other use they have for it. Personally, I use SDL_image to take care of that. And while I'm at it, SDL to take care of everything else in a nice cross platform way. It's teh win in my books for sure.

tokenherbz wrote:
Smile

Why, thank you!
[Gandalf]




PostPosted: Sat Sep 03, 2005 6:15 pm   Post subject: (No subject)

Coutsos wrote:
I haven't worked with DirectX personally, but what you're saying sounds familiar. When to minimize or Alt+Tab out of your game, it needs to release the rendering context, and when you go back to the game it needs to be reinitialized. I'd like to point out that if what I just said was wrong, it's only because I have next to no idea what I'm talking about.

Yes, maybe Smile, as far as I know, OpenGL doesn't have this problem.

Coutsos wrote:
Am I correct in thinking you mean Glaux? I know they use it initially for loading bitmaps, but there might have been some other use they have for it. Personally, I use SDL_image to take care of that. And while I'm at it, SDL to take care of everything else in a nice cross platform way. It's teh win in my books for sure.

Yep, glaux is the one. I'm not sure about SDL_image, or anything else as I haven't explored this too much, but it's just a warning that they're tutorials copy and pasted will not work without glaux. I think I might try to learn how to use SDL a bit...
Hikaru79




PostPosted: Mon Sep 05, 2005 5:56 pm   Post subject: (No subject)

w00t! A tutorial that helps beginners help themselves. I have a feeling it'll be frequently linked to around here Wink
md




PostPosted: Tue Sep 20, 2005 12:38 pm   Post subject: (No subject)

[Gandalf] wrote:

One reason why I don't like DirectX is because as far as I know, it doesn't allow you to minimize your graphics/game which can get annoying.


It can be done, it just requires a little work. Mostly remembering what was in each surface (texture...) and then loading it again if you need to. The only problem is that you need to redraw dynamically created surfaces which requires either keeping track of what was done, or just letting it pass until it next get's drawn.

[off topic]
Huzzah! Internet again! Oh how it sucks to be without internet for almost a month... I almost died!
Andy




PostPosted: Mon Aug 28, 2006 8:16 pm   Post subject: (No subject)

Anyone here have a lot of experience with DirectDraw? I need to learn it in 3 days, and might need some help.
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Aug 28, 2006 11:06 pm   Post subject: (No subject)

Aww, now I'm almost wishing that I had linked to some information regarding DirectX. Wait... wait... I did. Though I wouldn't say three days is a good timeframe for learning DirectX (at all). Good luck though.
md




PostPosted: Mon Aug 28, 2006 11:12 pm   Post subject: (No subject)

Andy wrote:
Anyone here have a lot of experience with DirectDraw? I need to learn it in 3 days, and might need some help.


DirectDraw is old and depreciated; it was last included as part of DirectX 7, DirectX 8 did away with it entirely. If you really want to learn direct draw then find a copy of the Direct X 7 help file (or search msdn). It should be all you need, assuming you understand the basics of graphic systems.
Andy




PostPosted: Tue Aug 29, 2006 12:00 pm   Post subject: (No subject)

wait, if its deprecated, then what do people use to draw 2 d graphics then?
md




PostPosted: Tue Aug 29, 2006 12:14 pm   Post subject: (No subject)

draw to textures; map the textures to a quad; then draw the quad. It's a strange way of getting 2d, but it does get you all sorts of other advantages (like all the benifits of 3d acceleration).
Andy




PostPosted: Thu Aug 31, 2006 10:30 pm   Post subject: (No subject)

I was going through a directx tutorial when i encountered this function protype statement

code:

LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);


does anyone have anyidea what it means to have LRESULT CALLBACK as the return type?
md




PostPosted: Thu Aug 31, 2006 10:47 pm   Post subject: (No subject)

LRESULT is a dword I think, CALLBACK is the calling convention iirc. MSDN will surely help you out there.
Andy




PostPosted: Wed Oct 04, 2006 9:23 pm   Post subject: (No subject)

md, how would you do a colorkey blit in D3D? sprites? or D3DXLoadSurfaceFromSurface

Thanks
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 26 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: