Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Do I (really) need 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
16 replies to this topic

#1 Master thief   Members   -  Reputation: 247

Like
0Likes
Like

Posted 20 September 2013 - 06:44 AM

I was following some tutorials on C++ with SDL and openGL, and as I was listening to the guy he mentioned what may be a key point for me: "openGL is an interface to your video card, so you can do 3D things".

 

So I was wondering, is this entirely true? Would I ever need openGL for 2D games?

 

I'm not planning on doing anything 3D and I guess I won't be for quite some time. So if this is true I may just skip openGL learning for now and focus on what I actually need.



Sponsor:

#2 wintertime   Members   -  Reputation: 1801

Like
0Likes
Like

Posted 20 September 2013 - 07:49 AM

Thats a wrong conclusion. Ultimately you need something to tell your video card what to show, its irrelevant if its 3D or 2D.

You could learn some other library thats less useful for 3D, but you will need to learn some library anyway and then you possibly discover later you learned something less capable or less widely used and you have to relearn.



#3 Ludus   Members   -  Reputation: 970

Like
1Likes
Like

Posted 20 September 2013 - 09:16 AM

SDL can handle 2D graphics just fine (I recommend using SDL 2.0 since it has more flexibility in this regard) so you could just stick with that for the time being.



#4 Master thief   Members   -  Reputation: 247

Like
0Likes
Like

Posted 20 September 2013 - 09:40 AM

Indeed, I'm using SDL and not yet openGL but I was thinking of mixing them. So perhaps I will leave openGL aside for now, since I'm already a bit into SDL, and I may get back to it when I'm experienced enough that I can mostly write a game on my own without melting my brain.

 

I don't have a problem with learning it later. I have more of an issue with having too much to worry about now, it may become too confusing. I think I prefer to go a step at a time as they become needed.

 

Thanks both of you for your feedback.


Edited by Master thief, 20 September 2013 - 09:41 AM.


#5 TheUnnamable   Members   -  Reputation: 803

Like
0Likes
Like

Posted 20 September 2013 - 09:45 AM

As mentioned above, OpenGL is more like something that tells the video card to do something. DirectX does the same, but it is only available on Windows.

 

In a certain sense, you do need OpenGL ( or DirectX ), but you don't always have to work with its code. Ultimately, SDL, Allegro, and the other similar libraries use OpenGL ( or DirectX ), but they provide a nice layer of abstraction so you don't have to mess with the low-level things.



#6 Master thief   Members   -  Reputation: 247

Like
0Likes
Like

Posted 20 September 2013 - 09:59 AM

Not entirely sure I understand. Does that mean these libraries may have "something" related to openGL within them?


Edited by Master thief, 20 September 2013 - 09:59 AM.


#7 GuardianX   Crossbones+   -  Reputation: 1528

Like
0Likes
Like

Posted 20 September 2013 - 10:14 AM

Not entirely sure I understand. Does that mean these libraries may have "something" related to openGL within them?

 

Yes, they are running on top of OpenGL, it means that they utilize it to render things on the screen. OpenGL and Direct3D are libraries, providing API to your video card hardware, this is true. The whole thing about 3D vs 2D is irrelevant, since they are essentially the same, they just utilize different projection matrices and coordinates.



#8 Master thief   Members   -  Reputation: 247

Like
0Likes
Like

Posted 20 September 2013 - 12:23 PM

Yes, I see. I remember now that some people made some actual 3D renderings with flash ActionScript 2, even though it was never intended to support it. And now that I think about it, it makes sense, since openGL (or any other such library) basically uses "raw" C++ (or the associated language) to achieve what it does.

 

So I guess it basically comes down to "do I need a video card or not?". Would a game made solely with SDL or Allegro (or FSML) only ever use the CPU? (considering that I wouldn't know how to deal with a video card on my own, purely with C++, I would assume so)

 

And just by the way, would you consider using the video card for even 2D games like say, a tetris clone, or an adventure game based on static images, or a platformer like Metal Slug)? I ask this just because I'm wondering when will I cross the line between good performace just using the CPU and the need for a little help from the video card.

 

Sorry if I'm asking lots of questions, I just want to have a consistent understanding of what I'm doing and what I'm dealing with.



#9 Miklas   Members   -  Reputation: 364

Like
1Likes
Like

Posted 20 September 2013 - 02:22 PM

About the 2D/3D: most 2D/3D related calculations can easily be extended (A 2D vector addition can also be done as a 3D addition with the last element zero) and most API's accept 2D data as well.  This means that you can perfectly use the OpenGL/Direct3D or any abstraction (SDL/SFML/Allegro...) for 2D games and still utilize the power of the GPU. Given that a GPU has a raw processing power that is far beyond a CPU's, even for simple 2D games like platformers I'd recommend using it.

 

About the "do I need a videocard"; the whole pipeline goes a little like this:

Application <-> (optional) Abstraction layer (such as SDL) <-> OpenGL/DirectX <-> Video Drivers <-> Hardware

 

This means that if there is a video driver that uses the CPU instead of the GPU; then you can run a game without a videocard but given the fact that the CPU has a lot less processing power (but is a lot more flexible) it probably won't be very smooth.

 

The hardware (GPU's) are there because they offer enormous amounts of power,

The drivers are there because every hardware is different and every vendor has their own architectures, (and because of this writing code directly for one GPU architecture is a very bad idea!)

The OpenGL/Direct3D api's are there because they standardize calls: you don't want vendors to include their own special features so you have to write your graphics code only once to run on all GPU's that support a certain OpenGL/Direct3D level,

The abstraction layers are there because the OpenGL and Direct3D API's are suited for all possible graphics applications and libraries such as SDL make certain applications easier (and often provide other features such as input handling which a graphics API doesn't provide).


Edited by Miklas, 20 September 2013 - 02:24 PM.


#10 GuardianX   Crossbones+   -  Reputation: 1528

Like
0Likes
Like

Posted 20 September 2013 - 02:36 PM

Yes, I see. I remember now that some people made some actual 3D renderings with flash ActionScript 2, even though it was never intended to support it. And now that I think about it, it makes sense, since openGL (or any other such library) basically uses "raw" C++ (or the associated language) to achieve what it does.

 

So I guess it basically comes down to "do I need a video card or not?". Would a game made solely with SDL or Allegro (or FSML) only ever use the CPU? (considering that I wouldn't know how to deal with a video card on my own, purely with C++, I would assume so)

 

And just by the way, would you consider using the video card for even 2D games like say, a tetris clone, or an adventure game based on static images, or a platformer like Metal Slug)? I ask this just because I'm wondering when will I cross the line between good performace just using the CPU and the need for a little help from the video card.

 

Sorry if I'm asking lots of questions, I just want to have a consistent understanding of what I'm doing and what I'm dealing with.

 

Well, I can't even imagine the situation where you don't have graphics card on user desktop with friendly OS. It is integrated into motherboard, into CPU or discrete. CPU alone couldn't process modern OS user interface and maintain the good performing business logic at the same time, because rendering task is extremely hard if you do not parallelize it by means of additional accelerator.

 

I think you are confusing general C++ concepts with GPU concepts. GPU is a SIMD processing unit, which has its own driver from manufacturer, which hides hardware specifications and provide more friendly and common interfaces to OpenGL and Direct3D. C++ doesn't have to do anything with GPU, it just manages GPU through some kind of interface, provided by video card's manufacturer.

 

Regarding 2D games. You can use whatever game engine you want, but know this - they will utilize OpenGL or Direct3D in order to present your game onto the screen. Usually those kind of engines are providing simple user-friendly interface and hide rendering mechanism, but at the end of the day, even emulated or "software" rendering will be presented on your screen by means of video card, thus utilizing OpenGL or Direct3D on OS level.



#11 Bregma   Crossbones+   -  Reputation: 5250

Like
0Likes
Like

Posted 20 September 2013 - 05:59 PM

I'm afraid some of these posts are a little misleading.

SDL and it's ilk are not written on top of OpenGL. SDL can be used to get an OpenGL context, but SDL itself does not use OpenGL.

If you're using SDL without OpenGL, you end up drawing to a frame buffer, bypassing the GPU entirely. The way a frame buffer works depends on the OS and the underlying hardware. On many computers, the GPU also ends up drawing to a framebuffer, and all framebuffers are rendered directly to the screen by a video chip (not a GPU).

Either way, if you write pure SDL code, you're not using OpenGL or the GPU.
Stephen M. Webb
Professional Free Software Developer

#12 mhagain   Crossbones+   -  Reputation: 8143

Like
2Likes
Like

Posted 20 September 2013 - 07:04 PM

Either way, if you write pure SDL code, you're not using OpenGL or the GPU.

 

Don't be so sure about that.  A modern OS will use either OpenGL or D3D to even accelerate it's desktop rendering, so ultimately, and even if you do a completely pure software renderer, the OS itself will be sending it through a 3D API which will use the GPU.  It may be just "put all of this into a render target and present it", or it may be further up the pipeline, but while you may not be using it directly yourself, you don't have control over what the OS does.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#13 Servant of the Lord   Crossbones+   -  Reputation: 20377

Like
4Likes
Like

Posted 20 September 2013 - 07:07 PM

SDL 1.x used software rendering by default.
I've heard, perhaps incorrectly, that SDL 2 uses OpenGL by default.

SFML (another 2D C++ library) uses OpenGL by default, and definitely is built ontop of OpenGL.

You can perfectly use OpenGL for 2D games, but you don't need to. It'd be easier to use something like SDL or SFML, which may or may not be using OpenGL under the hood to take advantage of the videocard. To do '2D' with these '3D' APIs, they just draw rectangles facing the screen, among other things, allowing them to still use the super-optimized drawing routines of the specialized hardware (the videocard). We could have (and have had in the past) hardware specialized for 2D drawing, but 3D videocards work fast enough for 2D that we no longer have the need for specialized 2D hardware, preferring (to save on the cost of computer hardware) to just do 2D on the 3D hardware and/or with 2D-specialized software. 2D rendering is rather simple after all, and is kinda a 'solved' problem (where with 3D we still hit performance limitations, and continually need to produce better hardware to meet the demands of new software).

You can use SDL or SFML without manually using OpenGL functions and make 2D games just fine.
Even when you move to 3D, you don't *have to* use OpenGL. You might just decide use a 3D engine that wraps OpenGL (or DirectX, an alternative).

OpenGL and DirectX define common APIs for accessing the messy videocard-specific interfaces to the videocards in a consistent way. SFML and some other APIs and 3D rendering engines then wrap OpenGL and DirectX to provide a nicer interface and more higher-level features. By 'higher level' I mean they provide convenience functions and classes that allow you to do common tasks in fewer lines of code than OpenGL and DirectX, in their generalized low-level nature, would require. E.g. doing something in one or two lines of code that might require 20 or 30 lines of OpenGL or DirectX.

So to answer your question, "Do I really need OpenGL?", no, you don't really need to learn OpenGL, but in most your projects you'll likely be using something that itself uses DirectX or OpenGL (or uses something that uses something else that uses OpenGL or DirectX, or... ad infinitum).


Edited by Servant of the Lord, 20 September 2013 - 07:20 PM.

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]


#14 Aldacron   GDNet+   -  Reputation: 3240

Like
1Likes
Like

Posted 21 September 2013 - 05:08 AM


I've heard, perhaps incorrectly, that SDL 2 uses OpenGL by default.

 

There are two ways to render with SDL 2, one via the old surface API and one with the accelerated rendering API. The latter will use D3D on Windows by default, OpenGL or OpenGL ES elsewhere, and a software renderer when neither available. The renderer is configurable during initialization so, for example, an OpenGL renderer can be created on Windows.

 

In practice, though, I've noticed a lot of people on the SDL mailing list recommending just avoiding the rendering API and create your own in OpenGL, using SDL for context creation and event management. As I understand it, there were some restrictions on the implementation in order to keep the software renderer on par with the hardware stuff. That may change in the future. For now, it's usable for simple 2D (probably for a wide range of games), but anyone wanting to take advantage of the hardware for special effects would need to roll their own.



#15 Master thief   Members   -  Reputation: 247

Like
0Likes
Like

Posted 21 September 2013 - 04:59 PM

Thank you all for your input, this is being quite insightful.



#16 Irlan   Members   -  Reputation: 1608

Like
0Likes
Like

Posted 23 September 2013 - 08:44 AM

Probably the guy that posted that, doesn't know anything about OpenGL and it's using another graphics library to do the job. sleep.png

OpenGL can be used to render 2D stuffs too.smile.png



#17 Irlan   Members   -  Reputation: 1608

Like
0Likes
Like

Posted 23 September 2013 - 12:39 PM

Multi-platform? Answer: Yes, its a must. 

Windows? Answer: Yes, along with DirectX. cool.png






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