GG / OpenGL help

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

GG / OpenGL help

#1 Post by The Silent One » Sun Feb 26, 2017 12:20 pm

I'd like to do some experiments with animated suns and I'd be thankful for some help with the GG/OpenGL part.

Does GG already offer some way to blend two GG::Textures:
- additively [in a form like tex = AddTextures(tex1, tex2);]
- using one of the images as b/w layer mask? [tex = ApplyLayerMask(tex1, layer_mask);]

Otherwise, I'll try to create two shaders for those tasks. If so, any suggestion where should I place the C++ code?
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
adrian_broher
Programmer
Posts: 1072
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: GG / OpenGL help

#2 Post by adrian_broher » Sun Feb 26, 2017 1:51 pm

What kind of animation you want to achieve?

Blending of images? Rotation? Particles?
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: GG / OpenGL help

#3 Post by The Silent One » Sun Feb 26, 2017 2:12 pm

I want to try out to combine a "corona" and a "core" image for each star. Before the images are added, the corona is blended with a layer mask of 20 frames to simulate movement at the sun's surface. (This way, only 2 pictures per star and +20 images in total.)
Attachments
star.jpg
star.jpg (76.15 KiB) Viewed 549 times
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
adrian_broher
Programmer
Posts: 1072
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: GG / OpenGL help

#4 Post by adrian_broher » Sun Feb 26, 2017 2:37 pm

Take the "RotatingPlanetControl" class in SidePanel.cpp as example and create a dedicated pair of source files for it. Same goes for the shader. Create a dedicated file pair for it and use the ScanelineRenderer class as reference.

Also you could add a tint to the shader and make the core and corona a greyscale-alpha image instead. This would allow to set abitary star colors/only have a minimal set of textures and color them within the shader to the corresponding star color.
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: GG / OpenGL help

#5 Post by The Silent One » Mon Feb 27, 2017 3:21 pm

I had intended to take the corona, core and layer mask textures and combine them into an array of textures, which I then wanted to pass to a GG::DynamicGraphic (instead of rendering directly to the screen). I guess there's no simple way to combine the textures into a new texture like I planned, it has to happen in the framebuffer?
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12248
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: GG / OpenGL help

#6 Post by Geoff the Medio » Wed Mar 01, 2017 9:55 am

Why do you want to generate a bunch of new combined textures, rather than just rendering one set on top of the other? If the base star image is static, then it could be put in a static graphic. If the corona is animated, put it in a dynamic graphic over top. As long as they render in the right order, it should look fine?

That said, I think if you want to generate new textures programatically, you should do so on the CPU and in RAM, and then create a Texture object using the result with Texture::Init : https://github.com/freeorion/freeorion/ ... ure.h#L104

Unless you want to do so every frame, in which case I don't think making a new texture is the answer... instead you'd probably want a multitexture rendering shader where you pass an offset to a sub-texture with the bigger texture containing all your animation frames.

User avatar
adrian_broher
Programmer
Posts: 1072
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: GG / OpenGL help

#7 Post by adrian_broher » Wed Mar 01, 2017 11:12 am

Those greyscale textures, are they based on some functions?
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: GG / OpenGL help

#8 Post by The Silent One » Thu Mar 02, 2017 4:31 pm

adrian_broher wrote:Those greyscale textures, are they based on some functions?
They're created with gimp:
- Render>Plasma
- Desaturate
- Distort>Waves
(It might be possible to obtain the algorithms, not sure about the license though.)
Geoff the Medio wrote:Why do you want to generate a bunch of new combined textures, rather than just rendering one set on top of the other? If the base star image is static, then it could be put in a static graphic. If the corona is animated, put it in a dynamic graphic over top. As long as they render in the right order, it should look fine?
That's right.

Following adrian_broher's advice, I've created a StarAnimation control class. It loads core, corona and layer mask textures, draws the core image and then uses a shader to apply the layer mask to the corona and draw the result on the screen. There is a prototype (here: https://github.com/TheSilentOne1/freeor ... -animation), but the part with the shader isn't working as intended yet.
Since the textures and the shader seem to load correctly, my suspicion is that there's something wrong with how I pass the texture coordinates to the shader [edit: is fixed, still no success however]. If someone more experienced would have a look I'd appreciate it.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

Post Reply