I found here Sample Code about DGLOpenGL and DGLShader.
and i am trying to use Opengl Some Effect . For this i am trying to do Effect Plugin and i want create Shader in Plugin
But when you try to create shader in Plugin Dll its make error.
i found This code. its work there is not problem
Code:
begin
InitOpenGL;
DC := GetDC ( form1.Handle );
ShowCursor ( FALSE );
pfd.dwFlags := PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER;
SetPixelFormat ( DC, ChoosePixelFormat ( DC, @pfd ), @pfd );
ActivateRenderingContext( DC, wglCreateContext ( DC ), TRUE );
DemoStart := GetTickCount;
ElapsedTime:=1;
//load simple glsl shader
glslsimpleprog := TGLSLProgram.Create();
glslsimplevert := TGLSLShader.Create('simple.vert');
glslsimplefrag := TGLSLShader.Create('simple.frag', GL_FRAGMENT_SHADER_ARB);
glslsimpleprog.Attach(glslsimplevert);
glslsimpleprog.Attach(glslsimplefrag);
glslsimpleprog.Link;
glslsimpleprog.Enable;
glslsimpleprog.Set2F('resolution',640*2,480*2);
glslsimpleprog.Set2F('mouse',0,0);
WHILE GetAsyncKeyState ( 27 ) = 0 DO
BEGIN
glslsimpleprog.setf('time', elapsedtime/320);
glLoadIdentity;
glBegin ( GL_QUADS );
glTexCoord2f ( 0.0, 0.0 ); glVertex3f ( -320, -240, 0 );
glTexCoord2f ( 1.0, 0.0 ); glVertex3f ( 320, -240, 0 );
glTexCoord2f ( 1.0, 1.0 ); glVertex3f ( 320, 240, 0 );
glTexCoord2f ( 0.0, 1.0 ); glVertex3f ( -320, 240, 0 );
glEnd;
LastTime := ElapsedTime;
{ Calculate Elapsed Time }
ElapsedTime := GetTickCount - DemoStart;
{ average it out for smoother movement }
ElapsedTime := ( LastTime + ElapsedTime ) DIV 2;
SwapBuffers ( DC )
END ;
end;
Ok. if You change this code and if you Move Shader in Dll Like bellow; its make error EXTERNAL SIGSEGV
Some One have any idea how to i can create shader in dll ?
MainApplication
Code:
VAR
DemoStart, LastTime : DWORD;
ElapsedTime : INTEGER;
glslsimplevert,
glslsimplefrag : TGLSLShader;
glslsimpleprog : TGLSLProgram;
pfd : TPixelFormatDescriptor;
DC : HDC;
begin
InitOpenGL;
DC := GetDC ( form1.Handle );
ShowCursor ( FALSE );
pfd.dwFlags := PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER;
SetPixelFormat ( DC, ChoosePixelFormat ( DC, @pfd ), @pfd );
ActivateRenderingContext( DC, wglCreateContext ( DC ), TRUE );
DemoStart := GetTickCount;
ElapsedTime:=1;
//load simple glsl shader
glslsimpleprog:=GLRender(glslsimpleprog); // i wrote GLRender Function in a DLL
WHILE GetAsyncKeyState ( 27 ) = 0 DO
BEGIN
glslsimpleprog.setf('time', elapsedtime/320);
glLoadIdentity;
glBegin ( GL_QUADS );
glTexCoord2f ( 0.0, 0.0 ); glVertex3f ( -320, -240, 0 );
glTexCoord2f ( 1.0, 0.0 ); glVertex3f ( 320, -240, 0 );
glTexCoord2f ( 1.0, 1.0 ); glVertex3f ( 320, 240, 0 );
glTexCoord2f ( 0.0, 1.0 ); glVertex3f ( -320, 240, 0 );
glEnd;
LastTime := ElapsedTime;
{ Calculate Elapsed Time }
ElapsedTime := GetTickCount - DemoStart;
{ average it out for smoother movement }
ElapsedTime := ( LastTime + ElapsedTime ) DIV 2;
SwapBuffers ( DC )
END ;
end;
DLL
Code:
library dll2;
{$mode objfpc}{$H+}
uses
Classes ,windows , DGLShader,DGLOpengl
{ you can add units after this };
VAR
glslsimplevert,
glslsimplefrag : TGLSLShader;
glslsimpleprog : TGLSLProgram;
Function GLRender(glslsimpleprog:TGLSLProgram):TGLSLProgram;stdcall;
begin
glslsimpleprog := TGLSLProgram.Create();
glslsimplevert := TGLSLShader.Create('simple.vert');
glslsimplefrag := TGLSLShader.Create('simple.frag', GL_FRAGMENT_SHADER_ARB);
glslsimpleprog.Attach(glslsimplevert);
glslsimpleprog.Attach(glslsimplefrag);
glslsimpleprog.Link;
glslsimpleprog.Enable;
glslsimpleprog.Set2F('resolution',640*2,480*2);
glslsimpleprog.Set2F('mouse',0,0);
result:= glslsimpleprog;
end;
exports
GLRender;
begin
end.
Result:=glCreateProgramObjectARB(); this is make error ...
Code:
// TGLSLProgram
constructor TGLSLProgram.Create();
function GETPO : Integer;
begin
Result:=glCreateProgramObjectARB();// if create program in DLL this is make Error EXERNAL SIGSEGV
end;
begin
FProgramObject:=GETPO;
// FProgramObject := glCreateProgramObjectARB
end;
Bookmarks