Porting OpenGL ES 2 to OpenGL - opengl

I have an iPhone game which I am porting to PC. The game uses OpenGL ES 2 (shaders) and I am to decide which version of OpenGL to use.
Should I port all shaders to OpenGL 2 (and support older hardware)? Or should I port to OpenGL 3 (which I don't know very well yet, but it seems that the shaders are more compatible)? Which will be easier to port?

Since OpenGL ES 2 is a subset of desktop OpenGL 2, you should be pretty fine with 2.x if you don't need your game to use more advanced techniques on PC (like instancing, texture arrays, geometry shaders, ..., things your ES device never heard about).
Just keep in mind, that the fact that you can use immediate mode and the fixed-function pipeline in desktop GL 2 doesn't mean you should. You can code completely forward-compatible modern GL (VBOs, shaders, ...) in OpenGL 2.0 just fine. On the other hand GL 3.x isn't really any different from previous versions, it just brings some additional features, which can be included later on if need arises. There is no real decision between GL 2 or 3, only between modern VBO-shader-based GL and old immediate-mode-fixed-function-based GL, and with your game already using GL ES 2.0 you have made the correct decision already.
Actually your shaders would be more compatible with GL 2 than 3, as ES 2 uses the old attribute/varying syntax. But that as a side note, nothing to really drive your decision as you may have to change your shaders a little bit, anyway (e.g. handle/remove precision qualifiers).

Related

Is it a big deal switching from OpenGL 3.0 to OpenGL ES 2.0?

If I am currently developing a game for windows using SDL and GLEW (for OpenGL 3.0+) and I later want to port my game to Android, will I have to rewrite the majority of my code to convert from OpenGL 3.0 to OpenGL ES 2.0? Are there any programs that do this for me? Is it a big deal switching from OpenGL to OpenGL ES?
Not at all, it is very easy to convert.
Only differences are shader variables and constants, and suffixes like GL_RGBA8 to GL_RGBA8_OES. However, there are limits in OpenGL ES. For instance, you can use only GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT as indices data type GL_UNSIGNED_INT. Which means, you can not draw more than 65,535 indices at one go. It is not a big deal although you should refer to the official OpenGL ES manual, https://www.khronos.org/opengles/sdk/docs/man/
Refer to the link OpenGL ES 2.0 vs OpenGL 3 - Similarities and Differences by coffeeandcode
It really depends on your code
OpenGL ES 2.0 (and 3.0) is mostly a subset of Desktop OpenGL.
The biggest difference is there is no legacy fixed function pipeline in ES. What's the fixed function pipeline? Anything having to do with glVertex, glColor, glNormal, glLight, glPushMatrix, glPopMatrix, glMatrixMode, etc... in GLSL using any of the variables that access the fixed function data like gl_Vertex, gl_Normal, gl_Color, gl_MultiTexCoord, gl_FogCoord etc...
If you use any of those features you'll have some work cut out for you. OpenGL ES 2.0 and 3.0 are just plain shaders. No "3d" is provided for you. You're required to write all projection, lighting, texture references, etc yourself.
If you're already doing that (which most modern games probably do ) you might not have too much work. If on the other hand you've been using those old deprecated OpenGL features which from my experience is still very very common (most tutorials still use that stuff). Then you've got a bit of work cut out for you as you try to reproduce those features on your own.
There is an open source library, regal, which I think was started by NVidia. It's supposed to reproduce that stuff. Be aware that whole fixed function system was fairly inefficient which is one of the reasons it was deprecated but it might be a way to get things working quickly.

Can I use both deprecated OpenGL and modern OpenGL in a single rendering window?

I am developing a project using modern OpenGL through OpenTK. I want to use Gwen dot net GUI library in my project. Unfortunately, Gwen dot net uses old OpenGL for its widget rendering. I have tried merging both modern OpenGL and Gwen dot net and so far, have been unsuccessfull. Before I waste my time debugging my code, I would like to know, is it possible to merge both old OpenGL and modern OpenGL?
If you create a compatibility profile context, it should support all all legacy functionality. From OpenGL 4.3 compatibility spec, 1.2.4:
Older generations of graphics hardware were not programmable using shaders,
although they were configurable by setting state controlling specific details of their
operation. The compatibility profile of OpenGL continues to support the legacy
OpenGL commands developed for such fixed-function hardware, although they
are typically implemented by writing shaders which reproduce the operation of
such hardware. Fixed-function OpenGL commands and operations are described
as alternative interfaces following descriptions of the corresponding shader stages.
These days mixing old style and new style OpenGL is best avoided. On MS Windows and Linux you can, but weird stuff tends to happen.
For MacOS, Apple have declared that they're not going to support compatibility contexts at all, so you can't mix.
Since you're stuck with the GUI toolkit, I would try to isolate all your new style OpenGL code in a separate context and render to an offscreen target, then blit that to the main display.
OpenTK render for GWEN is a separate class. Just rewrite it modern way. There's no problem with that.

How did I just use an OpenGL 3 feature in a 1.1 context?

I just started programming in OpenGL a few weeks ago, and as people suggested to me, I used GLFW as my window handler. I also used GLEW as my extensions handler. So I go through the whole process of making a vertex buffer with three points to draw a triangle and passing it to OpenGL to draw it and I compile and run. No triangle draws, presumably because I didn't have any shaders. So I think to myself "Why don't I lower my OpenGL version through the context creation using GLFW?" and I did that. From OpenGL 3.3 to 1.1 and surely enough, there's a triangle. Success, I thought. Then I remember an article saying that vertex buffers have only been introduce in OpenGL 3, so how have I possibly used an OpenGL 3 feature in a 1.1 context?
The graphics driver is free to give you a context which is a different version than what you requested, as long as they are compatible. For example, you may get a v3.0 context even if you ask for a v1.1 context, as OpenGL 3.0 does not change or remove any features from OpenGL 1.1.
Additionally, often times the only difference between OpenGL versions is what extensions that the GPU must support. If you have a v1.1 context but ARB_vertex_buffer_object is supported, then you will still be able to use VBOs (though you may need to append the ARB suffix to the function names).

learning OpenGL ES 2.0 under regular OpenGL - compilation

I am learning OpenGL with an aim to build OpenGL ES application for Android / iPhone.
Since I learn it from the beginning, I would prefer to learn the new specification, without touching the old stuff (glBegin etc.). Unfortunately, when I pass some tutorial and implement stuff, it turns out that the examples are incompatible with ES 2.0. For example, after those excellent tutorials I know how to implement lights, what works on my PC, but would not work on a mobile (gl_LightSource is not supported in the latter).
What I would like to do, is to develop the code on my PC, and restrict the API to the commands that are supported under OpenGL ES (like, throw error on glLight). Is that possible?
Assuming you are using Windows for development, then you can restrict the API to just OpenGL ES 2.0 by using Google ANGLE. ANGLE is basically wrapping DirectX, but you use it through a fully standard compliant OpenGL ES 2.0 interface.
If you have an AMD Radeon GPU, you have another option: the AMD OpenGL ES SDK also provides a fully compliant 2.0 interface.
In both cases, if you accidentally use non OpenGL ES 2.0 features, the code will just not compile or fail at runtime in case of unsupported combinations of parameters. Same goes for shaders, the glCompileShader call will fail.
IF you want to learn OpenGL ES 2 and make sure you are only using calls and techniques compatible with OpenGL ES 2, consider learning WebGL.
WebGL is almost identical to OpenGL ES 2. You get the advantage of a javasript console (with firebug or chrome's built-in developer tools) and in some environments (chrome on windows I think?) you get VERY helpful error messages whenever you do something wrong. Add to that you automatically have access to up to 4 implementations of WebGL to test with (firefox, chrome, safari, opera) and you have a pretty good set of tools for testing your OpengGL.
This is essentially how I have been able to learn OpenGL ES 2.
As stated in the Mali GPU OpenGL ES Application Development Guide:
OpenGL ES 1.1 and OpenGL ES 2.0 are subsets of the full OpenGL
standard. When using the OpenGL ES API, there are limitations that you
must be aware of when developing your applications.
For example, the following OpenGL functionality is not present in
either OpenGL ES 1.1 or OpenGL ES 2.0:
There is no support for glBegin or glEnd. Use vertex arrays and vertex buffer objects instead.
The only supported rasterization primitives are points, lines and triangles. Quads are not supported.
There is no polynomial function evaluation stage.
You cannot send blocks of fragments directly to individual fragment operations.
There is no support for display lists.
In addition, the following OpenGL functionality is not present in
OpenGL ES 2.0:
There is no support for the fixed-function graphics pipeline. You must use your own vertex and fragment shader programs.
There is no support for viewing transforms such as glFrustumf. You must compute your own transformation matrix, pass it to the vertex
shader as a uniform variable, and perform the matrix multiplication in
the shader.
There is no support for specialized functions such as glVertexPointer and glNormalPointer. Use glVertexAttribPointer
instead.
You can always refer to the OpenGL ES specification and see if a function / feature is supported.
There is a good set of lessons available for OpenGL ES 2.0 over at http://www.learnopengles.com/. For developing on PC you can try using an emulator; many different GPU vendors provide their own emulators that translate the calls to desktop GL. However, the best way to be sure that your code works as expected is to run it on the actual device.
EDIT: A new emulator for Android has support for OpenGL ES 2.0: http://android-developers.blogspot.ca/2012/04/faster-emulator-with-better-hardware.html

OpenGL ES versus OpenGL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
What are the differences between OpenGL ES and OpenGL ?
Two of the more significant differences between OpenGL ES and OpenGL are the removal of the glBegin ... glEnd calling semantics for primitive rendering (in favor of vertex arrays) and the introduction of fixed-point data types for vertex coordinates and attributes to better support the computational abilities of embedded processors, which often lack an FPU
Have a look here: OpenGL_ES
OpenGL ES is the opengl api for embedded systems. It is simpler than the normal opengl in terms of the number of the api functions, but may be harder to use, since you will have to use vertex buffers and write more shaders.
When you use a normal opengl, you can use glBegin and glEnd to enclose the geometry primitives you need to draw, but when using Opengl ES, you will have to use vertex buffers.
I guess this is for performance concerns.
Currently, there are two Opengl ES versions, the 1.1 version can only support the fixed rendering pipeline, while the 2.0 version supports glsl shader. However it has no fixed rendering pipeline. In other word, you will have to write your own shader for everything.
Opengl ES is mainly used on cell phones and web (webgl). According to the spec, your desktop opengl driver can support all opengl es apis.
Just like to add that OpenGL 3.3 and OpenGL ES 2.0 are mostly interoperable, by using a subset of the features of OpenGL 3.3. My custom C++ engine uses the same API calls, with a few defines, for Android/IOS/Windows/OSX/Linux.
Among the key differences are:
lack of geometry shader support
no min/max blending (there may be an extension for this)
no Quad List primitive
more restricted texture formats (especially regarding floating point)
glGetTexImage is not available
there is no Transform Feedback, same for several other advanced features
There are also many other differences, but that covers several of the important ones.
OpenGL ES means Open Graphics Library for Embedded Systems (OpenGL ES or GLES) is a subset of the OpenGL computer graphics rendering application programming interface (API) for rendering 2D and 3D computer graphics such as those used by video games, typically hardware-accelerated using a graphics processing unit (GPU). It is designed for embedded systems like smartphones, computer tablets, video game consoles and PDAs.
The OpenGL|ES Official Website: http://www.opengl.org/
you also can get more information from wiki : http://en.wikipedia.org/wiki/OpenGL_ES
Review the OpenGL ES overview here: http://www.khronos.org/opengles/
In short, ES is a subset of Open GL for "embedded systems". Specific differences will depend on the versions and feature sets you're comparing.
The OpenGL ES registry contains detailed API differences between OpenGL ES and the corresponding version of OpenGL:
OpenGL ES 2.0 / OpenGL 2.0
OpenGL ES 1.1 / OpenGL 1.5
However, there isn't a document containing the differences for OpenGL ES 3.0.
I think you'll get a better answer if you ask "what are the differences between OpenGL and OpenGL ES ".
There are profound differences between OpenGL ES 1.1 and ES 2.0, OpenGL 1.5 and 2.0, and OpenGL 3.0 and 4.0.
As others have described ES was written for embedded systems. It also represents the first "house cleaning" of the GL specification since its inception. OpenGL had a) many ways to do the same thing (e.g. you could draw a quad/rect two different ways and blit a pixel image two different ways, etc). ES is simpler than OpenGL with fewer features as a general statement because it's designed for less sophisticated hardware.
I urge you not to look at OpenGL ES 1.1 as it is the past and does not represent the way OpenGL or OpenGL ES is moving architecturally in the future.
The main difference between the two is that OpenGL ES is made for embedded systems like smartphones, while OpenGL is the one on desktops. On the coding level, OpenGL ES does not support fixed-function functions like glBegin/glEnd etc... OpenGL can support fixed-function pipeline (using a compatibility profile).
The modern answer, for ES 3.0 compared to OpenGL 4.6, is way different than the accepted answer. Now, all of the fixed-pipeline stuff is gone.
ES, for EMBEDDED SYSTEMS, is far less robust.
The terminology and versions are quite confusing (especially for newbies). For a more holistic view on OpenGL and OpenGL-ES (GLES), see OpenGL - Then and Now.
OpenGL ES is simply the OpenGL API for embedded systems (OpenGL ES refers to OpenGL Embedded Systems). so its a subset of OpenGL and widely used in cell phones and some VR systems, it's designed for less sophisticated hardware. OpenGL ES has less terms and functions than OpenGL, think of it as you are taking just what you need for that system, because if we dont need a function in whole our work or the hardware can't deal with it, then no mean to add that function but this also makes the use of this API more hard because of the need to write more Shaders and complicated codes to make something simple because OpenGL ES does not provide Shaders in the graphics pipeline as OpenGL. the last version of OpenGL ES is 3.2 it can now provide support for Tessellation for additional geometry details and new geometry shaders. so I advise you to start learning or using OpenGL ES 3.0+ (in case its your target API) because now and the next generation will not use the old versions especially with more powerful hardware and graphics cards we have today; and if your target is OpenGL start with v3.3+ or 4.0+. and when you have more time no problem to make a quick view on the old versions for more understanding how the things were and get developed and why.
you can check this link for more details : https://en.wikipedia.org/wiki/OpenGL_ES
OpenGL is 2D and 3D graphics API bringing thousands of applications to a wide variety of computer platform.
OpenGL ES is well-defined subsets of desktop OpenGL.
OpenGLĀ® ES is a royalty-free, cross-platform API for full-function 2D and 3D graphics on embedded systems - including consoles, phones, appliances and vehicles. It consists of well-defined subsets of desktop OpenGL, ...
See this link.
P.S.
WebGL shares specification with OpenGL ES, i.e. if you have learned desktop OpenGL, it is simple to learn the others(OpenGL ES, WebGL).
simply telling, opengl is desktop version and opengl es is for embedded systems like cellphones where there are memory and performance constraints more than that of computers. opengl es would be harder to use.