I am at this moment using SDL just for testing purposes. Whilst using EGL, I have found quite straight forward using this API with Win32 API. In Win32, all I have to do is link the hwnd pointer, which handles the createWindow function to the third parameter in eglCreateWindowSurface() function. But in SDL, I do not know which pointer function to place, or anything. Here is an example of the code i have worked with.
Here is my code
Code:
#include <vg/egl.h>
#include <gles/gl.h>
#include <vg/openvg.h>
#include <vg/vgu.h>
#include <sdl.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#define COLOR_SPACE EGL_COLORSPACE_sRGB
#define ALPHA_FORMAT EGL_ALPHA_FORMAT_NONPRE
#define SURFACE_TYPE EGL_WINDOW_BIT | EGL_PBUFFER_BIT
#define PBUFFER_WIDTH 256
#define PBUFFER_HEIGHT 256
EGLDisplay egldisplay;
EGLConfig eglconfig;
EGLContext eglContextOpenGLES;
EGLContext eglContextTexture;
EGLContext eglContextRenderer;
EGLSurface eglWindowSurface;
EGLSurface eglPBufferSurface;
bool active = true;
int width;
int height;
void closeApplication()
{
eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(egldisplay);
}
static void setGLESperspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zNear * (GLfloat)tan(fovy * 3.1415962f / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}
SDL_Surface* initSDL(int Swidth, int Sheight, char *AppName){
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption(AppName,AppName);
SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"), NULL);
SDL_SetVideoMode(Swidth,Sheight, 32, SDL_SWSURFACE | SDL_HWSURFACE);// | SDL_FULLSCREEN );
return 0;
}
int main(int argc, char **argv)
{
float aspect = height ? (float)width/(float)height : 1.0f;
width = 640; height = 480;
SDL_Surface* screen = initSDL(width,height,&"SDL - EGL BINDINGS - April 2006 - DWilson");
static const EGLint s_surfaceAttribs[] =
{
EGL_COLORSPACE, COLOR_SPACE,
EGL_ALPHA_FORMAT, ALPHA_FORMAT,
EGL_NONE
};
static const EGLint s_configAttribs[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_LUMINANCE_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, SURFACE_TYPE,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT & EGL_OPENGL_ES_BIT,
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
EGL_NONE
};
static const EGLint s_pbufferAttribs[] =
{
EGL_WIDTH, PBUFFER_WIDTH,
EGL_HEIGHT, PBUFFER_HEIGHT,
EGL_COLORSPACE, COLOR_SPACE,
EGL_ALPHA_FORMAT, ALPHA_FORMAT,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_NONE
};
EGLint majorVersion;
EGLint minorVersion;
egldisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(egldisplay, &majorVersion, &minorVersion);
EGLint numconfigs;
eglGetConfigs(egldisplay, NULL, 0, &numconfigs);
eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs);
//create a rendering surface and a context
eglWindowSurface = eglCreateWindowSurface(egldisplay, eglconfig, (SDL_Surface*)screen, s_surfaceAttribs);
eglPBufferSurface = eglCreatePbufferSurface(egldisplay, eglconfig, s_pbufferAttribs);
eglContextRenderer = eglCreateContext(egldisplay, eglconfig, NULL, NULL);
eglBindAPI (EGL_OPENGL_ES_API);
eglContextOpenGLES = eglCreateContext(egldisplay, eglconfig, NULL, NULL);
eglMakeCurrent(egldisplay, eglWindowSurface, eglWindowSurface, eglContextOpenGLES);
glViewport (0, 0, width, height);
glScissor (0, 0, width, height);
glMatrixMode (GL_MODELVIEW);
/* Update the projection matrix */
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
setGLESperspective (60.f, aspect, 0.1f, 100.f);
while(active){
Uint8 *keystate = SDL_GetKeyState(NULL);
SDL_Event event;
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
active = false; //Quit the program
}
}
if ( keystate[SDLK_ESCAPE]){
active = false;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}
closeApplication();
return 0;
}
The code is self explanatory as you may have noticed. I have tried many versions and re-written the code several times, but it is in more stable form, except for a line of code that is causing a major flaw in the application. The Pbuffer is working ok as I have had it checked and debugged, but the main window isnt rendering due to this line eglWindowSurface = eglCreateWindowSurface(egldisplay, eglconfig, (SDL_Surface*)screen, s_surfaceAttribs);
I have been using openGL for many years, but I am relatively new to EGL, and SDL. I know it is possible, as I have seen the same usage of EGL in native 1998 version of GLUT. I assume that if GLUT can handle it, SDL must be able to as it is an window management wrapper for all OS especially Windows.
If anyone could help me, it would be greatly appreciated
Regards
Dave