Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Dr_D on July 15, 2006
-
It's a metablob demo using a glsl vertex shader. It wont run on old cards, so I wouldn't bother with it, if you do have an older card.
By the way, nice forum! :cheers:
Option Explicit
Randomize Timer
'$Static
'$INCLUDE: "\gl\gl.bi"
'$INCLUDE: "\gl\glu.bi"
'$INCLUDE: "\gl\glext.bi"
'$INCLUDE: "\gl\glfw.bi"
Const As Integer True = -1, False = Not True
Type DisplayMode
  W As Uinteger
  H As Uinteger
  R_BITS As Uinteger
  G_BITS As Uinteger
  B_BITS As Uinteger
  A_BITS As Uinteger
  D_BITS As Uinteger
  S_BITS As Uinteger
  MODE As Uinteger
  GlVer As Zstring Ptr
  As Single FOVy, Aspect, zNear, zFar
End Type
Type Balls
  As Single R, G, B
  As Single x, Dx, y, Dy, Rad
End Type
Declare Sub Init_GL_Window( Display As DisplayMode )
Declare Sub Set_Ortho( Display As DisplayMode )
Declare Sub Drop_Ortho( Display As DisplayMode )
Declare Sub Init_Balls( Ball() As Balls, Display As DisplayMode)
Const MAX_BALLS As Integer = 25
Dim As Integer Use_Shader = True
Dim Ball(1 To Max_Balls) As Balls
Dim Display As DisplayMode
Init_GL_Window Display
#Define Midx (Display.w \ 2)
#Define Midy (Display.h \ 2)
Dim glCreateShaderObjectARBÂ Â As PFNglCreateShaderObjectARBPROCÂ Â = Cptr(PFNGLCREATESHADEROBJECTARBPROC, glfwGetProcAddress( "glCreateShaderObjectARB" ))
Dim glShaderSourceARBÂ Â Â Â Â As PFNglShaderSourceARBPROCÂ Â Â Â Â = Cptr(PFNGLSHADERSOURCEARBPROC, glfwGetProcAddress( "glShaderSourceARB" ))
Dim glGetShaderSourceARBÂ Â Â As PFNglGetShaderSourceARBPROCÂ Â Â = Cptr(PFNGLGetSHADERSOURCEARBPROC, glfwGetProcAddress( "glGetShaderSourceARB" ))
Dim glCompileShaderARBÂ Â Â Â As PFNGLCompileShaderARBPROCÂ Â Â Â = Cptr(PFNglCompileShaderARBPROC, glfwGetProcAddress( "glCompileShaderARB" ))
Dim glDeleteObjectARBÂ Â Â Â Â As PFNGLDeleteObjectARBPROCÂ Â Â Â Â = Cptr(PFNglDeleteObjectARBPROC, glfwGetProcAddress( "glDeleteObjectARB" ))
Dim glCreateProgramObjectARBÂ As PFNglCreateProgramObjectARBPROCÂ = Cptr(PFNglCreateProgramObjectARBPROC, glfwGetProcAddress( "glCreateProgramObjectARB" ))
Dim glAttachObjectARBÂ Â Â Â Â As PFNglAttachObjectARBPROCÂ Â Â Â Â = Cptr(PFNglAttachObjectARBPROC, glfwGetProcAddress( "glAttachObjectARB" ))
Dim glUseProgramObjectARBÂ Â Â As PFNglUseProgramObjectARBPROCÂ Â Â = Cptr(PFNglUseProgramObjectARBPROC, glfwGetProcAddress( "glUseProgramObjectARB" ))
Dim glLinkProgramARBÂ Â Â Â Â As PFNglLinkProgramARBPROCÂ Â Â Â Â = Cptr(PFNglLinkProgramARBPROC, glfwGetProcAddress( "glLinkProgramARB" ))
Dim glValidateProgramARBÂ Â Â As PFNglValidateProgramARBPROCÂ Â Â = Cptr(PFNglValidateProgramARBPROC, glfwGetProcAddress( "glValidateProgramARB" ))
Dim glGetObjectParameterivARB As PFNglGetObjectParameterivARBPROC = Cptr(PFNglGetObjectParameterivARBPROC, glfwGetProcAddress( "glGetObjectParameterivARB" ))
Dim glGetInfoLogARBÂ Â Â Â Â Â As PFNglGetInfoLogARBPROCÂ Â Â Â Â Â = Cptr(PFNglGetInfoLogARBPROC, glfwGetProcAddress( "glGetInfoLogARB" ))
If glfwExtensionSupported( "GL_ARB_shader_objects" ) = 0 Then
  Print "Error: ARB shader objects extension not supported."
  Sleep 1000
  End -1
End If
If( glCreateShaderObjectARB = 0 ) Then
  Print "Error: glCreateShaderObjectARB not present."
  Sleep 1000
  End -1
End If
If( glCreateProgramObjectARB = 0 ) Then
  Print "Error: glCreateProgramObjectARB not present."
  Sleep 1000
  End -1
End If
If( glShaderSourceARB = 0 ) Then
  Print "Error: glShaderSourceARB not present."
  Sleep 1000
  End -1
End If
If( GL_ARB_shading_language_100 = 0 ) Then
  Print "Error: This program required GL_ARB_shading_language_100."
  Sleep 1000
  End -1
End If
Dim As Integer Line_Cnt
Dim As String Shader_Text, tString
Dim As Integer i, x, y, Scale = 8
Dim As Integer Dist
Dim As GlHandleARB Vertex_Shader, Shader_Program
Dim As Gluint Shader_Compile_Success
Read Line_Cnt
For i = 1 To Line_Cnt
  Read tString
  Shader_Text + = tString + Chr( 13, 10 )
Next
Dim As GLcharARB Ptr table(0) => { Strptr( Shader_Text ) }
Vertex_Shader = glCreateShaderObjectARB( GL_VERTEX_SHADER )
glShaderSourceARB( Vertex_Shader, 1, @table(0), 0 )
glCompileShaderARB( Vertex_Shader )
glGetObjectParameterivARB(Vertex_Shader, GL_OBJECT_COMPILE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Dim As Gluint infologsize
  glGetObjectParameterivARB( Vertex_Shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, @infoLogSize)
  Dim As GlByte infolog(InfoLogSize)
  glGetInfoLogARB(Vertex_Shader, InfoLogSize, 0, @infoLog(0))
  tString=""
  For i = 0 To InfoLogSize-1
    tString+=Chr(InfoLog(i))
  Next
 Â
  Print "Vertex Shader Infolog error message:"
  Print tString
End If
Shader_Program = GlCreateProgramObjectARB()
glAttachObjectARB( Shader_Program, Vertex_Shader )
glLinkProgramARB( Shader_Program )
GlValidateProgramARB( Shader_Program )
glGetObjectParameterivARB( Shader_Program, GL_OBJECT_VALIDATE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Beep
  Print "GLSL program failed to compile!"
  Sleep 1000
End If
If GL_VERTEX_PROGRAM_POINT_SIZE_ARB = 0 Then
  Beep
  Print "GL_VERTEX_PROGRAM_POINT_SIZE_ARB required for program to run correctly!"
Else
  GLEnable GL_VERTEX_PROGRAM_POINT_SIZE_ARB
End If
Set_Ortho( Display )
'Drop_Ortho( Display )
Init_Balls( Ball(), Display )
Do
 Â
  If GlfwGetKey(GLFW_KEY_SPACE) Then
    Use_Shader Xor = True
    Do While GlfwGetKey(GLFW_KEY_SPACE)
      GlfwPollEvents()
    Loop Â
  End If
 Â
  If Use_Shader Then
    glUseProgramObjectARB( Shader_Program )
  Else
    glUseProgramObjectARB( False )
  End If
 Â
  GlClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
 Â
  For i = 1 To MAX_BALLS
    Ball(i).x += Ball(i).dx
    Ball(i).y += Ball(i).dy
   Â
    If Ball(i).x>360 Then
      Ball(i).dx -= (1+Rnd*.5)
    End If
   Â
    If Ball(i).x<280 Then
      Ball(i).dx += (1+Rnd*.5)
    End If
   Â
    If Ball(i).y>280 Then
      Ball(i).dy -= (1+Rnd*.5)
    End If
   Â
    If Ball(i).y<200 Then
      Ball(i).dy += (1+Rnd*.5)
    End If
   Â
  Next
 Â
  GlBegin GL_QUADS
  For y = Display.h To Scale Step -Scale
    For x = Scale To Display.w Step Scale
     Â
      Dim As Single R,G,B
      Dim As Integer Hits
     Â
      For i = 1 To MAX_BALLS
       Â
        Dist = ((y-Ball(i).y)^2 + (x-Ball(i).x)^2)/Ball(i).Rad
       Â
        If Dist<= Ball(i).Rad Then
          R += (Ball(i).Rad-Dist)/Ball(i).R
          G += (Ball(i).Rad-Dist)/Ball(i).G
          B += (Ball(i).Rad-Dist)/Ball(i).B
          Hits-=1
        End If
       Â
      Next
     Â
      If Hits>0 Then
        R/=Hits
        G/=Hits
        B/=Hits
      End If
      GlEnable GL_BLEND
      GlBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
      GlColor4F R, G, B, 0
      GlVertex3f X, Y, -Y / 500
      GlColor4F R, G, B, 0
      GlVertex3f X-Scale, Y, -Y / 500
      GlColor4F R, G, B, 0
      GlVertex3f X-Scale, Y-Scale, -( Y - Scale ) / 500
      GlColor4F R, G, B, 0
      GlVertex3f X, Y-Scale, -( Y - Scale ) / 500
     Â
    Next
  Next
  GlEnd
 Â
 Â
  GlfwSwapBuffers
Loop Until glfwGetKey( GLFW_KEY_ESC )
GlDeleteObjectArb( Vertex_Shader )
GlDeleteObjectArb( Shader_Program )
GlfwTerminate()
End
Sub Init_Balls( Ball() As Balls, Display As DisplayMode)
  Dim As Integer i
 Â
  For i = 1 To MAX_BALLS
    Ball(i).x = 320+Rnd*250
    Ball(i).y = 240+Rnd*150
    Ball(i).dx = 1+Rnd*10
    Ball(i).dy = 1+Rnd*10
    If Int(Rnd*10) = 5 Then
      Ball(i).dx = -Ball(i).dx
      If Int(Rnd*2) = 1 Then Ball(i).dy = -Ball(i).dy
    End If
   Â
    Ball(i).Rad = 64+Rnd*64
   Â
    Ball(i).R = 64+Int(Rnd*255)
    Ball(i).G = 64+Int(Rnd*255)
    Ball(i).B = 64+Int(Rnd*255)
  Next
 Â
End Sub
Sub Set_Ortho( Display As DisplayMode )
  GlMatrixMode( Gl_Projection )
  GlPushMatrix
  GlLoadIdentity
  GlMatrixMode( Gl_Modelview )
  GlPushMatrix
  GlLoadIdentity
  GlOrtho( 0, Display.W, 0, Display.H, -1, 1 )
End Sub
Sub Drop_Ortho( Display As DisplayMode )
  GlMatrixMode( Gl_Projection )
  GlPopMatrix
  GlMatrixMode( Gl_Modelview )
  GlPopMatrix
End Sub
Sub Init_GL_Window( Display As DisplayMode )
  Display.W   = 640
  Display.H   = 480
  Display.R_BITS= 8
  Display.G_BITS= 8
  Display.B_BITS= 8
  Display.A_BITS= 8
  Display.D_BITS= 24
  Display.S_BITS= 8
  Display.MODE = GLFW_WINDOW
 Â
  If glfwInit() Then
    'Successful!
  Else Â
    Print "Failed to initialize GLFW!"
    Sleep 1000
    End
  End If
 Â
 Â
  If glfwOpenWindow( _
  Display.W   , _
  Display.H   , _
  Display.R_BITS, _
  Display.G_BITS, _
  Display.B_BITS, _
  Display.A_BITS, _
  Display.D_BITS, _
  Display.S_BITS, _
  Display.MODE ) _
  Then
  GlfwSwapInterval 1
  Display.GlVer = glGetString(GL_VERSION)
Else
  GlfwTerminate()
  End
End If
'To check, use... glfwGetWindowParam()
' OpenGL specific stuff...
glViewport 0, 0, Display.W, Display.H
glMatrixMode GL_PROJECTIONÂ Â Â Â
glLoadIdentity Â
Display.FOVy = 45.0
Display.Aspect = Display.W / Display.H
Display.znear = 1
Display.zfar = 1000
gluPerspective Display.FOVy, Display.Aspect, Display.zNear, Display.zFar
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 0.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUALÂ Â
glEnable GL_COLOR_MATERIAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
glPolygonMode GL_FRONT_AND_BACK, GL_POINT
glEnable GL_CULL_FACE
End Sub
Data 13
Data "void main(void)"
Data "{"
Data "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
Data "vec4 V = gl_ModelViewMatrix * gl_Vertex;"
Data "gl_FrontColor = gl_Color;"
Data "float ptSize = length(V);"
Data "ptSize *= ptSize;"
Data "gl_PointSize = (gl_Color * 10.0);"
Data "if (gl_PointSize || 0 )"
Data "{"
Data "gl_FrontColor = gl_Color * (gl_PointSize/64);"
Data "}"
Data "}"
-
Thanks for posting the routine Dr_D :) Unfortunately it stops compiling at line 10 for me, trying to kluge it makes the compilation fale at various declarations throughout the listing, when it get to the shader definitions I gave up. Shame because I have shaders on this card and I'd really love to see it.
Soo.. If anyone can get this to compile could they attach an exe of it to their post please? Thanks!
And by the way :hi: to the board Dr_D, nice to see you here and I hope that you stick around.
-
Yo doc!!!
I just took a screenie!!!!
BTW, this forum is kool cuz you can post screenies as attachment.
-
Ah, thanks for posting the screen Rel, it looks excellent.
Could someone attach an exe so I can try running it please?
Thanks! :)
-
Definately need to try this when I get home, my parents gfx card doesnt do OGL too well.
Looks way smart from the screenie, and nice one DR D. :)
-
Thanks guys! ;D It overloads after a while though... I mean the balls will eventually start flying way off the screen because I didn't limit their movement. I'm working on another version that also uses a fragment shader, but it's obvious that I've still got alot to learn. :|| I'll make an exe of this one though. It should be very small.
-
Cool, you can just attach it to your post (as long as it is in a zip or rar file). Thanks :)
-
Ok. I attached a zip to the first post. :cheers:
-
Ok. I attached a zip to the first post. :cheers:
Awesome ... very cool fx !
-
very cool shader work mate!
-
Thanks very much for attaching the exe, I managed to run it however it was odd. My card / drivers are obviously out of date so the program wouldnt run properly, I got a dos window with some errors, however I got a good idea of what it would look like moving because another window was opened with the blob effect running as just dots, looked cool like that, I'm just gutted I can't see it for real :)
-
Vertex Shader Infolog error message:
ERROR: 0:8: 'assign' : cannot convert from '4-component vector of float' to 'Po
intSize float'
ERROR: 0:9: '||' : wrong operand types no operation '||' exists that takes a l
eft-hand operand of type 'PointSize float' and a right operand of type 'const in
t' (or there is no acceptable conversion)
ERROR: 0:11: '/' : wrong operand types no operation '/' exists that takes a le
ft-hand operand of type 'PointSize float' and a right operand of type 'const int
' (or there is no acceptable conversion)
ERROR: 3 compilation errors. No code generated.
GLSL program failed to compile!
-
That's the same as I got. I still managed to get some metablobs constructed from dots displayed though.
-
Dr_D attempts to make shader...
GFX card says... :whack:
hehehe, I told you I had alot to learn. I'm still reading. ;)
-
With the exe version everything looked pretty smart DR_D Dude :)
Perhaps it's a FB compiler issue.
-
Got the same errors as Relsoft and the movings dots - and I believe my GL shader libarary is up to date/
-
It's not just my shader library then? :)
Please post any further updates Dr_D , it'd be nice to help you sort out this compatibility problem if we can.
-
This is kind of a twist on the same thing... sort of. It's not real pretty, it just blurs a texture. It does show how to use a fragment shader. It also uses the point size extension from the other demo. ;)
Option Explicit
Randomize Timer
'$Static
'$INCLUDE: "\gl\gl.bi"
'$INCLUDE: "\gl\glu.bi"
'$INCLUDE: "\gl\glext.bi"
'$INCLUDE: "\gl\glfw.bi"
Const MAX_BALLS As Integer = 50
Const Depth As Single =Â .503
Type DisplayMode
  W As Uinteger
  H As Uinteger
  R_BITS As Uinteger
  G_BITS As Uinteger
  B_BITS As Uinteger
  A_BITS As Uinteger
  D_BITS As Uinteger
  S_BITS As Uinteger
  MODE As Uinteger
  GlVer As Zstring Ptr
  As Single FOVy, Aspect, zNear, zFar
End Type
Type Vector2D
  As Single X,Y
End Type
Type Balls
  As Single R, G, B
  As Single x, Dx, y, Dy,z, Dz, Rad
End Type
Declare Sub Init_GL_Window( Display As DisplayMode )
Declare Sub Set_Ortho( Display As DisplayMode )
Declare Sub Drop_Ortho( Display As DisplayMode )
Declare Sub Init_Ball( Ball As Balls, Display As DisplayMode)
Dim Ball(1 To Max_Balls) As Balls
Dim Display As DisplayMode
Init_GL_Window Display
#Define Midx (Display.w \ 2)
#Define Midy (Display.h \ 2)
Dim Buffer As GLUINT, tData As Uinteger Ptr
glGenTextures 1, @Buffer
GlBindTexture GL_TEXTURE_2D, Buffer
glTexImage2D( GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0)
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST )
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST )
Dim glCreateShaderObjectARBÂ Â As PFNglCreateShaderObjectARBPROCÂ Â = Cptr(PFNGLCREATESHADEROBJECTARBPROC, glfwGetProcAddress( "glCreateShaderObjectARB" ))
Dim glShaderSourceARBÂ Â Â Â Â As PFNglShaderSourceARBPROCÂ Â Â Â Â = Cptr(PFNGLSHADERSOURCEARBPROC, glfwGetProcAddress( "glShaderSourceARB" ))
Dim glGetShaderSourceARBÂ Â Â As PFNglGetShaderSourceARBPROCÂ Â Â = Cptr(PFNGLGetSHADERSOURCEARBPROC, glfwGetProcAddress( "glGetShaderSourceARB" ))
Dim glCompileShaderARBÂ Â Â Â As PFNGLCompileShaderARBPROCÂ Â Â Â = Cptr(PFNglCompileShaderARBPROC, glfwGetProcAddress( "glCompileShaderARB" ))
Dim glDeleteObjectARBÂ Â Â Â Â As PFNGLDeleteObjectARBPROCÂ Â Â Â Â = Cptr(PFNglDeleteObjectARBPROC, glfwGetProcAddress( "glDeleteObjectARB" ))
Dim glCreateProgramObjectARBÂ As PFNglCreateProgramObjectARBPROCÂ = Cptr(PFNglCreateProgramObjectARBPROC, glfwGetProcAddress( "glCreateProgramObjectARB" ))
Dim glAttachObjectARBÂ Â Â Â Â As PFNglAttachObjectARBPROCÂ Â Â Â Â = Cptr(PFNglAttachObjectARBPROC, glfwGetProcAddress( "glAttachObjectARB" ))
Dim glUseProgramObjectARBÂ Â Â As PFNglUseProgramObjectARBPROCÂ Â Â = Cptr(PFNglUseProgramObjectARBPROC, glfwGetProcAddress( "glUseProgramObjectARB" ))
Dim glLinkProgramARBÂ Â Â Â Â As PFNglLinkProgramARBPROCÂ Â Â Â Â = Cptr(PFNglLinkProgramARBPROC, glfwGetProcAddress( "glLinkProgramARB" ))
Dim glValidateProgramARBÂ Â Â As PFNglValidateProgramARBPROCÂ Â Â = Cptr(PFNglValidateProgramARBPROC, glfwGetProcAddress( "glValidateProgramARB" ))
Dim glGetObjectParameterivARB As PFNglGetObjectParameterivARBPROC = Cptr(PFNglGetObjectParameterivARBPROC, glfwGetProcAddress( "glGetObjectParameterivARB" ))
Dim glGetInfoLogARBÂ Â Â Â Â Â As PFNglGetInfoLogARBPROCÂ Â Â Â Â Â = Cptr(PFNglGetInfoLogARBPROC, glfwGetProcAddress( "glGetInfoLogARB" ))
Dim glGetUniformLocationARB As PFNglGetUniformLocationARBPROC = Cptr(PFNglGetUniformLocationARBPROC, glfwGetProcAddress( "glGetUniformLocationARB" ))
Dim glUniform1iARB As PFNglUniform1iARBPROC = Cptr(PFNglUniform1iARBPROC, glfwGetProcAddress( "glUniform1iARB" ))
Dim glUniform2fvARB As PFNglUniform2fvARBPROC = Cptr(PFNglUniform2fvARBPROC, glfwGetProcAddress( "glUniform2fvARB" ))
If glfwExtensionSupported( "GL_ARB_shader_objects" ) = 0 Then
  Print "Error: ARB shader objects extension not supported."
  Sleep 1000
  End -1
End If
If( glCreateShaderObjectARB = 0 ) Then
  Print "Error: glCreateShaderObjectARB not present."
  Sleep 1000
  End -1
End If
If( glCreateProgramObjectARB = 0 ) Then
  Print "Error: glCreateProgramObjectARB not present."
  Sleep 1000
  End -1
End If
If( glShaderSourceARB = 0 ) Then
  Print "Error: glShaderSourceARB not present."
  Sleep 1000
  End -1
End If
Dim As Integer Line_Cnt
Dim As String Shader_Text, tString
Dim As Integer i, x, y, Scale = 8
Dim As Integer Dist
Dim As GlHandleARB Vertex_Shader, Fragment_Shader, Vertex_Program, Fragment_Program
Dim As Gluint Shader_Compile_Success
Restore Vertex_Shader_Data
Read Line_Cnt
For i = 1 To Line_Cnt
  Read tString
  Shader_Text + = tString + Chr( 13, 10 )
Next
Print "Vertex Shader" + + Chr( 13, 10 )
Print Shader_Text
Dim As GLcharARB Ptr table(0) => { Strptr( Shader_Text ) }
Vertex_Shader = glCreateShaderObjectARB( GL_VERTEX_SHADER )
glShaderSourceARB( Vertex_Shader, 1, @table(0), 0 )
glCompileShaderARB( Vertex_Shader )
glGetObjectParameterivARB(Vertex_Shader, GL_OBJECT_COMPILE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Dim As Gluint infologsize
  glGetObjectParameterivARB( Vertex_Shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, @infoLogSize)
  Dim As GlByte infolog(InfoLogSize)
  glGetInfoLogARB(Vertex_Shader, InfoLogSize, 0, @infoLog(0))
  tString=""
  For i = 0 To InfoLogSize-1
    tString+=Chr(InfoLog(i))
  Next
 Â
  Print "Vertex Shader Infolog error message :("
  Print tString
End If
Restore Fragment_Shader_Data
Shader_Text = ""
tString=""
Read Line_Cnt
For i = 1 To Line_Cnt
  Read tString
  Shader_Text += tString + Chr( 13, 10 )
Next
Print "Fragment Shader"Â + Chr( 13, 10 )
Print Shader_Text
Dim As GLcharARB Ptr Frag_table(0) => { Strptr( Shader_Text ) }
Fragment_Shader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER )
glShaderSourceARB( Fragment_Shader, 1, @Frag_table(0), 0 )
glCompileShaderARB( Fragment_Shader )
glGetObjectParameterivARB(Fragment_Shader, GL_OBJECT_COMPILE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Dim As Gluint infologsize
  glGetObjectParameterivARB( Fragment_Shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, @infoLogSize)
  Dim As GlByte infolog(InfoLogSize)
  glGetInfoLogARB(Fragment_Shader, InfoLogSize, 0, @infoLog(0))
  tString=""
  For i = 0 To InfoLogSize-1
    tString+=Chr(InfoLog(i))
  Next
 Â
  Print "Fragment Shader Infolog error message :("
  Print tString
End If
Vertex_Program = GlCreateProgramObjectARB()
glAttachObjectARB( Vertex_Program, Vertex_Shader )
glLinkProgramARB( Vertex_Program )
Fragment_Program = GlCreateProgramObjectARB()
glAttachObjectARB( Fragment_Program, Fragment_Shader )
glLinkProgramARB( Fragment_Program )
GlValidateProgramARB( Vertex_Program )
glGetObjectParameterivARB( Vertex_Program, GL_OBJECT_VALIDATE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Beep
  Print "ARGHHHH!!!! GLSL program failed to compile. :("
  Sleep 1000
End If
GlValidateProgramARB( Fragment_Program )
glGetObjectParameterivARB( Fragment_Program, GL_OBJECT_VALIDATE_STATUS_ARB, @Shader_Compile_Success )
If Shader_Compile_Success = 0 Then
  Beep
  Print "ARGHHHH!!!! GLSL program failed to compile. :("
  Sleep 1000
End If
Dim As GLINT Sampler0Loc = glGetUniformLocationARB( Fragment_Program, Strptr("sampler0") )
Dim As GLINT tc_offsetLoc = glGetUniformLocationARB( Fragment_Program, Strptr("tc_offset") )
Dim As Vector2D tc_offset(8)
i=0
For y = -1 To 1
  For x = -1 To 1
    tc_offset(i).x = x/Depth
    tc_offset(i).y = y/Depth
    i+=1
  Next
 Â
Next
GLEnable GL_VERTEX_PROGRAM_POINT_SIZE_ARB
Dim Sphere As GLUquadricObj Ptr
Sphere = gluNewQuadric
gluQuadricDrawStyle Sphere, GLU_FILL
gluQuadricNormals Sphere, GLU_SMOOTH
gluQuadricOrientation Sphere, GLU_OUTSIDE
Dim As Single LightPos(2) => {0, 0, 100}
GlEnable GL_LIGHTING
GlEnable GL_Light0
glLightfv GL_LIGHT0, GL_POSITION, @LightPos(0)
For i = 1 To Max_Balls
  Init_Ball( Ball(i), Display )
  Ball(i).y = -i
Next
Do
 Â
 Â
  glUseProgramObjectARB( Vertex_Program )
  GlViewPort ( 0, 0, 512, 512 )
 Â
  GlClear( GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
  GlMatrixMode GL_Modelview
  GlLoadIdentity
  GlEnable GL_LIGHTING
  glLightfv GL_LIGHT0, GL_POSITION, @LightPos(0)
  GluLookat (0,0,100, 0,0,-1, 0,1,0)
  glPolygonMode GL_FRONT, GL_POINT'FILL
  For i = 1 To Max_Balls   Â
    Ball(i).x += Ball(i).dx
    Ball(i).y += Ball(i).dy
    Ball(i).z += Ball(i).dz
   Â
    Ball(i).dy-=.1
   Â
    If Ball(i).y<-100 Then
      Init_Ball( Ball(i), Display )
    End If
    GlPushMatrix
    GlTranslateF Ball(i).X, Ball(i).Y, Ball(i).Z
    GlRotateF Ball(i).y*50, 1, 0, 0
    GlColor4F Ball(i).R, Ball(i).G, Ball(i).B, 1
    gluSphere Sphere, Ball(i).Rad, 16, 16
    GlPopMatrix
  Next
 Â
  GlEnable GL_TEXTURE_2D
  glBindTexture(GL_TEXTURE_2D, Buffer)
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512)
 Â
  GlClear GL_COLOR_BUFFER_BIT
  glUseProgramObjectARB( Fragment_Program )
  'glUseProgramObjectARB( 0 )
  glUniform1iARB(Sampler0Loc, 0 )
  glUniform2fvARB(tc_offsetLoc, 9, @tc_offset(0).X)
  GlViewPort ( 0, 0, Display.W, Display.H )
  glPolygonMode GL_FRONT, GL_FILL
  Set_Ortho( Display )
  glBindTexture(GL_TEXTURE_2D, Buffer) Â
  GlDisable GL_LIGHTING
  GlColor3F 1,1,1
  GlBegin GL_QUADS
  GlTexCoord2D 1,0
  GlVertex3F Display.W,0,0
 Â
  GlTexCoord2D 1,1
  GlVertex3F Display.W,Display.H,0
 Â
  GlTexCoord2D 0,1
  GlVertex3F 0,Display.H,0
 Â
  GlTexCoord2D 0,0
  GlVertex3F 0,0,0
  GlEnd
 Â
  Drop_Ortho( Display )
  GlDisable GL_TEXTURE_2D
 Â
  GlfwSwapBuffers
Loop Until glfwGetKey( GLFW_KEY_ESC )
GluDeleteQuadric Sphere
GlDeleteObjectArb( Vertex_Shader )
GlDeleteObjectArb( Fragment_Shader )
GlDeleteObjectArb( Vertex_Program )
GlDeleteObjectArb( Fragment_Program )
GlfwTerminate()
End
Sub Init_Ball( Ball As Balls, Display As DisplayMode)
 Â
    Ball.x = -5+Rnd*10
    Ball.y = -25'+Rnd*30
    Ball.z = -50+(RND*20)
   Â
    Ball.dx = Ball.x/10
    Ball.dy = 2+Rnd*2
    Ball.dz = -Ball.z/50
   Â
    Ball.Rad = 10'5+Rnd*10
    Ball.R = .5+Rnd
    Ball.G = .5+Rnd
    Ball.B = .5+Rnd
End Sub
Sub Set_Ortho( Display As DisplayMode )
  GlMatrixMode( Gl_Projection )
  GlPushMatrix
  GlLoadIdentity
  GlMatrixMode( Gl_Modelview )
  GlPushMatrix
  GlLoadIdentity
  GlOrtho( 0, Display.W, 0, Display.H, -1, 1 )
End Sub
Sub Drop_Ortho( Display As DisplayMode )
  GlMatrixMode( Gl_Projection )
  GlPopMatrix
  GlMatrixMode( Gl_Modelview )
  GlPopMatrix
End Sub
Sub Init_GL_Window( Display As DisplayMode )
  Display.W   = 800
  Display.H   = 600
  Display.R_BITS= 8
  Display.G_BITS= 8
  Display.B_BITS= 8
  Display.A_BITS= 8
  Display.D_BITS= 24
  Display.S_BITS= 8
  Display.MODE = GLFW_WINDOW
 Â
  If glfwInit() Then
    'Successful!
  Else Â
    Print "Failed to initialize GLFW!"
    Sleep 1000
    End
  End If
 Â
 Â
  If glfwOpenWindow( _
  Display.W   , _
  Display.H   , _
  Display.R_BITS, _
  Display.G_BITS, _
  Display.B_BITS, _
  Display.A_BITS, _
  Display.D_BITS, _
  Display.S_BITS, _
  Display.MODE ) _
  Then
  GlfwSwapInterval 1
  Display.GlVer = glGetString(GL_VERSION)
Else
  GlfwTerminate()
  End
End If
'To check, use... glfwGetWindowParam()
' OpenGL specific stuff...
glViewport 0, 0, Display.W, Display.H
glMatrixMode GL_PROJECTIONÂ Â Â Â
glLoadIdentity Â
Display.FOVy = 45.0
Display.Aspect = Display.W / Display.H
Display.znear = 1
Display.zfar = 1000
gluPerspective Display.FOVy, Display.Aspect, Display.zNear, Display.zFar
glShadeModel GL_SMOOTH
glClearColor 0.0, 0.0, 0.0, 0.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glEnable GL_COLOR_MATERIAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
glPolygonMode GL_FRONT, GL_POINT
glEnable GL_CULL_FACE
End Sub
Vertex_Shader_Data:
Data 10
Data "void main(void)"
Data "{"
Data "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
Data "vec4 V = gl_ModelViewMatrix * gl_Vertex;"
Data "gl_FrontColor = gl_Color;"
Data "float ptSize = length(V);"
Data "ptSize *= ptSize;"
Data "gl_PointSize =Â (ptSize/1000.0);"
Data "gl_FrontColor = gl_FrontColor - (gl_PointSize / 16.0);"
Data "}"
Fragment_Shader_Data:
Data 11
Data "uniform sampler2D sampler0;"
Data "uniform vec2 tc_offset[9];"
Data "void main(void)"
Data "{"
Data "vec4 sample[9];"
Data "for (int i = 0; i < 9; i++)"
Data "{"
Data "sample[i]Â = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);"
Data "}"
Data "gl_FragColor = (sample[0] + sample[1] + sample[2] + sample[3] + sample[4] + sample[5] + sample[6] + sample[7] + sample[8])/16.0;"
Data "}"
-
Again I'm unable to run, everyone else will have to tell me how cool this is !
-
I can't get it to accept the gl commands proceeding @numbers.
-
I can't get it to accept the gl commands proceeding @numbers.
Hmmm... what version of FB are you using again? I remember that an older version of FB allowed to access gl ptr's without the @ operator, but it wont now.
-
Im using the new, Testing version 0.17b jul 21st release.
-
Can you try this attachment please? It's just the compiled code up there. Thanks.
-
Yep the exe works mate, and Cool effect dude.
-
Thanks... I think I know why it wont compile for you. There was a problem with the GL header files, for some reason. Here is a zip with the headers I've been using. It should work, if you use these... I think. O0
-
I've just replaced the new ones you supplied, but Im getting the same error log. Very strange.
-
That is strange. Are you able to run any of the gl example files included with the compiler?
-
No mate, none of the examples work for me. ???
-
screenshots please. Black screen of death here. Nvemulate on.
-
Damn. I don't understand why it wont even run with nvemulate. Here's a screenshot anyway.
(http://fileanchor.com/47924-t.jpeg) (http://fileanchor.com/47924.jpeg)
-
Yep thats the cool effect I get to see from the exe version.
-
The exe works here, it will not compile though.
The exe is really cool. Nice effect :)
-
I got the same issue on my ATI card with latest drivers...I wouldnt worry shaders have changed a lot in the last few years/months so its no surprise. Maybe you should try the shader in rendermonkey or some equivalent and see if they verify it and its just dodgy ATI drivers.
-
Very nice effects - thanks for posting the code - I didn't have a clue about gl code until I looked at this!!!
DrewPee