FreeOrion

Forums for the FreeOrion project
It is currently Wed Oct 18, 2017 4:32 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: GG / OpenGL help
PostPosted: Sun Feb 26, 2017 12:20 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 698
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.


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Sun Feb 26, 2017 1:51 pm 
Offline
Programmer
User avatar

Joined: Fri Mar 01, 2013 9:52 am
Posts: 1040
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Sun Feb 26, 2017 2:12 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 698
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 322 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.
Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Sun Feb 26, 2017 2:37 pm 
Offline
Programmer
User avatar

Joined: Fri Mar 01, 2013 9:52 am
Posts: 1040
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Mon Feb 27, 2017 3:21 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 698
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.


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Wed Mar 01, 2017 9:55 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12001
Location: Munich
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.


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Wed Mar 01, 2017 11:12 am 
Offline
Programmer
User avatar

Joined: Fri Mar 01, 2013 9:52 am
Posts: 1040
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: GG / OpenGL help
PostPosted: Thu Mar 02, 2017 4:31 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 698
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/freeorion/tree/sidepanel-sun-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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group