Sign in to follow this  
Master thief

OpenGL Do I (really) need openGL?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628388
    • Total Posts
      2982403
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now