How to use sdl2 with libglesv2.dll libegl.dll (angleproject)

I want to use angleproject(https://code.google.com/p/angleproject/) with SDL2 on windows for opengl es 2.0.
How to compile SDL2.dll to use libglesv2.dll and libegl.dll?
Thanks in advance.

SDL currently doesn’t build OpenGL ES support on Windows.

To enable this, you’ll have to at least add this line to
SDL_config_windows.h:
#define SDL_VIDEO_OPENGL_ES2 1

I haven’t tried this, so please let us know how it goes!On Tue, Jun 18, 2013 at 12:30 AM, leanid <leanid.chaika at gmail.com> wrote:

**
I want to use angleproject(https://code.google.com/p/angleproject/) with
SDL2 on windows for opengl es 2.0.
How to compile SDL2.dll to use libglesv2.dll and libegl.dll?
Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

ANGLE support would be a good idea. At the moment it probably isn’t
possible, as there aren’t any hooks in the Windows SDL code for managing
contexts with EGL. There was talk a little while back of consolidating the
various platform-specific EGL backends into a common one; if that gets
done, it should be easy to add a shim for Windows to latch onto it.On 19 June 2013 14:18, Sam Lantinga wrote:

SDL currently doesn’t build OpenGL ES support on Windows.

To enable this, you’ll have to at least add this line to
SDL_config_windows.h:
#define SDL_VIDEO_OPENGL_ES2 1

I haven’t tried this, so please let us know how it goes!

On Tue, Jun 18, 2013 at 12:30 AM, leanid <leanid.chaika at gmail.com> wrote:

**
I want to use angleproject(https://code.google.com/p/angleproject/) with
SDL2 on windows for opengl es 2.0.
How to compile SDL2.dll to use libglesv2.dll and libegl.dll?
Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

At one point, someone had proposed an OpenGL ES unification for mobile SDL
platforms. The next logical step after that is to drop the Direct3D
renderer and just use ANGLE/OpenGL ES in Windows :slight_smile:

GregoryOn Tue, 18 Jun 2013, Sam Lantinga wrote:

SDL currently doesn’t build OpenGL ES support on Windows.

To enable this, you’ll have to at least add this line to
SDL_config_windows.h:
#define SDL_VIDEO_OPENGL_ES2 1

I haven’t tried this, so please let us know how it goes!

On Tue, Jun 18, 2013 at 12:30 AM, leanid <leanid.chaika at gmail.com> wrote:

**
I want to use angleproject(https://code.google.com/p/angleproject/) with
SDL2 on windows for opengl es 2.0.
How to compile SDL2.dll to use libglesv2.dll and libegl.dll?
Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

It that was the idea they’d have dropped Direct3D by now since OpenGL
support is already there for Windows :stuck_out_tongue:

2013/6/19, Gregory Smith :> At one point, someone had proposed an OpenGL ES unification for mobile SDL

platforms. The next logical step after that is to drop the Direct3D
renderer and just use ANGLE/OpenGL ES in Windows :slight_smile:

Gregory

On Tue, 18 Jun 2013, Sam Lantinga wrote:

SDL currently doesn’t build OpenGL ES support on Windows.

To enable this, you’ll have to at least add this line to
SDL_config_windows.h:
#define SDL_VIDEO_OPENGL_ES2 1

I haven’t tried this, so please let us know how it goes!

On Tue, Jun 18, 2013 at 12:30 AM, leanid <leanid.chaika at gmail.com> wrote:

**
I want to use angleproject(https://code.google.com/p/angleproject/) with
SDL2 on windows for opengl es 2.0.
How to compile SDL2.dll to use libglesv2.dll and libegl.dll?
Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi. I spend whole week and manage to build ANGLE(libEGL.dll, libGLESv2.dll) for mingw4.8.1 and msvc2012express and use it with SDL2.0.
I create window using SDL and use hWnd from newly created window with GLES2.0 from ANGLE. All works even switch to fullscreen and back to window
mode.

Code:

#include “window.hpp”

#include
#include
#include
#include

#include <boost/numeric/conversion/cast.hpp>

#include <SDL2/SDL_syswm.h>
#include <SDL2/SDL_assert.h>

#include “application.hpp”
#include “ini.hpp”
#include “graphics/opengl_es_2_0_render.hpp”
#include “graphics/ogl_internal.hpp”

namespace lge
{
#if defined(WIN32) && !defined(USE_GLEW_ON_WIN)
typedef struct
{
/// Window width
GLint width;
/// Window height
GLint height;
/// Window handle
EGLNativeWindowType hWnd;
/// EGL display
EGLDisplay eglDisplay;
/// EGL context
EGLContext eglContext;
/// EGL surface
EGLSurface eglSurface;
} ESContext;

EGLBoolean CreateEGLContext ( EGLNativeWindowType hWnd, EGLDisplay* eglDisplay,
EGLContext* eglContext, EGLSurface* eglSurface,
EGLint* configAttribList, EGLint* surfaceAttribList)
{
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
EGLDisplay display;
EGLContext context;
EGLSurface surface;
EGLConfig config;
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };

// Get Display
display = eglGetDisplay(GetDC(hWnd)); // EGL_DEFAULT_DISPLAY
if ( display == EGL_NO_DISPLAY )
{
return EGL_FALSE;
}

// Initialize EGL
if ( !eglInitialize(display, &majorVersion, &minorVersion) )
{
return EGL_FALSE;
}

// Get configs
if ( !eglGetConfigs(display, NULL, 0, &numConfigs) )
{
return EGL_FALSE;
}

// Choose config
if ( !eglChooseConfig(display, configAttribList, &config, 1, &numConfigs) )
{
return EGL_FALSE;
}

// Create a surface
surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, surfaceAttribList);
if ( surface == EGL_NO_SURFACE )
{
return EGL_FALSE;
}

// Create a GL context
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs );
if ( context == EGL_NO_CONTEXT )
{
return EGL_FALSE;
}

// Make the context current
if ( !eglMakeCurrent(display, surface, surface, context) )
{
return EGL_FALSE;
}

*eglDisplay = display;
*eglSurface = surface;
eglContext = context;
return EGL_TRUE;
}
static ESContext
es_context = nullptr;
#endif

Window::Window() :
sdl_window_(nullptr, SDL_DestroyWindow), sdl_gl_context_(nullptr,
SDL_GL_DeleteContext), window_mode_width_(0), window_mode_height_(
0), fullscreen_(false)
{
if (0
!= SDL_Init(
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO
| SDL_INIT_JOYSTICK))
{
SDL_Log(“can’t init sdl”);
throw std::runtime_error(“Unable to initialize SDL”);
}
atexit(SDL_Quit);

Ini& ini = get_app().get_ini();
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, ini.get_gl_major());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, ini.get_gl_minor());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, ini.get_gl_profile());

// TODO BCB 5ABL ?>1;5<0, 5A;8 7405< >:=> :>B>@>5 =5 A>>B25BAB2C5B
// @07<5<C 1CD5 at 0 B> 2K2>4 >?5=e 1C45B =0 25AL 1CD5@ 0 =5 =0 >:=>
// =0?@8<5@ 5A;8 >:=> A>740=> 400 =0 400 B> 1CD5@ 1C45B 640 =0 480 8 :0 at B8=:0
// 1C45B A<5I5=0 2 >:=5 8 G0AB8G=> =5 284=0
// Create an application window with the following settings:
fullscreen_ = ini.is_fullscreen();
int fullscreen = fullscreen_ ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
std::unique_ptr<SDL_Window, void ()(SDL_Window)> window(
SDL_CreateWindow(ini.get_title().c_str(), // const char* title
SDL_WINDOWPOS_UNDEFINED, // int x: initial x position
SDL_WINDOWPOS_UNDEFINED, // int y: initial y position
ini.get_window_width(), // int w: width, in pixels
ini.get_window_height(), // int h: height, in pixels
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | fullscreen), SDL_DestroyWindow);
if (!window)
{
SDL_Log(“Could not create window: %s\n”, SDL_GetError());
throw std::runtime_error(“can’t create SDL Window”);
}

sdl_window_.swap(window);

#if defined(WIN32) && !defined(USE_GLEW_ON_WIN)
SDL_SysWMinfo info;
SDL_VERSION(&info.version); // initialize info structure with SDL version info
SDL_bool get_win_info = SDL_GetWindowWMInfo(sdl_window_.get(), &info);
SDL_assert_release(get_win_info);
EGLNativeWindowType hWnd = info.info.win.window;

SDL_assert_release(es_context == nullptr);
es_context = new ESContext();

es_context->width = get_width();
es_context->height = get_height();
es_context->hWnd = hWnd;

EGLint configAttribList[] =
{
	EGL_RED_SIZE,       8,
	EGL_GREEN_SIZE,     8,
	EGL_BLUE_SIZE,      8,
	EGL_ALPHA_SIZE,     8 /*: EGL_DONT_CARE*/,
	EGL_DEPTH_SIZE,     EGL_DONT_CARE,
	EGL_STENCIL_SIZE,   EGL_DONT_CARE,
	EGL_SAMPLE_BUFFERS, 0,
	EGL_NONE
};
EGLint surfaceAttribList[] =
{
	//EGL_POST_SUB_BUFFER_SUPPORTED_NV, flags & (ES_WINDOW_POST_SUB_BUFFER_SUPPORTED) ? EGL_TRUE : EGL_FALSE,
	EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_FALSE,
	EGL_NONE, EGL_NONE
};

if ( es_context == nullptr )
{
	throw std::runtime_error("can't create opengl es 2.0 context, NULL es_context");
}

EGLBoolean is_context_created = CreateEGLContext(es_context->hWnd,
		&es_context->eglDisplay,
		&es_context->eglContext,
		&es_context->eglSurface,
		configAttribList,
		surfaceAttribList);

if (is_context_created == 0)
{
	throw std::runtime_error("can't create opengl es 2.0 context");
}

#else
std::unique_ptr<void, void ()(void)> gl_context(
SDL_GL_CreateContext(sdl_window_.get()), SDL_GL_DeleteContext);
if (!gl_context)
{
std::stringstream ss;
ss << “can’t create opengl context " << SDL_GetError();
SDL_Log(”%s", ss.str().c_str());
throw std::runtime_error(ss.str());
}
sdl_gl_context_.swap(gl_context);
int result = SDL_GL_SetSwapInterval(0);
SDL_assert(0 == result);
#endif
}

Window::~Window()
{
#if defined(WIN32) && !defined(USE_GLEW_ON_WIN)
if (es_context)
{
if (EGL_NO_CONTEXT != es_context->eglContext)
{
eglDestroyContext(es_context->eglDisplay, es_context->eglContext);
es_context->eglContext = EGL_NO_CONTEXT;
}

	if (EGL_NO_SURFACE != es_context->eglSurface)
	{
		eglDestroySurface(es_context->eglDisplay, es_context->eglSurface);
		es_context->eglSurface = EGL_NO_SURFACE;
	}

	if (EGL_NO_DISPLAY != es_context->eglDisplay)
	{
		eglTerminate(es_context->eglDisplay);
		es_context->eglDisplay = EGL_NO_DISPLAY;
	}

	delete es_context;
	es_context = nullptr;
}

#endif
}

size_t Window::get_width() const
{
SDL_assert(sdl_window_);
int w = 0;
int h = 0;
SDL_GetWindowSize(sdl_window_.get(), &w, &h);
return boost::numeric_cast<size_t>(w);
}

size_t Window::get_height() const
{
SDL_assert(sdl_window_);
int w = 0;
int h = 0;
SDL_GetWindowSize(sdl_window_.get(), &w, &h);
return boost::numeric_cast<size_t>(h);
}

float Window::get_aspect() const
{
SDL_assert(sdl_window_);
int w = 0;
int h = 0;
SDL_GetWindowSize(sdl_window_.get(), &w, &h);
return float(h) / w;
}

glm::vec2 Window::get_size() const
{
return glm::vec2(get_width(), get_height());
}

bool Window::is_fullscreen() const
{
return fullscreen_;
}

void Window::set_fullscreen(bool value)
{
if (value)
{
if (!is_fullscreen())
{
SDL_GetWindowSize(sdl_window_.get(),
&window_mode_width_, &window_mode_height_);
#ifdef LINUX
int display_index = SDL_GetWindowDisplayIndex(sdl_window_.get());
SDL_assert_release(display_index >= 0);
SDL_DisplayMode desktom_mode;
int result = SDL_GetDesktopDisplayMode(display_index, &desktom_mode);
SDL_assert_release(0 == result);
SDL_SetWindowSize(sdl_window_.get(), desktom_mode.w, desktom_mode.h);
SDL_SetWindowBordered(sdl_window_.get(), SDL_FALSE);
SDL_SetWindowPosition(sdl_window_.get(), 0, 0);
#else
{
int result = SDL_SetWindowFullscreen(sdl_window_.get(),
SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_assert_release(0 == result);
}
#endif
}
} else
{
if (is_fullscreen())
{
int result = SDL_SetWindowFullscreen(sdl_window_.get(), SDL_FALSE);
SDL_assert_release(0 == result);
SDL_SetWindowSize(sdl_window_.get(), window_mode_width_,
window_mode_height_);
#ifdef LINUX
SDL_SetWindowBordered(sdl_window_.get(), SDL_TRUE);
#endif
}
}
fullscreen_ = value;
get_app().get_graphics().update_viewport_size();
}

void Window::set_title(const std::string& title)
{
SDL_SetWindowTitle(sdl_window_.get(), title.c_str());
}

void Window::swap_buffers()
{
#if defined(WIN32) && !defined(USE_GLEW_ON_WIN)
eglSwapBuffers( es_context->eglDisplay, es_context->eglSurface );
#else
SDL_GL_SwapWindow(sdl_window_.get());
#endif

get_app().get_time_system().update();

}

} /* namespace leo */

Thanks leanid!!

Wow what luck, that you should post that right before I was looking for it.

I hope this will be integrated into the main branch soon. It would be very useful for targeting older hardware with poor or no opengl 2.0 support but which is still perfectly capable of running (casual) games via direct3d 9.0.