Quote Originally Posted by jdarling
Ok, so I've been playing more and more with S2DL while trying to get things wrapped up on a few projects. Now I have a few questions:

1) How exactly do I resize the SDL window once its open, and can this be done in mid render (IE: After the clear and before the flip)?
2) How do I go about switching between full screen and windowed mode?
3) Is there a way to load any 3D model formats?
4) Why do some MS Paint bitmap images not render properly (color is all off)
5) Where is the support for GLSL, or should I make use of the standard OpenGL version? Also any samples?
6) Any frigging tutorials out there, not just samples, but tutorials ?
7) Is S2DL only for 2D SDL applications, or have I not figured out how to integrate 3D yet ? (I'm guessing that since its Simple 2D that its only for 2D)

Anyways, I know some of the questions will seem a bit ignorant, but I have to ask . Thanks for any answers.
I am not sure about the other questions, but for using GLSL I made a helper unit.

It uses glext.pas that came with JEDI-SDL (you may be able to use that too).

At the moment, it only supports

GL_ARB_Vertex_Shader, GL_ARB_Fragment_Shader and GL_ARB_Program, but the classes can be overriden so that other versions could be used

Initializing and loading shaders:

[code] If (Load_GL_ARB_shader_objects) And (Load_GL_ARB_vertex_shader) And (Load_GL_ARB_fragment_shader) Then
Begin
FShaders[0] := TGL_ARB_Vertex_Shader.Create;
FShaders[1] := TGL_ARB_Fragment_Shader.Create;

Try
If (Not FShaders[0].LoadAndCompileShaderSource&#40 ;'pointlight.vert')) Then
Logger.LogError(FShaders[0].GetInfoLog ,'''pointlight.vert''');

If (Not FShaders[1].LoadAndCompileShaderSource&#40 ;'pointlight.frag')) Then
Logger.LogError(FShaders[1].GetInfoLog ,'''pointlight.frag''');
Except
On E:Exception Do
Logger.LogError(E.Message,'');
End;

FShaderProgram := TGL_ARB_Program.Create;

For i := 0 To High(FShaders) Do
FShaderProgram.AttachShader(FShaders[i&#93 ;);

FShaderProgram.]

Using shaders:
Code:
    FShaderProgram.Enable;

    //  draw balls
    For i := 0 To FBalls.Count - 1 Do
    Begin
        Ball := TNewtonObject(FBalls.Objects[i]);

        FShaderProgram.SetUniform('MaterialAmbient',
            [
                PlayerColours[Ball.Tag].r * 0.3,
                PlayerColours[Ball.Tag].g * 0.3,
                PlayerColours[Ball.Tag].b * 0.3,
                1
            ]);

        FShaderProgram.SetUniform('MaterialDiffuse',
            [
                PlayerColours[Ball.Tag].r,
                PlayerColours[Ball.Tag].g,
                PlayerColours[Ball.Tag].b,
                1
            ]);

        FShaderProgram.SetUniform('MaterialSpecular',
            [
                0.9,0.9,0.9,1
            ]);

        FShaderProgram.SetUniform('MaterialShininess',[50]);


        Ball.Render;

        //  draw balls selection
        If (Ball.Selected) Then
            RenderBallSelection(Ball);
    End;

    FShaderProgram.Disable;
Vertex shader:
Code:
/* -------------------------------------------------------
This shader implements a point light per pixel using  the
diffuse, specular, and ambient terms acoording to "Mathematics of Lighthing"
as found in the book "OpenGL Programming Guide" (aka the Red Book)
--------------------------------------------------------- */

varying vec4 diffuse,ambientGlobal,ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;

uniform vec4 MaterialAmbient;
uniform vec4 MaterialDiffuse;
void main()
{	
	vec4 ecPos;
	vec3 aux;
	
	/* first transform the normal into eye space and normalize the result */
	normal = normalize(gl_NormalMatrix * gl_Normal);
	
	/* now normalize the light's direction. Note that according to the
	OpenGL specification, the light is stored in eye space. Also since 
	we're talking about a directional light, the position field is actually 
	direction */
	ecPos = gl_ModelViewMatrix * gl_Vertex;
	aux = vec3(gl_LightSource[0].position-ecPos);
	lightDir = normalize(aux);
	
	/* compute the distance to the light source to a varying variable*/
	dist = length(aux);

	/* Normalize the halfVector to pass it to the fragment shader */
	halfVector = normalize(gl_LightSource[0].halfVector.xyz);
	
	/* Compute the diffuse, ambient and globalAmbient terms */
/*
	diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
	ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
	ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
*/

	diffuse = MaterialDiffuse * gl_LightSource[0].diffuse;
	ambient = MaterialAmbient * gl_LightSource[0].ambient;
	ambientGlobal = gl_LightModel.ambient * MaterialAmbient;

	gl_Position = ftransform();
}
Fragment shader:

Code:
/* -------------------------------------------------------

This shader implements a point light per pixel using  the 
diffuse, specular, and ambient terms acoording to "Mathematics of Lighthing" 
as found in the book "OpenGL Programming Guide" (aka the Red Book)

--------------------------------------------------------- */

varying vec4 diffuse,ambientGlobal,ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;

uniform float MaterialShininess;
uniform vec4 MaterialSpecular;

void main()
{
	vec3 n,halfV,viewV,ldir;
	float NdotL,NdotHV;
	vec4 color = ambientGlobal;
	float att;
	
	/* a fragment shader can't write a verying variable, hence we need
	a new variable to store the normalized interpolated normal */
	n = normalize(normal);
	
	/* compute the dot product between normal and ldir */
	NdotL = max(dot(n,normalize(lightDir)),0.0);

	if (NdotL > 0.0) {
	
/*  att = 1.0 / (gl_LightSource[0].constantAttenuation +
      gl_LightSource[0].linearAttenuation * dist +
      gl_LightSource[0].quadraticAttenuation * dist * dist);*/

		att = 1.0;
		color += att * (diffuse * NdotL + ambient);
		
		halfV = normalize(halfVector);
		NdotHV = max(dot(n,halfV),0.0);
/*		color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV,gl_FrontMaterial.shininess);*/
		color += att * MaterialSpecular * gl_LightSource[0].specular * pow(NdotHV,MaterialShininess);
	}

	gl_FragColor = color;
}
Unit code
Code:
Unit GL_Shaders;
{.......................................................}
//  created by Paul Nicholls
//  Copyright 2006
//  Use for anything that you want, but
//  please email me with any improvements that you may make :)
//
//  Email:
//  paul_nicholls.hotmail.com
{.......................................................}
Interface

Uses
    gl,
    glext;

Type
    TGL_Shader = Class
    Private
    Protected
        FHandle: GLuint;
    Public

        Function  LoadAndCompileShaderSource(AFileName: String): Boolean; Virtual;

        Function  GetInfoLog: String;                                     Virtual;

        Property Handle: GLuint Read FHandle;
    End;

    TGL_ARB_Shader = Class(TGL_Shader)
    Protected
    Public
        Constructor Create;   Virtual;
        Destructor  Destroy;  Override;

        Function  LoadAndCompileShaderSource(AFileName: String): Boolean; Override;

        Function  GetInfoLog: String;                                     Override;
    End;

    TGL_ARB_Vertex_Shader = Class(TGL_ARB_Shader)
    Private
    Public
        Constructor Create;   Override;
        Destructor  Destroy;  Override;
    End;

    TGL_ARB_Fragment_Shader = Class(TGL_ARB_Shader)
    Private
    Public
        Constructor Create;   Override;
        Destructor  Destroy;  Override;
    End;

    TGL_Program = Class
    Private
    Protected
        FHandle: GLuint;
    Public
        Constructor Create;                                                        Virtual;
        Destructor  Destroy;                                                       Override;

        Procedure AttachShader(Const AShader: TGL_Shader);                         Virtual;
        Procedure Link;                                                            Virtual;
        Procedure Enable;                                                          Virtual;
        Procedure Disable;                                                         Virtual;

        Procedure SetUniform(Const AName: String;
                             Const AValue: GLint);             Overload;         Virtual;
        Procedure SetUniform(Const AName: String;
                             Const AValues: Array Of GLfloat); Overload;         Virtual;
    End;

    TGL_ARB_Program = Class(TGL_Program)
    Public
        Constructor Create;                                                        Override;
        Destructor  Destroy;                                                       Override;

        Procedure AttachShader(Const AShader: TGL_Shader);                         Override;
        Procedure Link;                                                            Override;
        Procedure Enable;                                                          Override;
        Procedure Disable;                                                         Override;

        Procedure SetUniform(Const AName: String;
                             Const AValue: GLint);             Overload;         Override;
        Procedure SetUniform(Const AName: String;
                             Const AValues: Array Of GLfloat); Overload;         Override;
    End;

Implementation

Uses
    SysUtils,Classes;

Function  TGL_Shader.LoadAndCompileShaderSource(AFileName: String): Boolean;
Begin
    Result := False;
End;
{.......................................................}

{.......................................................}
Function  TGL_Shader.GetInfoLog: String;
Begin
    Result := '';
End;
{.......................................................}

{.......................................................}
Constructor TGL_ARB_Shader.Create;
Begin
    Inherited Create;

    FHandle := 0;
End;
{.......................................................}

{.......................................................}
Destructor  TGL_ARB_Shader.Destroy;
Begin
    If &#40;FHandle <> 0&#41; Then
        glDeleteObjectARB&#40;FHandle&#41;;

    Inherited Destroy;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Function  TGL_ARB_Shader.LoadAndCompileShaderSource&#40;AFileName&#58; String&#41;&#58; Boolean;
Var
    ShaderSource  &#58; TStringList;
    Source        &#58; String;
    LinkStatus    &#58; GLint;
    CompileStatus &#58; GLint;
    SourceLength  &#58; Integer;
Begin
    Result &#58;= False;

    If &#40;Not FileExists&#40;AFileName&#41;&#41; Then
        Exit;

    ShaderSource &#58;= TStringList.Create;

    Try
        ShaderSource.LoadFromFile&#40;AFileName&#41;;

        If &#40;ShaderSource.Text = ''&#41; Then
            Exit;

        Source &#58;= ShaderSource.Text;

        SourceLength &#58;= Length&#40;Source&#41;;

        glShaderSourceARB&#40;FHandle,1,@Source,@SourceLength&#41;;

        glCompileShaderARB&#40;FHandle&#41;;

        glGetObjectParameterivARB&#40;FHandle,GL_OBJECT_LINK_STATUS_ARB   , @LinkStatus&#41;;
        glGetObjectParameterivARB&#40;FHandle,GL_OBJECT_COMPILE_STATUS_ARB, @CompileStatus&#41;;

        Result &#58;= &#40;LinkStatus = 1&#41; And &#40;CompileStatus = 1&#41;;
    Finally
        ShaderSource.Free;
    End;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Function  TGL_ARB_Shader.GetInfoLog&#58; String;
Var
    InfoLog       &#58; PGLcharARB;
    InfoLogLength &#58; GLint;
Begin
    glGetObjectParameterivARB&#40;FHandle,GL_OBJECT_INFO_LOG_LENGTH_ARB,@InfoLogLength&#41;;

    GetMem&#40;InfoLog,InfoLogLength + 1&#41;;

    glGetInfoLogARB&#40;FHandle,InfoLogLength,@InfoLogLength,InfoLog&#41;;

    Result &#58;= String&#40;InfoLog&#41;;

    FreeMem&#40;InfoLog,InfoLogLength + 1&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Constructor TGL_ARB_Vertex_Shader.Create;
Begin
    Inherited Create;

    FHandle &#58;= glCreateShaderObjectARB&#40;GL_VERTEX_SHADER_ARB&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Destructor  TGL_ARB_Vertex_Shader.Destroy;
Begin
    Inherited Destroy;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Constructor TGL_ARB_Fragment_Shader.Create;
Begin
    Inherited Create;

    FHandle &#58;= glCreateShaderObjectARB&#40;GL_FRAGMENT_SHADER_ARB&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Destructor  TGL_ARB_Fragment_Shader.Destroy;
Begin
    Inherited Destroy;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Constructor TGL_Program.Create;
Begin
    Inherited Create;

    FHandle &#58;= 0;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Destructor  TGL_Program.Destroy;
Begin
    If &#40;FHandle <> 0&#41; Then
        glDeleteObjectARB&#40;FHandle&#41;;

    Inherited Destroy;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.AttachShader&#40;Const AShader&#58; TGL_Shader&#41;;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.Link;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.Enable;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.Disable;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.SetUniform&#40;Const AName&#58; String;
                                 Const AValue&#58; GLint&#41;;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_Program.SetUniform&#40;Const AName&#58; String;
                                 Const AValues&#58; Array Of GLfloat&#41;;
Begin
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Constructor TGL_ARB_Program.Create;
Begin
    Inherited Create;

    FHandle &#58;= glCreateprogramObjectARB;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Destructor  TGL_ARB_Program.Destroy;
Begin
    Inherited Destroy;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.AttachShader&#40;Const AShader&#58; TGL_Shader&#41;;
Begin
    glAttachObjectARB&#40;FHandle,AShader.Handle&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.Link;
Begin
    glLinkProgramARB&#40;FHandle&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.Enable;
Begin
    glUseProgramObjectARB&#40;FHandle&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.Disable;
Begin
    glUseProgramObjectARB&#40;0&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.SetUniform&#40;Const AName&#58; String;
                                     Const AValue&#58; GLint&#41;;
Begin
    glUniform1iARB&#40;glGetUniformLocationARB&#40;FHandle,PGLCharArb&#40;AName&#41;&#41;,
        AValue&#41;;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
Procedure TGL_ARB_Program.SetUniform&#40;Const AName&#58; String;
                                     Const AValues&#58; Array Of GLfloat&#41;;
Var
    ParamCount&#58; Integer;
    NameArb   &#58; PGLCharArb;
Begin
    ParamCount &#58;= Length&#40;AValues&#41;;

    NameArb &#58;= PGLCharArb&#40;AName&#41;;
    
    Case ParamCount Of
        1&#58;  glUniform1fARB&#40;glGetUniformLocationARB&#40;FHandle, NameArb&#41;,
                AValues&#91;0&#93;&#41;;
        2&#58;  glUniform2fARB&#40;glGetUniformLocationARB&#40;FHandle, NameArb&#41;,
                AValues&#91;0&#93;,AValues&#91;1&#93;&#41;;
        3&#58;  glUniform3fARB&#40;glGetUniformLocationARB&#40;FHandle, NameArb&#41;,
                AValues&#91;0&#93;,AValues&#91;1&#93;,AValues&#91;2&#93;&#41;;
        4&#58;  glUniform4fARB&#40;glGetUniformLocationARB&#40;FHandle, NameArb&#41;,
                AValues&#91;0&#93;,AValues&#91;1&#93;,AValues&#91;2&#93;,AValues&#91;3&#93;&#41;;
    Else
    End;
End;
&#123;.......................................................&#125;

&#123;.......................................................&#125;
End.