How do I start to create graphical programs (OpenGL?)

Jan 26, 2012 at 4:01am
I've been programming some RPG mechanics in C++, relying on the cmd box and therefore being limited to creating roguelike or text adventure games. I'm starting to get the hang of things pretty well, and while even though I'm probably not completely ready for the leap into 'graphical' programming, I'd like to know how I would go about doing it?

I bought "The Red Book", which is an OpenGL book but it mainly focuses on 3D development which I won't touch yet. What I want to know is:

1) How to create a basic window
2) How to draw sprites / hit detection etc.
3) How to differentiate between foreground and background
4) How to implement 'screens' (main menu, map screen, level etc)
5) How to display text, (do you draw from a font.ttf file?)

Note: I'm not asking for answers to the above questions, I'm simply asking what kind of book / guide on the internet I'm looking for in order to start learning these things myself.

Thanks for any replies, you guys are always helpful.
Jan 26, 2012 at 4:11am
You can do all of that with a graphics library like SFML.
There's a SFML tutorial on the site which you can use to get started.
Jan 26, 2012 at 4:57am
Well there are many libraries out. SFML, OpenGL (Which I recommend), DirectX (Not portable, but good on windows). A guy on YouTube who goes by the name of TheNewBoston, has some excellent tutorials too.
Jan 26, 2012 at 9:37am
Precious tutorial for the basic concepts of 3D programming on OpenGL. It doesen't comprise shaders 2.0 but I strognly recomendate:
http://nehe.gamedev.net/

I started up from this tutorial:
http://www.videotutorialsrock.com/

In both tutorials there is everything from the begining. From setting up OpenGL SDK to your IDE to basic technics.

Disclaimer: OpenGL is multiplatform. You can create 3D programs even on mobile phones with it. DirectX is powerful as well, a little bit more than OpenGL but it works only on windows platforms.
Jan 26, 2012 at 4:26pm
Thanks for the replies.

@ResidentBiscuit: I actually watched a few of his videos, they're pretty I great. I've picked up a couple of neat tips from those.

@billythekid I think I'll give that second tutorial a shot, it looks like it covers a lot of basic ground.


Before I'm done, I'll squeeze a couple more answers out of you guys if that's okay.

1) What does 'shaders' mean in relation to OpenGL?
2) I'm wanting to focus solely on 2D programming for now, are these tutorials fine for that or do I need to follow a certain subsection of the library?

Again, thanks for pointing me in the right direction guys.
Jan 26, 2012 at 6:26pm
I can second SFML, it is extremely simple and easy to use to create 2D applications.
It can manage windows, graphics, audio, and networking.

http://sfml-dev.org/
Jan 26, 2012 at 6:43pm
FWIW, SFML uses OpenGL at its core. If you want to use OpenGL for graphics, I still recommend using SFML because you can use straight OpenGL with it anyway, plus it also makes other things much easier, like window creation/management, texture loading, audio, and input.
Jan 27, 2012 at 1:28am
:O I might have to actually check out SFML myself. The biggest hurdle for me in getting into graphics, is the whole windows creation. It seems to be this outrageously complicated thing in all libraries. And I'm used to Java for anything GUI related, and making a window (frame in Java), is easier than anything.
Jan 27, 2012 at 1:34am
Making and managing a window (skeletal program) in sfml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Caption of Window");

    // main loop
    while (window.IsOpened())
    {
        sf::Event event;
        while (window.PollEvent(event))
        {
            switch(event.Type)
            {
            case sf::Event::Closed:
                window.Close();
                break;

                // Handle other events you care about (if any) here
            }
        }
 
        window.Clear();

        // Draw your stuff to the window here

        window.Display();
    }
 
    return 0;
}


This is about as easy as it can get in C++ and still be reasonably functional.
Last edited on Jan 27, 2012 at 1:39am
Jan 27, 2012 at 1:38am
Wow, that's much simpler than the DirectX and OpenGL window creation
Jan 27, 2012 at 2:01am
If you want to try SDL this site seems promising.

http://sites.google.com/site/sdlgamer/
Jan 27, 2012 at 2:02am
SDL is easier to set up, but harder to use, IMO.

Plus SFML is still being actively developed. SDL hasn't had an updated release in like 8 years or something.
Jan 27, 2012 at 2:08am
I definitely think I'll be going the SFML route, it seems really straight forward. Thanks for all of the links and tips guys.
Jan 31, 2012 at 9:17am
another simple (I guess) 2D crossplatform graphical library that I've heard about:
http://alleg.sourceforge.net/
Last edited on Jan 31, 2012 at 9:18am
Jan 31, 2012 at 11:53am
I'd like to mention that using SFML isn't the same thing as not using OpenGL - as far as I know, SFML allows you to directly use OpenGL in a rather straight forward way. I am not sure how compatible SFML is with modern OpenGL though, which is why I'm still hesistating to use it (I honestly have no wish to go back to glBegin / glEnd or other nonsense like that).
Last edited on Jan 31, 2012 at 11:53am
Feb 1, 2012 at 10:31am
Just pushing this up again: Did some investigation, and apparently SFML works fine with OpenGL 3.x and 4.x (didn't actually try 4.x though, my GPU doesn't support it), however requires the compatibility flag atm. I was told this would change "soon", as in when they are done revamping the graphics package.
Topic archived. No new replies allowed.