Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFSL - Work in progress.  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFSL - Work in progress.
« on: January 28, 2010, 01:56:45 am »
SFSL, otherwise known as Simple Fast Shading Language, will make writing, compiling, and implementing OpenGL Shading Language(GLSL), into your C or C++ program easier than ever! When completed I will post the source & binaries download locations, for everyone to use freely. Currently, I can only offer an example as to how one might use this in its most simplest form. Which you'll see below.
 
SFSL Example
Code: [Select]

vec4 Color;

void myVertexShader()
{
gl_Vertex = gl_ModelViewProjectionMatrix * gl_Vertex;
}

void myFragmentShader()
{
gl_FragColor = Color;
}

// requires at least 1 material
material ExampleMaterial
{
// optional material booleans
AlphaEnabled = true;

// required material functions
VertexShader = myVertexShader();
FragmentShader = myFragmentShader();
}


C++ Example
Code: [Select]

sfsl::Shader myShader;

void initialize()
{
// load our shader from file
if(!myShader.LoadFromFile("example_shader.sfsl"))
{
std::cerr << sfsl::IO::GetLastError() << std::endl;
return;
}
}

....

void render()
{
// this will automatically get the last called material ( or first material ), unless a name is specified
sfsl::Material myMaterial = myShader.GetMaterial();

// enable the shader
myShader.Enable();
myMaterial.Enable();

// set our color property to red
float myColor[4] = { 1, 0, 0, 1 };
myMaterial.SetProperty("Color", myColor);

// draw the triangle
glBegin(GL_TRIANGLE);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, 1, 0);
glEnd();

// and disable the last called material ( or specify which one to disable by its name )
myMaterial.Disable();

// disable the shader
myShader.Disable();
}
[/code]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFSL - Work in progress.
« Reply #1 on: January 28, 2010, 08:28:38 am »
Actually I chose the opposite way in SFML 2, and removed all the interpretation stuff so that shaders are 100% valid GLSL fragment shaders. By the way, sf::PostFx has become sf::Shader.

However it may be a good idea to develop your idea as an external contribution to SFML, and post it on the wiki or even make it a library :)
Laurent Gomila - SFML developer

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFSL - Work in progress.
« Reply #2 on: January 28, 2010, 08:05:11 pm »
will do, though the reason I said I wanted to embed it into SFML directly, is due to situations where I want to set a GLSL sampler directly, the sampler is a pointer ( i think ) to the OpenGL resource ID, in this case its a texture.. meaning you can force it to change the targeted unit, simply by setting it via glUniform1i(sampler_location, opengl_resource_id);

problem here is, sf::Image, doesn't allow me to get the resource id, you create using glGenTextures(GLuint &id, int size);

so if I wanted to make my c++ syntax simular to

myShader.Properties["texture_resource"].SetValue(mySFImage);

then I'd have to cry, cause i wouldn't be able to access the ID..

I've not mastered opengl, so I'm not sure if there are any functions simular to glGetMatrixf(..) which returns the world matrix, that'll allow me to get the ID of the current binded texture(glGetBindedTextureID()??)

though from what I've learned so far, I'm almost positive there isn't.. so I'd like for you to help me out here. =]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFSL - Work in progress.
« Reply #3 on: January 28, 2010, 08:08:22 pm »
There is such a function
Code: [Select]
GLint texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture);
Laurent Gomila - SFML developer

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFSL - Work in progress.
« Reply #4 on: January 29, 2010, 12:00:53 am »
Ah, thanks! It appears the sampler, is not based on the texture ID as I thought, you have to set this information using glActiveTexture(GL_TEXTURE{0...N});
then
glBindTexture(...);

so, i'll have to rethink my strategy a little, but it's not a big change/problem. =]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFSL - Work in progress.
« Reply #5 on: January 29, 2010, 12:08:39 am »
You have to retrieve the location of the sampler (glGetUniformLocation), then associate the texture unit (0 .. N) to this location to bind the texture to the sampler (glUniform1i).

You can have a look at the sf::Shader source code if you need an example.
Laurent Gomila - SFML developer

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFSL - Work in progress.
« Reply #6 on: January 29, 2010, 12:39:14 am »
I'm going to call this SFSL, Simple Fast Shader Language, an extension to GLSL, it will not use any SFML, although, I will write tutorials on how to link the two, and you may add it to the wiki if you please.

By the way, is there a reason you decided to use ARB extensions, opposed to OpenGL 2.0?

Can we talk at all via MSN/AIM/Yahoo?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFSL - Work in progress.
« Reply #7 on: January 29, 2010, 08:28:20 am »
Quote
I'm going to call this SFSL, Simple Fast Shader Language, an extension to GLSL, it will not use any SFML, although, I will write tutorials on how to link the two, and you may add it to the wiki if you please.

Thats sounds like a very good idea :)

Quote
By the way, is there a reason you decided to use ARB extensions, opposed to OpenGL 2.0?

Because Windows provides 1.1 headers/libs since 1995, and will most likely never update them.
Laurent Gomila - SFML developer