Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. If I target my framework for OpenGL on the desktop, will it just run without modification in an OpenGL ES 2.0 environment?
  2. 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?
like image 525
Heat Miser Avatar asked Jul 24 '09 18:07

Heat Miser


People also ask

Is OpenGL ES better than OpenGL?

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).

Is OpenGL ES a subset of OpenGL?

OpenGL ES is an “embeddable subset” of OpenGL. It slims down the rather large OpenGL API to the bare essentials, so that it can be implemented on devices with simpler, cheaper hardware, and above all, low enough power requirements to run on batteries.

What is OpenGL ES version?

OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices.

Is WebGL easier than OpenGL?

WebGL is used for web applications, and OpenGL is used for many video games. WebGL is easier to learn and develop applications. OpenGL can be learned easily if once you are familiar with WebGL.


2 Answers

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.

  1. 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.

  2. 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
like image 78
Ivan Vučica Avatar answered Sep 21 '22 13:09

Ivan Vučica


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.

like image 36
Tronic Avatar answered Sep 19 '22 13:09

Tronic