learning OpenGL ES 2.0 under regular OpenGL - compilation - opengl

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

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.

Porting OpenGL ES 2 to 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).

Differences between WebGL and OpenGL

Can anyone give me a simple answer about the exact difference between OpenGL and WebGL? I need more specific on the following:
programming semantics, API's inheritence, API's extensions etc.
I've looked at the following site but it is not very clear to me:
http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences
WebGL is "OpenGL ES 2", not plain OpenGL (the ES stands for 'for Embedded Systems'). So there's the first difference. OpenGL ES is essentially a subset of OpenGL. In addition, WebGL is almost the same as OpenGL ES 2, but has some subtle differences, explained in the link you provide. There's not much to add to that link, it's a pretty clear explanation of what is different between OpenGL ES 2 and Webgl.
OpenGL is a desktopcomputer-centric API (like Direct3D). WebGL is derived from OpenGL ES 2.0 (intended for mobile devices) which has less capabilities and is simpler to use.
WebGL is also designed to run in a browser, and has therefore a few limitations more then OpenGL ES 2.0.
Unlike OpenGL, WebGL does not require native driver support. A wrapper called ANGLE, which Safari, Chrome and Firefox use can translate WebGL calls and GLSL to either OpenGL/GLSL or Direct3D/HLSL
Please see the Khronos wiki for a detailed answer: http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences
WebGL is meant to run in a browser (web applications).
WebGL is a software library that extends the capability of the JavaScript programming language to allow it to generate interactive 3D graphics within any compatible web browser.
...
It uses the HTML5 canvas element and is accessed using Document Object Model interfaces. Automatic memory management is provided as part of the JavaScript language.
OpenGL is typically used in desktop applications. It is a cross-language, cross-platform specification, of which WebGL is more-or-less a subset.
The consortium (https://www.khronos.org/webgl/) definition is quoted below.
WebGL is a cross-platform, royalty-free web standard for a low-level 3D graphics API based on OpenGL ES 2.0, exposed through the HTML5 Canvas element as Document Object Model interfaces. Developers familiar with OpenGL ES 2.0 will recognize WebGL as a Shader-based API using GLSL, with constructs that are semantically similar to those of the underlying OpenGL ES 2.0 API. It stays very close to the OpenGL ES 2.0 specification, with some concessions made for what developers expect out of memory-managed languages such as JavaScript.
OpenGL and WebGL have similar semantics but are coded in different languages. You will see at the basic level that most of differences are in the programming language constructs of C/C++ vs JavaScript
WebGL and OpenGL shows the similarities between the two, OpenGL in C/C++ and WebGL in JavaScript.

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.

OpenGL vs OpenGL ES 2.0 - Can an OpenGL Application Be Easily Ported?

I am working on a gaming framework of sorts, and am a newcomer to OpenGL. Most books seem to not give a terribly clear answer to this question, and I want to develop on my desktop using OpenGL, but execute the code in an OpenGL ES 2.0 environment. My question is twofold then:
If I target my framework for OpenGL on the desktop, will it just run without modification in an OpenGL ES 2.0 environment?
If not, then is there a good emulator out there, PC or Mac; is there a script that I can run that will convert my OpenGL code into OpenGL ES code, or flag things that won't work?
It's been about three years since I was last doing any ES work, so I may be out of date or simply remembering some stuff incorrectly.
No, targeting OpenGL for desktop does not equal targeting OpenGL ES, because ES is a subset. ES does not implement immediate mode functions (glBegin()/glEnd(), glVertex*(), ...) Vertex arrays are the main way of sending stuff into the pipeline.
Additionally, it depends on what profile you are targetting: at least in the Lite profile, ES does not need to implement floating point functions. Instead you get fixed point functions; think 32-bit integers where first 16 bits mean digits before decimal point, and the following 16 bits mean digits after the decimal point.
In other words, even simple code might be unportable if it uses floats (you'd have to replace calls to gl*f() functions with calls to gl*x() functions.
See how you might solve this problem in Trolltech's example (specifically the qtwidget.cpp file; it's Qt example, but still...). You'll see they make this call:
q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));
This is meant to replace call to glClearColorf(). Additionally, they use macro f2vt() - meaning float to vertex type - which automagically converts the argument from float to the correct data type.
While I was developing some small demos three years ago for a company, I've had success working with PowerVR's SDK. It's for Visual C++ under Windows; I haven't tried it under Linux (no need since I was working on company PC).
A small update to reflect my recent experiences with ES. (June 7th 2011)
Today's platforms probably don't use the Lite profile, so you probably don't have to worry about fixed-point decimals
When porting your desktop code for mobile (e.g. iOS), quite probably you'll have to do primarily these, and not much else:
replace glBegin()/glEnd() with vertex arrays
replace some calls to functions such as glClearColor() with calls such as glClearColorf()
rewrite your windowing and input system
if targeting OpenGL ES 2.0 to get shader functionality, you'll now have to completely replace fixed-function pipeline's built in behavior with shaders - at least the basic ones that reimplement fixed-function pipeline
Really important: unless your mobile system is not memory-constrained, you really want to look into using texture compression for your graphics chip; for example, on iOS devices, you'll be uploading PVRTC-compressed data to the chip
In OpenGL ES 2.0, which is what new gadgets use, you also have to provide your own vertex and fragment shaders because the old fixed function pipeline is gone. This means having to do any shading calculations etc. yourself, things which would be quite complex, but you can find existing implementations on GLSL tutorials.
Still, as GLES is a subset of desktop OpenGL, it is possible to run the same program on both platforms.
I know of two projects to provide GL translation between desktop and ES:
glshim: Substantial fixed pipeline to 1.x support, basic ES 2.x support.
Regal: Anything to ES 2.x.
From my understanding OpenGL ES is a subset of OpenGL. I think if you refrain from using immediate mode stuff, like glBegin() and glEnd() you should be alright. I haven't done much with OpenGL in the past couple of months, but when I was working with ES 1.0 as long as I didn't use glBegin/glEnd all the code I had learned from the standard OpenGL worked.
I know the iPhone simulator runs OpenGL ES code. I'm not sure about the Android one.
Here is Windows emulator.
Option 3) You could use a library like Qt to handle your OpenGL code using their built in wrapper functions. This gives you the option of using one code base (or minimally different code bases) for OpenGL and building for most any platform you want. You wouldn't need to port it for each different platform you wanted to support. Qt can even choose the OpenGL context based on the functions that you use.