Jump to content

  • Log In with Google      Sign In   
  • Create Account

2D tutorial on OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 SeeForever   Members   -  Reputation: 131

Like
0Likes
Like

Posted 20 February 2008 - 01:07 AM

Greetings, I have been using SDL for quite a bit now. I really like that library, it's easy to use and has many functions and its sub-libraries are very handy. But I would like to try something more low-level. I thought of OpenGL, and found the NeHe tutorials, but those seem mainly aimed towards 3D applications. I am only interested in 2D at the moment. So I wanted to ask, is there a 2D-based tutorial on OpenGL that you would recommend? Thanks in advance.

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 19560

Like
0Likes
Like

Posted 20 February 2008 - 04:37 AM

OpenGL in itself doesn't handle anything other than graphics for you, you need to create the window, and handle input, yourself through other APIs then OpenGL. Since you already have some familairity with SDL, you should use that with OpenGL, as it's fairly easy to do with only a little hassle involved.

Using SDL with OpenGL

Then I'd look at this here: (It uses OpenGL and SDL for graphics)
Complete 2D Engine Overview
Particularily this section: Core Graphics

And you can always look at NeHe or other sites for how to use certain features.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 SeeForever   Members   -  Reputation: 131

Like
0Likes
Like

Posted 20 February 2008 - 10:51 PM

I just can't seem to grasp OpenGL's ideology... Guess I'll have to take notes, but once I understand the basics, it'll be a piece of cake.

Anyway, here's another question: I have a very simple game in pure SDL. It uses my engine, which is basically a wrapper around the various SDL libraries. That version runs very well, but on one of my slower computers (a 400MHz P2 with ~300 megs'o'ram) it runs a bit... choppy. Will there be a speed increase if I implement OpenGL into the engine (and modify the game to use textures instead of surfaces)?

Thanks again.

#4 Fiddler   Members   -  Reputation: 850

Like
0Likes
Like

Posted 20 February 2008 - 11:28 PM

Depending on the video card and drivers, you may see a significant speedup (especially if you are using blending).

You'll have to keep the limitations of older hardware (and general 3d hardware) in mind, though: no per pixel manipulations, no readbacks to CPU, and some older hardware may not support 32bit color (pre Riva TNT, and all 3dfx cards prior to 4000).

Last but not least, many drivers were problematic those days, so keep that in mind.

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]


#5 ramearess   Members   -  Reputation: 158

Like
0Likes
Like

Posted 21 February 2008 - 06:04 AM

OpenGL is a 3D graphics API though it can manage 2D drawing there are others such as SDL which are designed for 2D.

The most difficult part of working with OpenGL is creating the window and rendering context and this can be different between OSes, a good rule of thumb is when reading through the code from OpenGL tutorials if it does not contain A statement beginning with gl or GL_ then it's not a OpenGL call but rather something to do with window set-up or input handling.

A easy to follow tutorial on openGL using glut to skip all the nasty parts such as setting up a window.

When I first encountered OpenGL I started by modifying source code generated by the IDE that copied with all the window set-up.

I also found because the main choice for choosing OpenGL a lot of books and tutorials skim over the window set-up section as it's different between OSes. The best source I found for tutorials on setting up a window on a windows platform was Direct3D (DirectX) as it is windows only they go into more detail on setting up a window.

#6 evillive2   Members   -  Reputation: 694

Like
0Likes
Like

Posted 21 February 2008 - 04:34 PM

Quote:
The most difficult part of working with OpenGL is creating the window and rendering context
I find this semi true. My personal opinion is that the opengl states and using textures vs surfaces are more difficult coming from a 2d perspective than using any of the libraries such as GLFW, SDL or even GLUT for windowing as these use simple intuitive API calls whereas opengl can be a cruel mistress...

Some minor differences right off the bat that will take some fudging or getting used to coming from a pure 2d perspective:
1. screen coordinates are 0,0 in bottom left instead of upper left (easy fix).
2. texture mapping is not quite as easy (IMHO) as blitting (the benefits outweigh this though)
3. if you thought pixel manipulation was slow in SDL it gets worse in opengl however there are shaders and other workarounds that can make this multiples faster.
4. alpha blending vs colorkey - the different types of blending can be confusing and with scaling and rotation (although much faster fps wise) you will have to make some tweaks to your images and how you load them whereas colorkeys just ignored certain pixels so were never drawn when blitting

I totally made the move to 2d in 3d (via opengl however many concepts translate to any 3d API) and think the benefits far outweigh the pitfalls. I still don't understand vector math very well (you will want to learn at least some of this!) however even doing things in a very unoptimized way so you can feel more like old 2d there are noticeable performance boosts (especially when using alpha blending or rotation) to using a 3d API such as opengl on relatively modern hardware (modern = anything less than 5 or even 6 years old).

Sorry for the long post. Not sure why I replied in the first place. I must be really tired... :)

#7 SeeForever   Members   -  Reputation: 131

Like
0Likes
Like

Posted 21 February 2008 - 07:53 PM

No use, I can't understand it... probably because my math isn't that good.

I find myself copying code off tutorials without understanding a single line. No, I'll wait until I'm a bit more ready, I'll keep using SDL until then.

Thanks all very much for your replies!

#8 OrangyTang   Members   -  Reputation: 1294

Like
0Likes
Like

Posted 21 February 2008 - 10:01 PM

Quote:
Original post by evillive2
1. screen coordinates are 0,0 in bottom left instead of upper left (easy fix).

If you pass suitable arguments to glOrtho then you can position the screen origin either bottom left or bottom right depending on what you prefer (or even another corner if you're weird).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS