At what point should I start learning OpenGL?

So I have recently started to learn C++ and I have got all of the basics down (Arrays, Variables, Constants, Strings, Operators, Expressions, Statements, Loops, and Functions w/ Parameters). Probably some stuff that I haven't learned here and there but I have the general gist of it.

I have programmed the usual stuff any beginner would program, like a text-based calculator and RPG. I wish to try making more of my own projects, but my capabilities are very limited without knowing how to program graphics.

I am only around a fourth of the way through a beginner-advanced level book, so I am wondering if I should start learning OpenGL to aid my programming. Should I finish the book first, or begin to learn OpenGL within the next couple of days?

And if anybody thinks I should use a different graphics language, please feel free to tell me about it. I would appreciate one with intermediate difficulty and very good graphics capabilities.

Thanks!
Modern OpenGL is somewhat tricky if you've never done any graphics programming before. I'd highly recommend you use an intermediate library that wraps around it with a simpler interface before you start.

I often recommend SFML as such a library. It's very easy to learn and use, and you could easily pick it up now if you know enough to make a simple console-based RPG already.

Some alternatives to SFML are SDL (use version 2.x please -- 1.x is horrendously outdated) and Allegro.


SFML can be found here:
http://www.sfml-dev.org/


If you want to dive right into OpenGL instead... this tutorial is excellent:
http://www.arcsynthesis.org/gltut/

Avoid any OpenGL tutorial that tells you to use glMatrixMode, glLoadIdentity, glVertex3f, etc functions as those have been deprecated for some time, so those tutorials are very old.
Thanks! Was thinking about Allegro as an alternative. I'll check out all of them to see which one fits me best.
Hey, I was wondering. With SFML, do I have to add SFML libraries and headers and other stuff in my file properties for every new project I make?
Did you link them with the compiler?
You have to do that with every library. So yes.
I only had to do it once using code::blocks with GNU when I used SDL library.

Or is he talking about including the headers like #include "SOMETHING" ?
I assume he meant #include the header and link the library. Which must be done for every project.

Depending on your IDE there may be shortcuts, though. I wrote my own header for SFML to automate the linking and everything in MSVS.
Last edited on
Yeah, I meant linking up the SFML include and lib files with my compiler (Visual Studio Express 2012). Just wanted to know so I might remember to change my project properties when I start my next project. I know you have to write out #include <headerFile> in every program. Thanks for the help! Having a bit of trouble getting SFML to work properly though. Keep getting error codes whenever I compile. Fix one, another pops up. Happens pretty much every time I try something new.
Keep getting error codes whenever I compile.


You get errors when you compile SFML (like the actual lib)? Or you get errors when you compile something that uses SFML?

You should not be getting errors when compiling SFML. It should work as downloaded... you shouldn't have to fix anything.

So I'm assuming you mean the latter... in that you're trying to write a program that uses SFML but you are getting errors. I might be able to help with those errors. Can you post them and the related code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}


error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)
error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
error LNK1120: 2 unresolved externals


The first two statements were in the main.obj file and the last one was just my project's executable. I have no idea why these errors are popping up because I watched a youtube video on how to link SFML libraries and headers and also read the tutorial on the SFML website for Visual Studio. The source code is the test code that SFML used on their tutorial page to check if SFML was properly linked.
Last edited on
Yeah those are linker errors. Looks like you are linking to the window lib, but not to the graphics lib.

Double check and make sure you are linking to the appropriate "sfml-graphics" lib file in your projects linker settings.




FWIW, I perfer to avoid the manual linking and just put linking stuff right in a common header, so I can just include the header and be done with it.

The header I use:

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
30
31
#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

#define SFML_STATIC

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #pragma comment(lib,"sfml-graphics-s-d.lib")
    #pragma comment(lib,"sfml-audio-s-d.lib")
    #pragma comment(lib,"sfml-network-s-d.lib")
    #pragma comment(lib,"sfml-window-s-d.lib")
    #pragma comment(lib,"sfml-system-s-d.lib")
    #pragma comment(lib,"sfml-main-d.lib")
#else
    #pragma comment(lib,"sfml-graphics-s.lib")
    #pragma comment(lib,"sfml-audio-s.lib")
    #pragma comment(lib,"sfml-network-s.lib")
    #pragma comment(lib,"sfml-window-s.lib")
    #pragma comment(lib,"sfml-system-s.lib")
    #pragma comment(lib,"sfml-main.lib")
#endif


#endif // SFMLFULL_INCLUDED 


Though note that I statically link to SFML. If you are dynamically linking you'd want to use this instead:

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
#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #pragma comment(lib,"sfml-graphics-d.lib")
    #pragma comment(lib,"sfml-audio-d.lib")
    #pragma comment(lib,"sfml-network-d.lib")
    #pragma comment(lib,"sfml-window-d.lib")
    #pragma comment(lib,"sfml-system-d.lib")
    #pragma comment(lib,"sfml-main-d.lib")
#else
    #pragma comment(lib,"sfml-graphics.lib")
    #pragma comment(lib,"sfml-audio.lib")
    #pragma comment(lib,"sfml-network.lib")
    #pragma comment(lib,"sfml-window.lib")
    #pragma comment(lib,"sfml-system.lib")
    #pragma comment(lib,"sfml-main.lib")
#endif


#endif // SFMLFULL_INCLUDED 



Just throw this header in your SFML directory... then you can just #include it and the #pragmas will automatically link up your program with SFML.
Last edited on
OK, I got it working. One of my .dll files was misplaced. *facepalm
Might do that in the future if I get really lazy to where I just want to copy and paste. But for now I'll stick with changing the project properties.
Might do that in the future if I get really lazy to where I just want to copy and paste


Well it's not "lazy", it's "sensible". Making programming easier isn't necessarily a sign of laziness.

There's never a time where you'd want to include a header and not link to the library. So why put yourself through 2 steps?

With the number of SFML projects I make (for testing or for whatever else), I save a lot of time not having to dink around with that. Just a simple #include <sfml.h> and I get all of it. One step, nice and easy.

But for now I'll stick with changing the project properties.


That's fine. It's just a tip. Use it (or don't) at your discretion.

=)
@ Disch

If you want to dive right into OpenGL instead... this tutorial is excellent:
http://www.arcsynthesis.org/gltut/

I saw that that tutorial was for 3D-games, is there something similar for 2D-games?
I saw that that tutorial was for 3D-games, is there something similar for 2D-games?


Just use that one. If you understand 3D, you understand 2D.

Besides... OpenGL is a 3D graphics library, because all modern graphics hardware is designed around 3D.

2D graphics are the exact same concept... only you give all your triangles the same Z coordinate (to put them on a 2D plane) and you use an Orthogonal projection (which that tutorial discusses).
Last edited on
Topic archived. No new replies allowed.