• Welcome to Dark Bit Factory & Gravity.
 

GLSL shader with Png Image and Scroller Support [Code Included]

Started by Omnikam, April 17, 2017

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

inc.

thanks :)

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

-solved
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Omnikam

There is a lot of differences, The Texture  Procedure is different
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

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
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

Omnikam

#62
Removed

inc.

can not run this code. you should provide all externals too.


btw. i sent you a pm
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Omnikam

 :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"

inc.

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

Omnikam

Yeah i forget about Time Zones, it`s 1pm atm and 3.40am in Germany
Okay dude get some rest  :)

inc.

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

Omnikam

Thia was the problem, no Alpha channel, it creates am image pixel by pixel but only using r,g,b and setting transparency

  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
uniform U_time;
to Uniform time; Fragcolor to [code[gl_fragcolor[/code]
etc
as for their ichannels im not sure?

inc.

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

Omnikam

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

inc.


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

currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

emook

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

inc.

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

emook

And its the TextFFT* values that bezomatic generates from the audio it listens to, not the textures.
----

R Tape loading error, 0:1

emook

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

inc.

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

emook

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

Omnikam

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:

Omnikam

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