# OpenGL GLSL Video Mixer (new demo)

## Recommended Posts

Screenshot: I've spent a lot of time working on this demo since converting the DirectShow video playback code from directx to OpenGL wasn't too obvious, and now I believe I have something pretty neat to show to the GL community. The one aspect that I'm the most proud of about this demo is the GUI; coming from a Java background, I decided to create a SWING-like widget collection and import it into my applications through XML. If you're looking into using my widgets in your existing or future work, take a look at the files in GUIUtils, and WindowsManager (the windowProcessor function) in ManagersUtils. If you have any questions, you can get in touch with me at abezrati at hotmail dot com. The GUI layout xml descriptor.
<Panel texturePath = "GUIElements.png"
visible     = "false"
font        = "Arial">

<MaterialSurface callbackString = "1stVideo">
<Dimensions   x =  "0.5" y = "0.5"/>
<Position     x = "0.25" y = "0.25"/>
</MaterialSurface>

<MaterialSurface callbackString = "2ndVideo">
<Dimensions   x =  "0.5" y = "0.5"/>
<Position     x = "0.25" y = "0.75"/>
</MaterialSurface>

<MaterialSurface callbackString = "finalMix"
drawBounds     = "true">
<BordersColor x = "000" y = "000" z = "255"/>
<Dimensions   x =  "0.5" y = "0.5"/>
<Position     x = "0.75" y = "0.25"/>
</MaterialSurface>

<Panel name           = "1s Quarter"
drawBounds     = "true"
anchorPoint    = "CORNERLU">

<BordersColor x = "000" y = "000" z = "255"/>
<Dimensions   x = "0.5" y = "0.5"/>
<Position     x = "0.0" y = "0.0"/>

drawBounds     = "true"
anchorPoint    = "CORNERRU"
drawBackground = "true">

<Dimensions  x = "75" y = "100"/>
<Position    x = "-12" y = "10"/>
anchorPoint    = "CORNERLU"
checked        = "true">
<Text      string         = "3x3 Cone"/>
<Position  x =   "5" y = "2"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Edge"/>
<Position  x =   "5" y = "22"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Sepia"/>
<Position  x =   "5" y = "42"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Invert"/>
<Position  x =   "5" y = "62"  />

anchorPoint    = "CORNERLU">
<Text      string         = "HSV"/>
<Position  x =   "5" y = "82"  />
</Panel>

<Panel name           = "FPS"
drawBounds     = "true"
anchorPoint    = "CORNERLU"
drawBackground = "true">

<Dimensions   x = "130" y = "30"/>
<Position     x =  "10" y = "10"/>

<Label>
<Text string  = "Current FPS: 0.0" />
</Label>
</Panel>

<Panel name           = "1st Movie CP"
drawBounds     = "true"
anchorPoint    = "CORNERLD"
drawBackground = "true">

<Dimensions  x = "170" y =  "80"/>
<Position    x = "10" y = "-10"/>

<Slider callbackString = "MovieProgress1"
progress       =  "0.0">
<Position    x = "0.65" y = "0.3"         />
<Text        string  = "Progress" />
</Slider>

<CheckBox callbackString = "Loop"
checked        = "true">
<Position    x =   "0.6" y = "0.75"  />
<Text        string  = "Enable Looping" />
</CheckBox>

<Button callbackString = "PlayMovie">
<ButtonColor x =   "0.8" y =  "0.8" z="0.8"/>
<Position    x =   "0.15" y = "0.35"       />
<Text        string  = "Play" />
</Button>

<Button callbackString = "StopMovie">
<Text        string  = "Stop"/>
<Position    x =   "0.15" y = "0.75"  />
</Button>
</Panel>

anchorPoint    = "CORNERRD">
<Position    x =   "-10" y = "-10"  />
</Button>
</Panel>

<Panel name           = "2nd Quarter"
drawBounds     = "true"
anchorPoint    = "CORNERLU">

<BordersColor x = "000" y = "000" z = "255"/>
<Dimensions   x = "0.5" y = "0.5"/>
<Position     x = "0.0" y = "0.5"/>

drawBounds     = "true"
anchorPoint    = "CORNERRU"
drawBackground = "true">

<Dimensions  x = "75" y = "100"/>
<Position    x = "-12" y = "10"/>
anchorPoint    = "CORNERLU"
checked        = "true">
<Text      string         = "3x3 Cone"/>
<Position  x =   "5" y = "2"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Edge"/>
<Position  x =   "5" y = "22"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Sepia"/>
<Position  x =   "5" y = "42"  />

anchorPoint    = "CORNERLU">
<Text      string         = "Invert"/>
<Position  x =   "5" y = "62"  />

anchorPoint    = "CORNERLU">
<Text      string         = "HSV"/>
<Position  x =   "5" y = "82"  />
</Panel>

<Panel name           = "2nd Movie CP"
drawBounds     = "true"
anchorPoint    = "CORNERLD"
drawBackground = "true">

<Dimensions  x = "170" y =  "80"/>
<Position    x = "10"  y = "-10"/>

<Slider callbackString = "MovieProgress2">
<Text        string  = "Progress"/>
<Position    x = "0.65" y = "0.35"/>
</Slider>

<Button callbackString = "PlayMovie">
<Text        string  = "Play"/>
<Position    x =   "0.15" y = "0.35" />
</Button>

<Button callbackString = "StopMovie">
<Text        string  = "Stop"/>
<Position    x =   "0.15" y = "0.75"  />
</Button>

<CheckBox callbackString = "Loop"
checked        = "true">
<Text      string  = "Enable Looping"/>
<Position  x =   "0.6" y = "0.75"  />
</CheckBox>

</Panel>

anchorPoint    = "CORNERRD">
<Position    x =   "-10" y = "-10"  />
</Button>

</Panel>

<Panel name = "4th Quarter">

<Dimensions  x = "0.5" y = "0.5"/>
<Position    x = "0.75" y = "0.75"/>

progress       =  "0.5">
<Position    x = "0.5" y = "0.15"/>
</Slider>

<Slider callbackString = "brightness"
progress       = "0.2">
<Text        string  = "Brightness:1.00"/>
<Position    x = "0.25" y = "0.6"/>
</Slider>

<Slider callbackString = "contrast"
progress       = "0.6">
<Text        string  = "Contrast:1.00"/>
<Position    x = "0.75" y = "0.6"/>
</Slider>

<Slider callbackString = "saturation"
progress       = "0.5">
<Text        string  = "Saturation"/>
<Position    x = "0.25" y = "0.8"/>
</Slider>

<Slider callbackString = "hue"
progress       = "0.5">
<Text        string  = "Hue"/>
<Position    x = "0.75" y = "0.8"/>
</Slider>
</Panel>

<TexCoordsDesc xStart        =   "0"
yStart        =   "0"
xEnd          =  "65"
yEnd          =  "66"
type          =   "1"/>

<TexCoordsDesc xStart        =   "66"
yStart        =   "1"
xEnd          =  "129"
yEnd          =  "66"
type          =   "2"/>

<TexCoordsDesc xStart        =  "131"
yStart        =   "0"
xEnd          =  "165"
yEnd          =  "34"
type          =   "4"/>

<TexCoordsDesc xStart        =  "0"
yStart        =  "67"
xEnd          =  "64"
yEnd          =  "131"
type          =   "5"/>

<TexCoordsDesc xStart        =  "65"
yStart        =  "67"
xEnd          =  "129"
yEnd          =  "131"
type          =   "6"/>
</Panel>


PS: Saturation and Hue sliders don't work simply because I have no clue how to implement these filters... Demo binaries. Demo source and build files. Demo util files.

##### Share on other sites
nice :) I don't spose your gui library has any win32 specific code?

##### Share on other sites
Woow great player :)
Edit: BTW can you give me your Video loader if you don mind .

[Edited by - ff8 on March 28, 2005 5:37:48 AM]

##### Share on other sites
As a matter of fact there is only one thing about my GUI that is win32 dependent:
The window listener.
However, I assume there is a similar callback function in Linux or Mac that handles all the mouse clicks/events.
BTW the video loader is located in AppUtils/DVTexture.h/cpp :)

thank you :)

##### Share on other sites
i should be able to replace with sdl or something similar.

##### Share on other sites
Let me know how it goes :)
I'm really sorry for the lack of documentation, but if you have any questions, don't hesitate and send me an email or something.
BTW, I updated the demo with even better looking buttons since the previous ones didn't scale too well as their dimensions got bigger. With these new ones, no matter how big your button is, it would always look really good.
I should add a new filter or two and notify you guys when it's done.
Peace.
I also have changed the way my shaders are scripted; now you can specify in the xml file what part is the vertex shader and what other is the fragment. You can also link shaders together (must be both shaders!! You can't possibly link a vertex shader and a fragment program)

Examples taken out of the demo;
<Shaders    linkProcessors    = "true"    vertexProcessor   = "VERTEX_SHADER"   fragmentProcessor = "FRAGMENT_SHADER">    <VERTEX_SHADER>    <RawData>      void main(void)      {         gl_TexCoord[0] = gl_MultiTexCoord0;              gl_Position    = ftransform();      }    </RawData>  </VERTEX_SHADER>  <FRAGMENT_SHADER>    <Uniform name = "texOffset" size = "2" type = "float" x = "0.001953125"                                                           y = "0.001953125"/>    <Uniform name = "texture"   size = "1" type = "int"   x = "0"  />    <RawData>      uniform sampler2D texture;      uniform vec2      texOffset;       void main(void)      {        float weights[9];        vec2  offsets[9];        weights[0] = 2.0; weights[1] = 2.0; weights[2] = 2.0;        weights[3] = 2.0; weights[4] = 5.0; weights[5] = 2.0;        weights[6] = 2.0; weights[7] = 2.0; weights[8] = 2.0;        offsets[0] = vec2(-texOffset.x, texOffset.y);        offsets[1] = vec2( 0.0, texOffset.y);        offsets[2] = vec2( texOffset.x, texOffset.y);        offsets[3] = vec2(-texOffset.x, 0.0);         offsets[4] = vec2( 0.0, 0.0);        offsets[5] = vec2( texOffset.x, 0.0);        offsets[6] = vec2(-texOffset.x,-texOffset.y);        offsets[7] = vec2( 0.0,-texOffset.y);        offsets[8] = vec2( texOffset.x,-texOffset.y);        for(int i = 0; i < 9; i++)          gl_FragColor += texture2D(texture, gl_TexCoord[0].xy + offsets[i])*weights[i];                gl_FragColor/= 21.0;      }    </RawData>  </FRAGMENT_SHADER></Shaders>

<Shaders    linkProcessors    = "false"    vertexProcessor   = "VERTEX_SHADER"   fragmentProcessor = "FRAGMENT_PROGRAM">  <VERTEX_SHADER>    <RawData>      void main(void)      {         gl_TexCoord[0] = gl_MultiTexCoord0;              gl_Position    = ftransform();      }    </RawData>  </VERTEX_SHADER>   <!-- Assembly is l33t :P -->  <FRAGMENT_PROGRAM>    <Attributes local = "false"                name  = "texOffset"                x     = "0.00390625"                y     = "0.00390625" />    <RawData>!!ARBfp1.0     PARAM textureOffset   = program.env[0];     PARAM grayExtractor   = {0.30, 0.59, 0.11, 0.0};     PARAM offsetCoeffs[8] = {{-1.0, 1.0, 0.0, 0.0},                              { 0.0, 1.0, 0.0, 0.0},                              { 1.0, 1.0, 0.0, 0.0},                              {-1.0, 0.0, 0.0, 0.0},                              { 1.0, 0.0, 0.0, 0.0},                              {-1.0,-1.0, 0.0, 0.0},                              { 0.0,-1.0, 0.0, 0.0},                              { 1.0,-1.0, 0.0, 0.0}};     TEMP texCoords,  luminance1,          luminance2, colorSample;     MAD   texCoords  , offsetCoeffs[0], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance1.x, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[1], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance1.y, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[2], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance1.z, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[3], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance1.w, grayExtractor, colorSample;     TEX   colorSample, fragment.texcoord[0], texture[0], 2D;     DP4   luminance2.x, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[4], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance2.y, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[5], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance2.z, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[6], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   luminance2.w, grayExtractor, colorSample;     MAD   texCoords  , offsetCoeffs[7], textureOffset, fragment.texcoord[0];     TEX   colorSample, texCoords, texture[0], 2D;     DP4   colorSample.z, grayExtractor, colorSample;        MAD   colorSample.x, 2.0, luminance2.y, colorSample.z;     MAD   colorSample.x,-2.0, luminance1.w, colorSample.x;     ADD   colorSample.x, colorSample.x, luminance1.z;     ADD   colorSample.x, colorSample.x,-luminance1.x;     ADD   colorSample.x, colorSample.x,-luminance2.z;     MAD   colorSample.y, 2.0, luminance2.w, luminance2.z;     MAD   colorSample.y,-2.0, luminance1.y, colorSample.y;     ADD   colorSample.y, colorSample.y, colorSample.z;     ADD   colorSample.y, colorSample.y,-luminance1.x;     ADD   colorSample.y, colorSample.y,-luminance1.z;     MUL   colorSample.z, colorSample.x, colorSample.x;     MAD   colorSample.z, colorSample.y, colorSample.y, colorSample.z;       RSQ   colorSample.z, colorSample.z;     RCP   colorSample,   colorSample.z;     MAD   result.color, -1.0, colorSample, 1.0;     END      </RawData>   </FRAGMENT_PROGRAM></Shaders>

PS: With the next version, all the widgets will be able to specify and request their own fonts with different sizes, bold or italic etc...

[Edited by - JavaCoolDude on March 28, 2005 8:17:48 PM]

##### Share on other sites
All sliders are now active and working, enjoy the final result :)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628303
• Total Posts
2981924
• ### Similar Content

• By mellinoe
Hi all,
First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
• By aejt
I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
I have these classes:
For GPU resources:
Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).
And my plan is to define everything into these XML documents to abstract away files:
Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
Factory classes for resources:
For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
Factory classes for assets:
Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).

Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
Thanks!
• By nedondev
I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
Thanks.

• So I've recently started learning some GLSL and now I'm toying with a POM shader. I'm trying to optimize it and notice that it starts having issues at high texture sizes, especially with self-shadowing.
Now I know POM is expensive either way, but would pulling the heightmap out of the normalmap alpha channel and in it's own 8bit texture make doing all those dozens of texture fetches more cheap? Or is everything in the cache aligned to 32bit anyway? I haven't implemented texture compression yet, I think that would help? But regardless, should there be a performance boost from decoupling the heightmap? I could also keep it in a lower resolution than the normalmap if that would improve performance.
Any help is much appreciated, please keep in mind I'm somewhat of a newbie. Thanks!

• Hi,
I'm trying to learn OpenGL through a website and have proceeded until this page of it. The output is a simple triangle. The problem is the complexity.
I have read that page several times and tried to analyse the code but I haven't understood the code properly and completely yet. This is the code: