44

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?

5 Answers 5

41

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
3
  • 2/ imgtec.com/PowerVR/insider/sdkdownloads which archive for linux platform ? I am sure we can emulate glBegin on top of GLES implementation
    – RzR
    Commented Jul 1, 2011 at 9:27
  • @rzr: Emulating glBegin() is certainly possible, but might be a bad idea. You may instead want to restructure the code. On that site, you'll want to download "PC Emulation" archive for either OpenGL ES 1.1 or OpenGL ES 2.0. Commented Jul 7, 2011 at 10:09
  • the goal is to ensure a source compatibility first, dont care about performance, just want to build legacy apps ... -- rzr.online.fr/q/opengl
    – RzR
    Commented Jul 12, 2011 at 12:37
4

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.

2
  • 3
    +1 This is a very good answer that will probably lead to the most productive approach (avoid refactoring, write code as programmable with VBOs right from the start).
    – Engineer
    Commented Jul 9, 2012 at 12:27
  • 1
    ES2 is not a strict subset of desktop GL, ES3 is. Commented Jul 17, 2013 at 17:24
4

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.

2
  • I have found Regal recently too, it looks pretty nice. Commented Jul 17, 2013 at 11:55
  • I found Regal painful to use, however :(
    – lunixbochs
    Commented Jul 17, 2013 at 17:09
3

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.

2
  • The android SDK simulators definitely will run OpenGL ES code, depending on the API version your virtual device supports. Much slower than the real device though.
    – davenpcj
    Commented Jun 14, 2010 at 0:49
  • Furthermore, the Android emulator can only handle OpenGL ES 1.x. It throws an exception if fed OpenGL ES 2.0 code. That has to be tested on a device that supports 2.0. This might change in a couple of weeks with Ice Cream Sandwich, but I wouldn't count on it: the attitude of the developers is that it is simpler to test on a device anyway, so updating the emulator is not that important.
    – Matt J.
    Commented Oct 15, 2011 at 23:18
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.