Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How to use GLSL with JEDI-SDL?

  1. #1

    How to use GLSL with JEDI-SDL?

    Does anyone know of an FPC or Delphi demo that shows how to use the OpenGL shading language with JEDI-SDL? Do I need the latest OpenGL headers? Are the ones that come with FPC or JEDI-SDL good enough?
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

  2. #2

    How to use GLSL with JEDI-SDL?

    The headers that come with FPC/Lazarus are for OpenGL 1.1, so they are definitely too old.
    The headers from JEDI-SDL seem to be outdated too, I'm using the dglOpenGL (http://www.delphigl.com) headers, they should compile on Linux too, but I haven't tried it yet. At least I can compile my test project using the headers with FPC and it runs.
    If you develop an idiot proof system, the nature develops better idiots.

  3. #3

    How to use GLSL with JEDI-SDL?

    The headers in the JEDI-SDL cvs are up to date and support OpenGL 2.0. These are being tested (by me). I have got a basic framework for GLSL I'll try and post it but you will need the headers from cvs for it to work.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  4. #4

    How to use GLSL with JEDI-SDL?

    Thanks, I'd much appreciate that framework.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  5. #5

    How to use GLSL with JEDI-SDL?

    There is a tutorial at http://wiki.delphigl.com/index.php/Tutorial#Shader, but it is in german.

  6. #6

    How to use GLSL with JEDI-SDL?

    Danke sch??n!
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  7. #7

    How to use GLSL with JEDI-SDL?

    I'm having trouble with the shaders... The shader loads just fine and I can set the uniform parameters, but I get "invalid operation" on glEnd();

    Here's the vertex program:
    Code:
    void main&#40;void&#41;
    &#123;
    	gl_TexCoord&#91;0&#93; = gl_MultiTexCoord0;
       gl_Position = ftransform&#40;&#41;;
    &#125;
    Fragment program:
    Code:
    uniform sampler2D colorMap;
    
    void main&#40;void&#41;
    &#123;
    	gl_FragColor = texture2D&#40; colorMap, gl_TexCoord&#91;0&#93;.st&#41;; 
    &#125;
    Here's the test code:
    [pascal]
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, Textures[0]);
    glCheckForError();
    Shader.Enable;
    glCheckForError();
    Shader.SetParameter('colorMap', GL_TEXTURE0_ARB);
    glCheckForError();

    glBegin(GL_QUADS);
    glColor3f(1, 1, 1);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
    glVertex3f(10, -10, -30);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
    glVertex3f(10, 10, -30);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
    glVertex3f(-10, 10, -30);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
    glVertex3f(-10, -10, -30);
    glEnd();
    glCheckForError(); // Error here

    Shader.Disable;
    [/pascal]

    The shader class is just a simple wrapper for loading the programs and setting parameters that I made for testing.

    [pascal]
    unit uShader;
    {
    Project Miniverse
    http://www.projectminiverse.com

    Description:
    GLSL shader object

    Classes:
    TShader

    Created:
    22.04.2006 (JA)

    Modified:

    }

    interface

    uses
    {$IFDEF USE_SDL}
    GL, GLU, GLEXT,
    {$ELSE}
    dglOpenGL,
    {$ENDIF}
    glShader, glGeometry;

    type
    TShader = class(TObject)
    protected
    FProgramObject: GLHandleARB;
    FName: String;
    FResult: String;
    public
    constructor Create(FileName: String); overload;
    constructor Create(const Name, VertexProgram, FragmentProgram: String); overload;
    destructor Destroy; override;

    procedure Enable;
    procedure Disable;
    procedure SetParameter(const Name: String; Value: TInt); overload;
    procedure SetParameter(const Name: String; Value: TFloat); overload;
    procedure SetParameter(const Name: String; Value1, Value2, Value3, Value4: TFloat); overload;

    property Name: String read FName;
    property ProgramObject: GLHandleARB read FProgramObject;
    property Result: String read FResult;
    end;

    implementation

    uses
    glUtils;

    constructor TShader.Create(FileName: String);
    begin
    inherited Create;
    end;

    constructor TShader.Create(const Name, VertexProgram, FragmentProgram: String);
    begin
    inherited Create;
    FName := Name;
    FProgramObject := glShader.LoadFragmentandVertexShader(FragmentProgr am, VertexProgram);
    FResult := glShader.CheckForErrors(FProgramObject);
    glCheckForError();
    end;

    destructor TShader.Destroy;
    begin
    inherited Destroy;
    end;

    procedure TShader.Enable;
    begin
    glUseProgramObjectARB(FProgramObject);
    end;

    procedure TShader.Disable;
    begin
    glUseProgramObjectARB(0);
    end;

    procedure TShader.SetParameter(const Name: String; Value: TInt);
    var
    p: PGLcharARB;
    l: TInt;
    begin
    p := PGLCharArb(Name);
    glUniform1iARB(glGetUniformLocationARB(FProgramObj ect, p), Value);
    end;

    procedure TShader.SetParameter(const Name: String; Value: TFloat);
    var
    p: PGLcharARB;
    l: TInt;
    begin
    p := PGLCharARB(Name);
    glUniform1fARB(glGetUniformLocationARB(FProgramObj ect, p), Value);
    end;

    procedure TShader.SetParameter(const Name: String; Value1, Value2, Value3, Value4: TFloat);
    var
    p: PGLcharARB;
    l: TInt;
    begin
    p := PGLCharARB(Name);
    glUniform4fARB(glGetUniformLocationARB(FProgramObj ect, p), Value1, Value2, Value3, Value4);
    end;

    end.
    [/pascal]

    I tried to search for possible reason, but I can't seem to find any.
    If you develop an idiot proof system, the nature develops better idiots.

  8. #8

    How to use GLSL with JEDI-SDL?

    Doesn't look like a problem with the Shader Programs. I tested the code in the ShaderDesigner and it works. I would first try to get the copde working without a shader (just use the fixed functionality) then add the shader once that is working. There might be a problem in the setup/initialization of the app which is causing the error.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  9. #9

    How to use GLSL with JEDI-SDL?

    It works if I use ARB multitexturing, but as soon as I try to use the shader I get the error.

    I load the ARB extensions for multitexturing and shaders, ie. GL_ARB_multitexture and GL_ARB_shader_objects, do I need something else too? Do I need to initialize the OpenGL pipeline for shaders before using them? Doesn't seem likely as I can load and compile the shaders and the driver says: "Link successful. The GLSL vertex shader will run in hardware. The GLSL fragment shader will run in hardware."

    Here's my OpenGL initialization code:
    [pascal]
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);
    [/pascal]

    Didn't find any documentation to explain what can I do and what I cannot do when using shaders...
    If you develop an idiot proof system, the nature develops better idiots.

  10. #10

    How to use GLSL with JEDI-SDL?

    I'll have a look at something similar here and see if I can get it working.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

Page 1 of 2 12 LastLast

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
  •