22 July 2012


I have added some very basic support for shaders into the OpenGL backend. Right now, it looks for a "vertex.glsl" and a "fragment.glsl" to load as vertex and fragment shaders respectively. Eventually I want to have some manifest file that stores the properties of shader programs, but I have not done that yet.

Right now, two uniforms are passed to the shaders. The first is the texture to use called "texture". The second is a vec2 containing the width and height of the texture in pixels called "textureDimensions". This is useful since texture coordinates are in the range [0..1] so it is difficult to tell where one pixel ends and another starts. I have attached a shader program that implements scale2x (Advmame2x) by finding the position within a pixel using these uniforms. It duplicates the functionality of the scaler in the SDL backend, but it looks kinda funky with scale factors != 2. It can probably be modified to use a combination of Advmame3x and Advmame2x depending on subpixel position.

What is great about this is that no development tools are required to change the shader programs. So users can create and load shaders without having to configure build environments and compile ScummVM. Hopefully this can lower the barrier to making some creative works.

Advmame2x shader: https://gist.github.com/3161079
ScummVM branch with enabled shaders: https://github.com/singron/scummvm/tree/opengl


  1. What about this?

    http://gitorious.org/bsnes/xml-shaders (supported by libretro/RetroArch)

    RetroArch (https://github.com/Themaister/RetroArch/)/

    Do you have some opinion about this? Would a portable shader format be possible for OSystem's ScummVM/ResidualVM?

  2. We are looking into the XmlShaderFormat to be compatible with existing shaders for emulators.

  3. Hi, I'm having trouble compiling with mingw, getting undefined reference glgenframebuffersext on line 1379 of opengl-graphics.cpp any ideas where I'm going wrong? :)

    1. Hi Gib. I was compiling on linux while making this. On linux, OpenGL extensions are declared in system headers. However on windows, they require some additional setup.

      First see if using "glext.h" and "wglext.h" headers from the OpenGL registry solves anything.


      You probably still need to resolve the functions at runtime. For instance

      glGenFrameBuffersEXT = (PFNGLGLGENFRAMEBUFFERSEXTPROC) wglGetProcAddress("glGenFrameBuffersEXT");

      That weird character mess is just "PFNGL" + uppercase function name + "PROC". For the SDL backend you can use

      glGenFrameBuffersEXT = (glGenFrameBuffersEXT) SDL_GL_GetProcAddress("glGenFrameBuffersEXT");

    2. Thanks a lot Eric, I'll give it a go