Author Topic: GLSL shader with Png Image and Scroller Support [Code Included]  (Read 3868 times)

0 Members and 1 Guest are viewing this topic.

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: GLSL shader with Png Jpg Support [Code Included]
« Reply #60 on: April 29, 2017 »
thanks :)

head back to this code and find out what you did wrong. with the SC below the alphablending works fine:

 -solved
« Last Edit: April 30, 2017 by inc. »
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Re: GLSL shader with Png Jpg Support [Code Included]
« Reply #61 on: April 29, 2017 »
There is a lot of differences, The Texture  Procedure is different
Code: [Select]
Procedure LoadTexture_(Texture.i) ; Returns the texture for an OpenGL application
  Protected Width.i, Height.i, NWidth.i, NHeight.i, X.i, Y.i, Colour.i, I.i, R.i, G.i, B.i, Tex.i
 
 If Texture = 0 : CatchImage(1, ?Bigtext)  : EndIf
 If Texture = 1 : CatchImage(1, ?MyLogo)  : EndIf;   Catch Logo Image to Texture(1)
  If Texture = 3 : CatchImage(1, ?Smallfont): EndIf
 
  Width = ImageWidth(1)
  Height = ImageHeight(1)

  NWidth  = Width : NHeight  = Height
  If NWidth > NHeight : NHeight = NWidth : EndIf ;/ had to force equal width / height due to compatability issues
  If NHeight > NWidth : NWidth = NHeight : EndIf ;/

  Dim ImageData.c(NWidth * NHeight * 4)
  ImageD = ImageDepth(Texture, #PB_Image_InternalDepth)
  StartDrawing(ImageOutput(1))

  For Y=0 To NHeight-1
    For X=0 To NWidth-1
      If Y>Height-1 Or X>Width
        Colour = 0 ;/ speeds up loading
  Else
        Colour = Point(X,Y)
        r=Red(Colour) : g=Green(Colour) : b=Blue(Colour)
        ImageData(i)=b : i+1
        ImageData(i)=g : i+1
        ImageData(i)=r : i+1
        ImageData(i)=255
      EndIf
      If r<15 And g<15 And b<15  : ImageData(i)=0 : EndIf
      i+1
    Next
  Next
  StopDrawing()
  glGenTextures_(1, @tex.i)
  glBindTexture_(#GL_TEXTURE_2D, tex)
  If ImageD = 32
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
  Else
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_NEAREST)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_NEAREST)
  glTexParameteri_(#GL_TEXTURE_2D,#GL_TEXTURE_WRAP_S, #GL_CLAMP)
  glTexParameteri_(#GL_TEXTURE_2D,#GL_TEXTURE_WRAP_T, #GL_CLAMP)
 EndIf
  If ImageD = 32
    glTexImage2D_(#GL_TEXTURE_2D, 0,4 , NWidth, NHeight, 0, #GL_BGRA, #GL_UNSIGNED_BYTE, @ImageData());
     Else
      glTexImage2D_(#GL_TEXTURE_2D, 0, #GL_RGBA, NWidth, NHeight, 0, #GL_BGRA_EXT, #GL_UNSIGNED_BYTE, @ImageData());
  EndIf
  FreeImage(1)
  Dim ImageData(0)
  ProcedureReturn tex
EndProcedure

And then This

Code: [Select]
Procedure SetupGLTexture(ImageHandle.i)
  Define.i ImageW, ImageH, ImageD
  Define.i MemoryAddress
  Define.i TextureHandle
  If IsImage(ImageHandle) = 0
    ProcedureReturn #False
  EndIf
  ImageD = ImageDepth(ImageHandle, #PB_Image_InternalDepth)
  StartDrawing(ImageOutput(ImageHandle))
    MemoryAddress = DrawingBuffer()
  StopDrawing()
  If MemoryAddress = 0
    ProcedureReturn #False
  EndIf
  glGenTextures_(1, @TextureHandle)
  glBindTexture_(#GL_TEXTURE_2D, TextureHandle)
  ImageW = ImageWidth(ImageHandle)
  ImageH = ImageHeight(ImageHandle)
  If ImageD = 32
    glTexImage2D_(#GL_TEXTURE_2D, 0, 4, ImageW, ImageH, 0, #GL_BGRA, #GL_UNSIGNED_BYTE, MemoryAddress)
  Else
    glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageW, ImageH, 0, #GL_BGR, #GL_UNSIGNED_BYTE, MemoryAddress)
  EndIf
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
  ProcedureReturn TextureHandle
EndProcedure

There are other Differences too, however i think perhaps the loading and binding is the problem especially this
Code: [Select]
StartDrawing(ImageOutput(1))

  For Y=0 To NHeight-1
    For X=0 To NWidth-1
      If Y>Height-1 Or X>Width
        Colour = 0 ;/ speeds up loading
  Else
        Colour = Point(X,Y)
        r=Red(Colour) : g=Green(Colour) : b=Blue(Colour)
        ImageData(i)=b : i+1
        ImageData(i)=g : i+1
        ImageData(i)=r : i+1
        ImageData(i)=255
      EndIf
      If r<15 And g<15 And b<15  : ImageData(i)=0 : EndIf
      i+1
    Next
  Next
  StopDrawing()

Wont have time to look at it for a few days

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Re: GLSL shader with Png Jpg Support [Code Included]
« Reply #62 on: April 29, 2017 »
Removed
« Last Edit: April 30, 2017 by Omnikam »

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: GLSL shader with Png Jpg Support [Code Included]
« Reply #63 on: April 29, 2017 »
can not run this code. you should provide all externals too.


btw. i sent you a pm
« Last Edit: April 30, 2017 by inc. »
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Re: GLSL shader with Png Jpg Support [Code Included]
« Reply #64 on: April 30, 2017 »
 :cheers:
Okay  :buddies:  It`s Fixed
Feel free to Merge both Texture Procedures into one  ;D
Thanks for the Typer source  :)  Havnt looked at it yet, check it out soon
Its nearly time to put something together  O0

Included in the Attachment is everything needed to compile my "DEMO"

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Screenshot looks good :)
But first, head over into the bed.   :cheers:
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Yeah i forget about Time Zones, it`s 1pm atm and 3.40am in Germany
Okay dude get some rest  :)

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Really well done mate.  :updance:  :clap:
you should move the final into your first post and remove the not working code from your thread.
if not, other could be frustrated ;)


last question: what was the issue with the blending? which line in your SC?

and another Question, have you any idea to import shaders from shadertoy?

now back to work with the shader tool . you made a great progress for further tool options because i stuck with that gfx.
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Thia was the problem, no Alpha channel, it creates am image pixel by pixel but only using r,g,b and setting transparency

Code: [Select]
  Else
        Colour = Point(X,Y)
        r=Red(Colour) : g=Green(Colour) : b=Blue(Colour)
        ImageData(i)=b : i+1
        ImageData(i)=g : i+1
        ImageData(i)=r : i+1
        ImageData(i)= 255
      EndIf

Shadertoy would be difficult for me, Too much to implement. They have more than vertex and fragment shader support, and also some custom environmental naming s
Update:  From what ive just read about Shadertoy they use a pixel shader. Naming issues wont be a problem, just simple things like
Code: [Select]
uniform U_time;to
Code: [Select]
Uniform time;
Code: [Select]
Fragcolor to [code[gl_fragcolor[/code]
etc
as for their ichannels im not sure?
« Last Edit: May 02, 2017 by Omnikam »

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
it seems to be more different. it's a web GL Sahder. for this kind of Shaders i'm not skilled enuff :D
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
Until recently id never used glsl shaders, Ive been going through the exercises from
http://thebookofshaders.com     Learning a lot from it
I`d like to know how to communicate with the shader, so i can pass information in real time, the idea being to make music effect the fragments, Apparently Emook achieved this  ;)   ill post anything really cool i uncover, sharing makes us all stronger
Ps. Our Glsl shader does support WebGl  Take GLSLSandbox.com   its all WebGl and most of the shaders work without any need to convert
« Last Edit: May 03, 2017 by Omnikam »

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile

A great link. Thanks.
Yes shaders from the sandbox can copied and pasted directly. 
But we try to discover and support shadertoy's shader too.  the "shader Demo tool", that i'm coding at the moment, should be able to handle them too.
It is a nice idea to sync shaders behavior to music :) but you will be also able to sync any other shaders to the beat of your music. i have added a timer option that can switch between shaders in 1 ms.  you can create cool effects.

here is a test with longer switch timer straight from the tool:

see attachment pls
 
There are GL options that can handle music.
Uniform Sampler 2D textex1 and so on.
I'll discover :)
Take time to watch this video. Very cool and interesting :
https://youtu.be/m6xWreYb3zM

have a closer look at 4:48 min

« Last Edit: May 04, 2017 by inc. »
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline emook

  • C= 64
  • **
  • Posts: 87
  • Karma: 12
    • View Profile
Really cool that someone has been able to do this finally! Well done!

I managed to get shaders to react to FFT values set by BASS dll.

https://www.youtube.com/watch?v=4uk19hytCnw

I'll clean up the sources and post, it was a while back!
----

R Tape loading error, 0:1

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
yes. i've seen this demo, but we want to include all into one exe file :D no external libs / dll should be shared with the demo.
we find the way.
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline emook

  • C= 64
  • **
  • Posts: 87
  • Karma: 12
    • View Profile
And its the TextFFT* values that bezomatic generates from the audio it listens to, not the textures.
----

R Tape loading error, 0:1

Offline emook

  • C= 64
  • **
  • Posts: 87
  • Karma: 12
    • View Profile
And its not hard to have a bass dll inside the exe, it would be possible even to use the osm library included and use that instead.
----

R Tape loading error, 0:1

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 260
  • Karma: 18
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Sounds good. Yes it is possible to include each file via includebinary into the exe and extract em on start into a temp folder.
Looking forward,  would be nice to see some solution using FFT or similar  :inspired:
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline emook

  • C= 64
  • **
  • Posts: 87
  • Karma: 12
    • View Profile
I've been busy writing code for the spectrum over the past two years and haven't really done much in PB but I'll grab rework my example using the texture mapping above.

I had everything working apart from being able to show bitmaps at the same time. As I couldn't find a solution the whole code got out of the shelf :)
----

R Tape loading error, 0:1

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
It`s funny Emook because in my search for a solution i found your posts over at Purebasic forums, only 2 years earlier. It`s funny because i came up with some pretty funny workarounds before the solution, thank god inc pressed me to solve it properly, because at one point i was using png drawn windows to display an image on top of the GlGadget, it  worked  :P but not good coding practice
inc  ;D Very nice share. especially the expansion folder   :cheers:
« Last Edit: May 04, 2017 by Omnikam »

Offline Omnikam

  • Atari ST
  • ***
  • Posts: 100
  • Karma: 4
    • View Profile
What would life be like without a Vu meter for xm music?   
This one uses uFmod and in particular the uFMOD_GetStats()  to capture the RMS volume stats for L and R channels. I then modified the output to use in my textured quads matrix
« Last Edit: May 05, 2017 by Omnikam »