Code:
procedure DoOpenGLES();
type
TEGLAttribut = array[0..128] of EGLint;
procedure AddAttribute(var iPos : Integer; var Attr : TEGLAttribut; aType, aValue : EGLInt);
begin
Attr[iPos] := aType; Inc(iPos);
Attr[iPos] := aValue; Inc(iPos);
end;
var
iMajorVersion : EGLint;
iMinorVersion : EGLint;
iLoop : Integer;
iConfigs : integer;
eglAttribs : TEGLAttribut;
myeglDisplay : EGLDisplay;
myeglConfig : EGLConfig;
myeglSurface : EGLSurface;
myeglContext : EGLContext;
eglWindow : NativeWindowType;
Info : TSDL_SysWMinfo;
dc : LongWord;
begin
SDL_VERSION(Info.Version);
if ( SDL_GetWMInfo(@Info) < 0 ) then begin
raise Exception.Create('SDL_GetWMInfo failed!');
end;
iMajorVersion := 0;
iMinorVersion := 0;
myeglDisplay := 0;
myeglConfig := 0;
myeglSurface := nil;
myeglContext := nil;
{$IFDEF WIN32}
eglWindow := Info.window;
dc := GetDC(eglWindow);
if (dc = 0) then begin
raise Exception.Create('GetDC failed!');
end;
{$ELSE}
nanoGL_Init();
eglWindow := OS_CreateWindow();
dc := 0;
{$ENDIF}
Log.Add('');
Log.Add('window handle is: %d', eglWindow);
try
myeglDisplay := eglGetDisplay(dc);
if (myeglDisplay = EGL_BAD_DISPLAY) then begin
raise Exception.Create('eglGetDisplay failed!');
end;
if (eglInitialize(myeglDisplay, @iMajorVersion, @iMinorVersion) = 0)
then begin
raise Exception.Create('eglInitialize failed!');
end;
iLoop := 0;
AddAttribute(iLoop, eglAttribs, EGL_RED_SIZE, 5);
AddAttribute(iLoop, eglAttribs, EGL_GREEN_SIZE, 6);
AddAttribute(iLoop, eglAttribs, EGL_BLUE_SIZE, 5);
AddAttribute(iLoop, eglAttribs, EGL_ALPHA_SIZE, 0);
AddAttribute(iLoop, eglAttribs, EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
AddAttribute(iLoop, eglAttribs, EGL_NONE, 0);
if (eglChooseConfig(myeglDisplay, @eglAttribs, @myeglConfig, 1, @iConfigs) = 0)
then begin
raise Exception.Create('eglChooseConfig failed!');
end;
if (iConfigs = 0) then begin
raise Exception.Create('No compatible open gl es mode found!');
end;
myeglSurface := eglCreateWindowSurface(myeglDisplay, myeglConfig, eglWindow, nil);
if (myeglSurface = nil) then begin
if (eglWindow <> 0) then begin
myeglSurface := eglCreateWindowSurface(myeglDisplay, myeglConfig, 0, @eglAttribs);
end;
if (myeglSurface = nil) then begin
raise Exception.Create('eglCreateWindowSurface failed!');
end;
end;
myeglContext := eglCreateContext(myeglDisplay, myeglConfig, nil, nil);
if (myeglContext = nil) then begin
raise Exception.Create('myeglContext failed!');
end;
Log.Add('EGL Init Completed');
eglMakeCurrent(myeglDisplay, myeglSurface, myeglSurface, myeglContext);
for iLoop := 0 to Pred(100) do begin
if ((iLoop mod 2) = 1) then begin
glClearColor(0.6, 0.8, 1.0, 1.0); // clear blue
end else begin
glClearColor(1.0, 1.0, 0.66, 1.0); // clear yellow
end;
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(myeglDisplay, myeglSurface);
SDL_Delay(10);
end;
finally
if (myeglDisplay <> EGL_BAD_DISPLAY) then begin
eglMakeCurrent(myeglDisplay, nil, nil, nil);
// eglDestroySurface(myeglDisplay, myeglSurface);
// eglDestroyContext(myeglDisplay, myeglContext);
// eglTerminate(myeglDisplay);
end;
{$IFDEF WIN32}
ReleaseDC(eglWindow, dc);
{$ELSE}
//
{$ENDIF}
end;
end;
Code:
function eglCreateWindowSurface(dpy : EGLDisplay; config : EGLConfig; win: NativeWindowType; const attrib_list: PEGLint) : EGLSurface;
begin
if Assigned(peglCreateWindowSurface) then begin
Result := peglCreateWindowSurface(dpy, config, win, attrib_list);
Log.Add('eglCreateWindowSurface called');
Exit;
end;
raise Exception.CreateFmt(cmsgUnknowProc, ['eglCreateWindowSurface']);
end;
I write a log file and after calling eglCreateWindowSurface it stops, no entry is written, that eglCreateWindowSurface was called. On Windows it works.
Bookmarks