2D tutorial on OpenGL
#1 Members - Reputation: 122
Posted 20 February 2008 - 01:07 AM
#2 Marketplace Seller - Reputation: 8951
Posted 20 February 2008 - 04:37 AM
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.
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
#3 Members - Reputation: 122
Posted 20 February 2008 - 10:51 PM
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 Members - Reputation: 698
Posted 20 February 2008 - 11:28 PM
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 and OpenAL. Now with GL4 and multi-mouse][GLPlusPlus: C++ OpenGL headers for the win]
#5 Members - Reputation: 158
Posted 21 February 2008 - 06:04 AM
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 Members - Reputation: 579
Posted 21 February 2008 - 04:34 PM
Quote: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...
The most difficult part of working with OpenGL is creating the window and rendering context
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 Members - Reputation: 122
Posted 21 February 2008 - 07:53 PM
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 Members - Reputation: 1294
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).






