
-----------------------------------
Mazer
Fri Sep 02, 2005 1:52 pm

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.
That's IT?! Those are my only choices?
No, just the major (IMO) ones. The next best would be 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 is still cool, you nerd.
Resources
[url=http://www.google.com]Google  :D 
[url=http://www.opengl.org/]OpenGL.org lots of information that I could never dream of understanding completely
[url=http://nehe.gamedev.net]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
[url=http://www.microsoft.com/windows/directx/default.aspx]DirectX The DirectX homepage
[url=http://nexe.gamedev.net]"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
[url=http://www.libsdl.org]SDL downloads, tutorials, etc
[url=http://www.gamedev.net]GameDev.net lots of articles and information for games programming. Don't ask them about making mmorpgs
[url=http://www.devmaster.net/]DevMaster.net info for graphics with a focus on game development

-----------------------------------
[Gandalf]
Fri Sep 02, 2005 6:54 pm


-----------------------------------
Great tutorial, great :).  Now just move it into the tutorials section ;).

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
Sat Sep 03, 2005 3:10 am


-----------------------------------
:)

-----------------------------------
Mazer
Sat Sep 03, 2005 7:05 am


-----------------------------------
"]Great tutorial, great :).  Now just move it into the tutorials section ;).
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!*

"]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.

"]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.

 :) 
Why, thank you!

-----------------------------------
[Gandalf]
Sat Sep 03, 2005 6:15 pm


-----------------------------------
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 :), as far as I know, OpenGL doesn't have this problem. 

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
Mon Sep 05, 2005 5:56 pm


-----------------------------------
w00t! A tutorial that helps beginners help themselves. I have a feeling it'll be frequently linked to around here ;)

-----------------------------------
md
Tue Sep 20, 2005 12:38 pm


-----------------------------------
"]
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
Mon Aug 28, 2006 8:16 pm


-----------------------------------
Anyone here have a lot of experience with DirectDraw? I need to learn it in 3 days, and might need some help.

-----------------------------------
Mazer
Mon Aug 28, 2006 11:06 pm


-----------------------------------
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
Mon Aug 28, 2006 11:12 pm


-----------------------------------
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
Tue Aug 29, 2006 12:00 pm


-----------------------------------
wait, if its deprecated, then what do people use to draw 2 d graphics then?

-----------------------------------
md
Tue Aug 29, 2006 12:14 pm


-----------------------------------
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
Thu Aug 31, 2006 10:30 pm


-----------------------------------
I was going through a directx tutorial when i encountered this function protype statement


LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);


does anyone have anyidea what it means to have LRESULT CALLBACK as the return type?

-----------------------------------
md
Thu Aug 31, 2006 10:47 pm


-----------------------------------
LRESULT is a dword I think, CALLBACK is the calling convention iirc. MSDN will surely help you out there.

-----------------------------------
Andy
Wed Oct 04, 2006 9:23 pm


-----------------------------------
md, how would you do a colorkey blit in D3D? sprites? or D3DXLoadSurfaceFromSurface

Thanks

-----------------------------------
md
Wed Oct 04, 2006 9:58 pm


-----------------------------------
I unfortunately have very little experience with Direct3D on it's own. I've also been using linux for a long time, so my windows expereince is rusty... notthat I ever did a lot of graphics stuff anyways...

-----------------------------------
Andy
Tue Oct 24, 2006 4:50 pm


-----------------------------------
okay.. after 8 weeks at nvidia, i'm pretty confident about d3d9. so if anyone have any problems, post it here and i will try my best to answer them =)

-----------------------------------
Ninja
Wed Oct 25, 2006 7:30 am


-----------------------------------
okay.. after 8 weeks at nvidia, i'm pretty confident about d3d9. so if anyone have any problems, post it here and i will try my best to answer them =)

hey bro, do you know of any good books or any othe resources for learning d3d? i started learning some of it yesterday when i finally got vs2005 working with the directX9 SDK

-----------------------------------
tupac
Wed Oct 25, 2006 1:42 pm


-----------------------------------
I know some OpenGL and it took me about 3 days to learn how to make a little program with a sphere bouncing around the screen. i luv openGL, just cuz it makes everything so much easier to do. so if anyone wants to do graphics in C++ the answer I'd give is definately OpenGL.

-----------------------------------
Mazer
Wed Oct 25, 2006 1:43 pm


-----------------------------------
okay.. after 8 weeks at nvidia, i'm pretty confident about d3d9. so if anyone have any problems, post it here and i will try my best to answer them =)
Ugh, no. For starters, this thread is about introducing people to what graphics programming entails (and more importantly, to try and deter those who aren't ready for it yet). Secondly, this is the C & C++ Tutorials section. Maybe Dan could add a section for graphics programming?

-----------------------------------
Andy
Wed Oct 25, 2006 2:34 pm


-----------------------------------
going through the tutorials bundled with the D3DSDK would be a great place to start. After that, visit codesampler.com and try to understand all of the d3d samples provided. 

and coutsos, you talk to dan.

-----------------------------------
saltpro15
Sun Apr 12, 2009 7:24 pm

Re: Graphics in C and C++
-----------------------------------
reviving this old thread to recommend these excellent [url=http://lazyfoo.net/SDL_tutorials/index.php] tutorials on the SDL graphics library  They have everything you need to get started with 2d game development, and include source code for download.    Enjoy

-----------------------------------
Silinter
Mon Apr 13, 2009 12:06 am

Re: Graphics in C and C++
-----------------------------------
Thanks saltpro. I've been immersed in c++ programming for the past 3 weeks, and came across [url=http://student.kuleuven.be/~m0216922/CG/index.html]QuickCG and [url=http://irrlicht.sourceforge.net/]Irrlicht.
Mazer mentioned irrlicht in his post but said it didn't look too good. Im not sure how it was back in 05, but even the 19 included tutorials look AMAZING.
That is to say, to someone that's been trying how to figure out how to draw a line on the screen in a window just the other week, but it has some impressive features.

What do you guys think of QuickCG and Irrlicht. I'm not planning to keep QuickCG forever, but i think it's excellent when transitioning from turing to c++, and the author's site is very informative, not just about the language but a wide array of concepts.
Still can't figure out how to properly load in pictures, but i'll figure it out. In time...

Irrlicht made me jizz the first time I compiled the collision detection tutorial in dev-c++. Just damn; and the entries in the latest contest they held on their website were amazing. one entry was something like an RTS.

-----------------------------------
saltpro15
Mon Apr 13, 2009 8:15 am

RE:Graphics in C and C++
-----------------------------------
never heard of them Silinter, I'll check it out today.

-----------------------------------
Scott
Sun Mar 20, 2011 9:48 am

Re: Graphics in C and C++
-----------------------------------
For simply easy to use graphics I would use SDL, to do primitives(Draw line, points, ovals, circles) I found SDL_Draw (Just google to locate). It allows drawing like turing and java with no extensive knowledge to implement.

If a more experienced person can verify this is good advice?

-----------------------------------
apython1992
Sun Mar 20, 2011 9:55 am

RE:Graphics in C and C++
-----------------------------------
SDL is a good place to start, but the last post was a couple years ago...
