Results 1 to 3 of 3

Thread: Create Shader in Dll

  1. #1

    Create Shader in Dll

    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;
    Last edited by SilverWarior; 23-10-2014 at 05:35 AM. Reason: Replace quote fields with code fields

  2. #2
    I don't know if it will help but in dll you have glslsimpleprog var declared and then you use same name and type in GLRender as parameter.


  3. #3
    Thank you. yes its true and i found another problems to ..
    i was tested it yesterday. and i fix error .

    1 InitOpenGL ... in my dll i dint use initOpengl.. This Function LoadOpenGl DLL..
    2 ActiveRendering Context.. ThisFunction must use in DLL...
    3 glslsimpleprog := TGLSLProgram.Create(); ... before i create this variable only in dll or only in main application. When i create this variable in mainapplication and in dll its work..
    4. if i create first Shader and later some Component for Plugın Gui its make error.. But if firstly create shader and last create Component for Plugin ui its work ...


    Quote Originally Posted by laggyluk View Post
    I don't know if it will help but in dll you have glslsimpleprog var declared and then you use same name and type in GLRender as parameter.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •