Sign in to follow this  

OpenGL ES on desktops

This topic is 1259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to use opengl es 2 on desktops natively? I have tried searching google and found alot to do with the android emulator but not much about gles2 on windows I found mesagles that maybe a solution for linux. I would think theres got to be something how do browsers use webgl?

Share this post


Link to post
Share on other sites

Thanks ill look into that at first glance i just see that it translates to directx is there something else they use for linux and mac osx?

 

Nevermind I see they use it for mac and linux just portions of it I guess

Edited by jeff8j

Share this post


Link to post
Share on other sites

Is there a way to do it in reverse so something already existing using opengl can run in a browser or mobile with opengles? Is there a higher language that could be used across everything? Do developers usually make multiple shaders for multiple targets?

Share this post


Link to post
Share on other sites

Is there a way to do it in reverse so something already existing using opengl can run in a browser or mobile with opengles? Is there a higher language that could be used across everything?

That's what game engines do - they make up their own higher level API and then implement it repeatedly for every back-end.
e.g. Not the best example, but the Horde3D graphics engine is originally built on GL, but then ported to GLES and D3D.

Do developers usually make multiple shaders for multiple targets?

The technique that I've seen most often is that you write your shaders in HLSL/Cg (pretty much the same language), with some #defines to cover up the differences between different HLSL-based back-ends. Then you use something like hlsl2glsl to support OpenGL.

Share this post


Link to post
Share on other sites

We run the same render path for desktop and mobile GL. I have a "proxy" header, which defines functions like gl::Clear, gl::VertexAttribPointer, etc instead. The proxy changes a few function names as needed, and a few things are switched on either compile or runtime flags. (Not many things.) I don't try to fully emulate correct GL ES behavior on desktop; I just want my ES code to run. This proxy does that and works across Windows, Linux, Mac, and iOS. 

 

As for shaders, I found that trying to share them across desktop and mobile was a catastrophe. I now use hlsl2glsl (linked above) with some custom patches for full Mac and ES support. I should remember to assemble those changes into a pull request some day.

Edited by Promit

Share this post


Link to post
Share on other sites
You might want to try out Emscripten. It compiles fairly typical C/C++ OpenGL code to Javascript / WebGL (WebGL is a subset of OpenGL ES).

You might also like to have a look at PVRVFrame which is part of the Imagination Technologies PowerVR SDK (http://www.imgtec.com/tools/powervr-tools/). We had a talk from these guys at work and these tools certainly looked useful. Edited by Karsten_

Share this post


Link to post
Share on other sites
Getting SDL2 up with EGL/GLES2 on Windows is really easy, albeit super poorly documented and took me forever to figure out a couple simple mistakes.

Make sure you're using a recent version of SDL; the latest is 2.0.3, and I think you need at least 2.0.2.

You'll also need to grab libEGL.dll and libGLESv2.dll (or build them). The easiest option is to grab the copies installed with Google Chrome. You also need d3dcompiler_46.dll, either the copy with Chrome or the one that ships with the D3D SDK (they're the same file).

Copy those DLLs along with the SDL2 DLL into your binary build directory like normal. When you build your app, do _not_ link to OpenGL32.lib like you would for a normal Windows GL application. When creating your window/context in SDL2, do (and this is from memory, so probably some small mistakes):
 
// helper, not strictly necessary
#include <SDL_opengles2.h>

#include <SDL.h>

void setup() {
  // must be done _before_ creating the window - this tells SDL to create an ES context instead of a GL one.
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);

  // not necessary, but I like being pedantic
  // ANGLE will support ES 3 very soon, so you might bump this up after if you want to target new mobiles and Firefox's WebGL2 experiment
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

  // create window with OpenGL flag
  SDL_Window* window = SDL_CreateWindow("test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);

  // create the context
  SDL_GLContext ctx = SDL_GL_CreateContext(window);
|

void clear_example() {
  // you need to grab the pointers since you didn't link directly with libGLESv2; or you could use a helper glue library, glew or glee or something, not sure which of them support ES
  // you also want to do all these lookups once and not do them every frame
  using ClearFunctionT = void(KHRONOS_APIENTRY*)(GLbitfield);
  ClearFunctionT fClear = (ClearFunctionT)SDL_GL_GetProcAddress("glClear");

  fClear(GL_COLOR_BUFFER_BIT);
}

Share this post


Link to post
Share on other sites

This topic is 1259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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