Aktuelle Zeit: 20.09.2019 01:15

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 17 Beiträge ]  Gehe zu Seite 1, 2  Nächste
Autor Nachricht
 Betreff des Beitrags: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 14:06 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo Leute,

ich habe dieses Beispiel im Forum gefunden:

Code:
;/ GLSL example to test new OpenGLGadget - PJ 06/2014.

;EnableExplicit
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  CompilerIf Subsystem("OpenGL") = #False
    MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
    End
  CompilerEndIf
CompilerEndIf

CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
  Import ""
    glXGetProcAddress(s.p-ascii) As "glXGetProcAddress"
  EndImport
 
CompilerCase #PB_OS_Windows
  CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
    Import "opengl32.lib"
      wglGetProcAddress(s.p-ascii) As "_wglGetProcAddress@4"
    EndImport
   
  CompilerElse   
    Import "opengl32.lib"
      wglGetProcAddress(s.p-ascii) As "wglGetProcAddress"
    EndImport
   
  CompilerEndIf
 
CompilerDefault
  CompilerError "Unsupported OS"
 
CompilerEndSelect



Enumeration ;/ Window
  #Window_Main
EndEnumeration
Enumeration ;/ Gadget
  #Gad_OpenGL
  #Gad_Editor
  #Gad_ShaderSelector_Combo
EndEnumeration
Enumeration ;/ Menu
  #Menu_Open
  #Menu_Save
  #Menu_Run
EndEnumeration


Structure System
  Width.i
  Height.i
  Shader_Width.i
  Shader_Height.i
  Event.i
  Exit.i
  MouseX.i
  MouseY.i
 
  App_CurrentTime.i
  App_StartTime.i
  Editor_LastText.s
 
  Shader_Vertex_Text.s
  Shader_Fragment_Text.s
  Shader_Vertex.i
  Shader_Fragment.i
  Shader_Program.i
 
  Shader_Uniform_Time.i
  Shader_Uniform_Resolution.i
  Shader_Uniform_Mouse.i
  Shader_Uniform_SurfacePosition.i
 
  FPS_Timer.i
  Frames.i
  FPS.i
EndStructure

Global System.System

Procedure Init_Main()
  Protected MyLoop.i
 
  System\Width.i = 1024
  System\Height = 480
  System\Shader_Width = 640
  System\Shader_Height = 480
 
  OpenWindow(#Window_Main,0,0,System\Width, System\Height,"",#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(#Window_Main), 0, 0, WindowWidth(#Window_Main)-170, WindowHeight(#Window_Main), 0, 0, 0)
 
    CreateCamera(1, 0, 0, 100, 100)
    MoveCamera(1, -100, 120, 190, #PB_Absolute)
    CameraLookAt(1, 0, 0, 0)
   
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 90, 60, 0, #PB_Absolute)
    CameraLookAt(0, 0, 0, 0)
    CameraFOV(0, 80)
    CameraProjectionMode(0, #PB_Camera_Perspective)

    ;Miroir
    ;CreateRenderTexture(1, CameraID(0), 800, 600)
    CreateRenderTexture(1, CameraID(0), CameraViewWidth(0), CameraViewHeight(0), #PB_Texture_AutomaticUpdate)
    CreateMaterial(1, TextureID(1))
   
  If CreateMenu(0, WindowID(#Window_Main))
    MenuTitle("File")
    MenuItem(#Menu_Open,"Open")
    MenuItem(#Menu_Save,"Save")
    MenuBar()
    MenuItem(#Menu_Run,"Run Shader")
   
  EndIf
 
  ;OpenGLGadget(#Gad_OpenGL,0,0,System\Shader_Width,System\Shader_Height,#PB_OpenGL_Keyboard)
  ComboBoxGadget(#Gad_ShaderSelector_Combo,System\Shader_Width+4,2,System\Width - (System\Shader_Width+8),24)
AddGadgetItem(#Gad_ShaderSelector_Combo,-1,"Shader: "+Str(1))

 
  ;SetGadgetState(#Gad_ShaderSelector_Combo,0)
  EditorGadget(#Gad_Editor,System\Shader_Width+4,30,System\Width - (System\Shader_Width+8),System\Height-30)
 
  System\App_StartTime = ElapsedMilliseconds()
 
 
  System\Shader_Vertex_Text = "attribute vec3 position;"
  System\Shader_Vertex_Text + "attribute vec2 surfacePosAttrib;"
  System\Shader_Vertex_Text + "varying vec2 surfacePosition;"
  System\Shader_Vertex_Text + "   void main() {"
  System\Shader_Vertex_Text + "      surfacePosition = surfacePosAttrib;"
  System\Shader_Vertex_Text + "      gl_Position = vec4( position, 1.0 );"
  System\Shader_Vertex_Text + "   }"
EndProcedure

Init_Main()

;{ Opengl shader setup & routines

#GL_VERTEX_SHADER = $8B31
#GL_FRAGMENT_SHADER = $8B30

Prototype glCreateShader(type.l)
Prototype glCreateProgram()
Prototype glCompileShader(shader.l)
Prototype glLinkProgram(shader.l)
Prototype glUseProgram(shader.l)
Prototype glAttachShader(Program.l, shader.l)
Prototype glShaderSource(shader.l, numOfStrings.l, *strings, *lenOfStrings) :
Prototype.i glGetUniformLocation(Program.i, name.s)
Prototype glUniform1i(location.i, v0.i)
Prototype glUniform2i(location.i, v0.i, v1.i)
Prototype glUniform1f(location.i, v0.f)
Prototype glUniform2f(location.i, v0.f, v1.f)
Prototype glGetShaderInfoLog(shader.i, bufSize.l, *length_l, *infoLog)

Prototype.i glGetProcAddress(name.s)

CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
  Global glGetProcAddress.glGetProcAddress = @glXGetProcAddress()
 
CompilerCase #PB_OS_Windows
  Global glGetProcAddress.glGetProcAddress = @wglGetProcAddress()
 
CompilerDefault
  CompilerError "Unsupported OS"
 
CompilerEndSelect

Global glCreateShader.glCreateShader = glGetProcAddress("glCreateShader")
Global glCreateProgram.glCreateProgram = glGetProcAddress("glCreateProgram")
Global glCompileShader.glCompileShader = glGetProcAddress("glCompileShader")
Global glLinkProgram.glLinkProgram = glGetProcAddress("glLinkProgram")
Global glUseProgram.glUseProgram = glGetProcAddress("glUseProgram")
Global glAttachShader.glAttachShader = glGetProcAddress("glAttachShader")
Global glShaderSource.glShaderSource = glGetProcAddress("glShaderSource")
Global glGetUniformLocation.glGetUniformLocation = glGetProcAddress("glGetUniformLocation")
Global glUniform1i.glUniform1i = glGetProcAddress("glUniform1i")
Global glUniform2i.glUniform2i = glGetProcAddress("glUniform2i")
Global glUniform1f.glUniform1f = glGetProcAddress("glUniform1f")
Global glUniform2f.glUniform2f = glGetProcAddress("glUniform2f")
Global glGetShaderInfoLog.glGetShaderInfoLog = glGetProcAddress("glGetShaderInfoLog")

Procedure Shader_Compile_Link_Use(Vertex.s,Fragment.s,Use.i=1)
  Protected VertShader.i, FragShader.i, *TxtPointer, Program.i
  Protected Textlength.i, Mytext.s = Space(1024)
 
  ;/ Compile Vertex shader
  VertShader.i = glCreateShader(#GL_VERTEX_SHADER)
  *TxtPointer = Ascii(Vertex)
  glShaderSource(VertShader, 1, @*TxtPointer, #Null)
  glCompileShader(VertShader)
  ;debug "Vert: "+VertShader
  glGetShaderInfoLog(VertShader,1023,@Textlength,@Mytext)
  ;debug MyText
  ;/ Compile Fragment Shader
  FragShader.i = glCreateShader(#GL_FRAGMENT_SHADER)
  *TxtPointer = Ascii(Fragment)
  glShaderSource(FragShader, 1, @*TxtPointer, #Null)
  glCompileShader(FragShader)
  ;debug "Frag: "+FragShader
  glGetShaderInfoLog(FragShader,1023,@Textlength,@Mytext)
  ;debug MyText
 
  ;/ Create Shader Program
  Program = glCreateProgram()
  glAttachShader(Program,VertShader)
  ;debug "Attached Vert Shader"
  glAttachShader(Program,FragShader)
  ;debug "Attached Frag Shader"
  glLinkProgram(Program)
  ;debug "Link program"
 
  If Use = 1
    glUseProgram(Program)
  EndIf
 
  ProcedureReturn Program
EndProcedure
;}

Procedure Shader_Set(Fragment.i, shader$="")
 
  If System\Shader_Program <> 0 ;/ delete the previous shaders
    glUseProgram(0);
  EndIf
 
  If Fragment = -2 ; run the shader   
    System\Shader_Fragment_Text = GetGadgetText(#Gad_Editor)   
  ElseIf Fragment = -1 ; load the shader
      System\Shader_Fragment_Text = shader$+Chr(10)
  Else
   
   Select Fragment
    Case 0
      System\Shader_Fragment_Text = "uniform float time;"+Chr(10)
      System\Shader_Fragment_Text + "uniform vec2 resolution;"+Chr(10)
      System\Shader_Fragment_Text + ""+Chr(10)
      System\Shader_Fragment_Text + "void main( void ) {"+Chr(10)
      System\Shader_Fragment_Text + "   vec2 p = ( gl_FragCoord.xy / resolution.xy ) - 0.2;"+Chr(10)
      System\Shader_Fragment_Text + "   float sx = 0.3 * (p.x + 0.8) * sin( 3.0 * p.x - 1. * time);"+Chr(10)
      System\Shader_Fragment_Text + "   float dy = 4./ ( 123. * abs(p.y - sx));"+Chr(10)
      System\Shader_Fragment_Text + "   dy += 1./ (160. * length(p - vec2(p.x, 0.)));"+Chr(10)
      System\Shader_Fragment_Text + "   gl_FragColor = vec4( (p.x + 0.1) * dy, 0.3 * dy, dy, 2.1 );"+Chr(10)
      System\Shader_Fragment_Text + "}"+Chr(10)
   
   
   
     
  EndSelect
 
  EndIf

  System\Shader_Program = Shader_Compile_Link_Use(System\Shader_Vertex_Text,System\Shader_Fragment_Text)
 
  If System\Shader_Program = 0
    MessageRequester("Unsupported Device?","No Shader Support Available",#PB_MessageRequester_Ok)
    End
  EndIf
 
  ;/ store shader uniform locations
  ;debug "Shader: "+System\Shader_Program
  System\Shader_Uniform_Time = glGetUniformLocation(System\Shader_Program, "time")
  System\Shader_Uniform_Mouse = glGetUniformLocation(System\Shader_Program, "mouse")
  System\Shader_Uniform_Resolution = glGetUniformLocation(System\Shader_Program, "resolution")
  System\Shader_Uniform_SurfacePosition.i = glGetUniformLocation(System\Shader_Program, "surfacePosition")
  ;debug "Time location: "+System\Shader_Uniform_Time
  ;debug "Mouse location: "+System\Shader_Uniform_Mouse
  ;debug "Res location: "+System\Shader_Uniform_Resolution
  ;debug "SurfacePos location: "+System\Shader_Uniform_SurfacePosition
 
  SetGadgetText(#Gad_Editor,System\Shader_Fragment_Text)
 
EndProcedure

Procedure OpenShader()
  Define filename$ ="", txt$ = ""
 
  filename$ = OpenFileRequester("Open shader","","All|*.*",0)
 
  If filename$ <> ""
   
    If ReadFile(0, filename$)
      While Eof(0) = 0           
        txt$ + ReadString(0) +Chr(10)
      Wend
      CloseFile(0)
      Shader_Set(-1,txt$)

    Else
      MessageRequester("Information","Impossible d'ouvrir le fichier!")
    EndIf

  EndIf
 
EndProcedure
Procedure SaveShader()
  Define filename$ =""
 
  filename$ = SaveFileRequester("Save","","txt|*.txt",0)
 
  If filename$ <> ""
   
    If OpenFile(0, filename$)
      WriteStringN(0, GetGadgetText(#Gad_Editor))
      CloseFile(0)
    EndIf
   
  EndIf
 
EndProcedure
Procedure RunShader()
 
  Shader_Set(-2)
 
EndProcedure

Shader_Set(0)

Procedure Render()
  ;/ set shader Uniform values
  glUniform2f(System\Shader_Uniform_Resolution,System\Shader_Width,System\Shader_Height)
  glUniform1f(System\Shader_Uniform_Time,(System\App_CurrentTime-System\App_StartTime) / 1000.0)
  glUniform2i(System\Shader_Uniform_SurfacePosition.i,1.0,1.0)
 
  glBegin_(#GL_QUADS)
    glVertex2f_(-1,-1)
    glVertex2f_( 1,-1)
    glVertex2f_( 1, 1)
    glVertex2f_(-1, 1)
  glEnd_()           
 
  System\Frames + 1
  If System\App_CurrentTime > System\FPS_Timer
    System\FPS = System\Frames
    System\Frames = 0
    System\FPS_Timer = System\App_CurrentTime  + 1000
    SetWindowTitle(#Window_Main,"GLSL Testing - PJ 07/06/2014 - FPS: "+Str(System\FPS))
  EndIf
 
  ;SetGadgetAttribute(#Gad_OpenGL,#PB_OpenGL_FlipBuffers,1)
     
  ;FlipBuffers()
 
EndProcedure

;CreateRenderTexture(1, CameraID(0), CameraViewWidth(0), CameraViewHeight(0), #PB_Texture_AutomaticUpdate)
;CreateMaterial(9, TextureID(9))

Repeat
 
  Repeat
   
    System\Event = WindowEvent()
   
    Select System\Event
       
      Case #PB_Event_Menu
        Select EventMenu()
          Case #Menu_Open
            OpenShader()
          Case #Menu_Save
            SaveShader()
          Case #Menu_Run
            RunShader()
           
        EndSelect
       
      Case #PB_Event_CloseWindow       
        System\Exit = #True
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Gad_ShaderSelector_Combo
            Select EventType()
              Case #PB_EventType_Change
                ;debug "Set to: "+GetGadgetState(#Gad_ShaderSelector_Combo)
                Shader_Set(GetGadgetState(#Gad_ShaderSelector_Combo))
            EndSelect
          Case #Gad_OpenGL
            Select EventType()
              Case #PB_EventType_MouseMove
                System\MouseX = GetGadgetAttribute(#Gad_OpenGL,#PB_OpenGL_MouseX)
                System\MouseY = GetGadgetAttribute(#Gad_OpenGL,#PB_OpenGL_MouseY)
                glUniform2f(System\Shader_Uniform_Mouse,System\MouseX / System\Shader_Width,(System\Shader_Height-System\MouseY) / System\Shader_Height)
            EndSelect
        EndSelect
    EndSelect
   
  Until System\Event = 0
 
 
  System\App_CurrentTime = ElapsedMilliseconds()
 
  RenderWorld()
  Render()
  FlipBuffers()
   
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Space)
    t+1
   
   If flag=0
     FreeCamera(1)
     flag=1
   EndIf
   
   If t=1
     
     SaveRenderTexture(1, "empty.png")
   Else
   
   No + 1
   SaveRenderTexture(1, "test" + Str(No) + ".png")
   
 EndIf
 
  EndIf
 If KeyboardReleased(#PB_Key_Z)
   If IsCamera(1) = 0
   flag=0 : t=0
   CreateCamera(1, 0, 0, 100, 100)
   EndIf
 EndIf
 
 
Until System\Exit


Ich bekomme aber unter Linux immer einen Speicherfehler bei: glCreateShader

Ich glaube es liegt irgentwie an glew (glew_init fehlt, oder ?)

Wie bekomme ich das unter Linux zum laufen ?

Also das hier liefert bei mir:

ImportC "-lGLEW"
glewInit()
EndImport

und der Aufruf:

Debug glewInit()

liefert bei mir 0


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 16:09 
Offline
Benutzeravatar

Registriert: 20.04.2006 09:50
Scheint bei mir zu laufen. Ubuntu 18, pb570b2 x64.

_________________
my pb stuff..
Bild..jedenfalls war das mal so.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 16:17 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo #Null,

bei mir nicht, aber ich habe den Fehler gefunden.

Prototype.i glGetProcAddress(name.p-ascii) ;Hier muss man natürlich auch eine Übergabe als Ascii machen

:::::::::::::::::::::::::::::::::::::

Wie kann ich jetzt eine Textur (Bild) manipulieren ?

Wie müsste die Übergabe und der Shader aussehen ?

OpenGL-Gadget-Beispiel
Code:
EnableExplicit
InitSprite()

UsePNGImageDecoder()
UseJPEGImageDecoder()

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    Import ""
      glXGetProcAddress(s.p-ascii) As "glXGetProcAddress"
    EndImport
   
  CompilerCase #PB_OS_Windows
    CompilerIf Subsystem("OpenGL") = #False
      MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
      End
    CompilerEndIf
   
    CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
      Import "opengl32.lib"
        wglGetProcAddress(s.p-ascii) As "_wglGetProcAddress@4"
      EndImport
     
    CompilerElse   
      Import "opengl32.lib"
        wglGetProcAddress(s.p-ascii) As "wglGetProcAddress"
      EndImport
     
    CompilerEndIf
   
  CompilerDefault
    CompilerError "Unsupported OS"
   
CompilerEndSelect

Enumeration ;/ Window
  #Window_Main
EndEnumeration
Enumeration ;/ Gadget
  #Gad_Editor
  #Gad_ShaderSelector_Combo
EndEnumeration
Enumeration ;/ Menu
  #Menu_Open
  #Menu_Save
  #Menu_Run
EndEnumeration

Structure System
  Width.i
  Height.i
  Shader_Width.i
  Shader_Height.i
  Event.i
  Exit.i
  MouseX.i
  MouseY.i
 
  App_CurrentTime.i
  App_StartTime.i
  Editor_LastText.s
 
  Shader_Vertex_Text.s
  Shader_Fragment_Text.s
  Shader_Vertex.i
  Shader_Fragment.i
  Shader_Program.i
 
  Shader_Uniform_Time.i
  Shader_Uniform_Resolution.i
  Shader_Uniform_Mouse.i
  Shader_Uniform_SurfacePosition.i
 
  FPS_Timer.i
  Frames.i
  FPS.i
EndStructure

Global System.System

#GL_TEXTURE_RECTANGLE_NV=$84F5
#GL_CLAMP_TO_EDGE=$812F

Global Dim glTextureIDs.i(0)
Global screenGL, screenColor=RGBA(0, 0, 0, 0), image
Global glSpriteTexture, w, h, tint=RGB(255, 255, 255)
Global scaleX.f=1.0, scaleY.f=1.0

Global *DrawGLBuffer

Procedure SetupGL(screenW, screenH)
 
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  glOrtho_(0, screenW, 0, screenH, -5.0, 5.0)
 
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
 
  glEnable_(#GL_CULL_FACE)
 
  glPushAttrib_(#GL_DEPTH_BUFFER_BIT | #GL_LIGHTING_BIT);
 
  glDisable_(#GL_DEPTH_TEST)
 
  glDisable_(#GL_LIGHTING)
 
  glDisable_(#GL_BLEND)
EndProcedure

Procedure.i LoadTextureGL(image)
  ;// Generate 100 texture IDs (only one time)
  If ArraySize(glTextureIDs())=0
    ReDim glTextureIDs(100)
    glGenTextures_(ArraySize(glTextureIDs()), @glTextureIDs())
  EndIf
  Static glTextureID=0
 
  ;// Enable the texture rectangle extension
  glEnable_(#GL_TEXTURE_RECTANGLE_NV)
 
  ;// Bind the texture using #GL_TEXTURE_RECTANGLE_NV
  glTextureID + 1
  glBindTexture_(#GL_TEXTURE_RECTANGLE_NV, glTextureIDs(glTextureID))
 
  ;// Enable NEAREST filtering on this texture (for old school style)
  glTexParameteri_(#GL_TEXTURE_RECTANGLE_NV, #GL_TEXTURE_MIN_FILTER, #GL_NEAREST)
  glTexParameteri_(#GL_TEXTURE_RECTANGLE_NV, #GL_TEXTURE_MAG_FILTER, #GL_NEAREST)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_WRAP_S, #GL_CLAMP_TO_EDGE);
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_WRAP_T, #GL_CLAMP_TO_EDGE);
 
  ;// Write the 32-bit RGBA texture buffer To video memory
  StartDrawing(ImageOutput(image))
  ;glTexImage2D_(#GL_TEXTURE_RECTANGLE_NV, 0, #GL_RGBA, ImageWidth(image), ImageHeight(image), 0, #GL_BGRA_EXT, #GL_UNSIGNED_BYTE, DrawingBuffer())
  glTexImage2D_(#GL_TEXTURE_RECTANGLE_NV, 0, #GL_RGBA, ImageWidth(image), ImageHeight(image), 0, #GL_RGBA, #GL_UNSIGNED_BYTE, DrawingBuffer())
  StopDrawing()
 
  ProcedureReturn glTextureIDs(glTextureID)
EndProcedure

Procedure Init_Main()
  Protected MyLoop.i
 
  System\Width.i = 1024
  System\Height = 480
  System\Shader_Width = 640
  System\Shader_Height = 480
 
  OpenWindow(#Window_Main,0,0,System\Width, System\Height,"",#PB_Window_SystemMenu)
  ;OpenWindowedScreen(WindowID(#Window_Main), 0, 0, 640, 480)
  screenGL=OpenGLGadget(#PB_Any, 0, 0, 640, 480)
 
  SetupGL(640, 480)
 
  ;-OpenGL-Image ?
  LoadImage(0, "render.jpeg")
  w=640 : h=480
  image=CreateImage(#PB_Any, w, h, 32, RGB(255, 255, 255)) ; white background
  If StartDrawing(ImageOutput(image))
    DrawImage(ImageID(0), 0, 0, ImageWidth(image), ImageHeight(image))
    DrawText(10, 10, "Ich bin ein Bild.")
    StopDrawing()
   
    glSpriteTexture = LoadTextureGL(image)
  EndIf
 
  If CreateMenu(0, WindowID(#Window_Main))
    MenuTitle("File")
    MenuItem(#Menu_Open,"Open")
    MenuItem(#Menu_Save,"Save")
    MenuBar()
    MenuItem(#Menu_Run,"Run Shader")
  EndIf
 
  ComboBoxGadget(#Gad_ShaderSelector_Combo,System\Shader_Width+4,2,System\Width - (System\Shader_Width+8),24)
  AddGadgetItem(#Gad_ShaderSelector_Combo,-1,"Shader: "+Str(1))
 
 
  ;   SetGadgetState(#Gad_ShaderSelector_Combo,0)
  EditorGadget(#Gad_Editor,System\Shader_Width+4,30,System\Width - (System\Shader_Width+8),System\Height-30)
 
  System\App_StartTime = ElapsedMilliseconds()
 
  System\Shader_Vertex_Text = "attribute vec3 position;"
  System\Shader_Vertex_Text + "attribute vec2 surfacePosAttrib;"
  System\Shader_Vertex_Text + "varying vec2 surfacePosition;"
  System\Shader_Vertex_Text + "   void main() {"
  System\Shader_Vertex_Text + "      surfacePosition = surfacePosAttrib;"
  System\Shader_Vertex_Text + "      gl_Position = vec4( position-1.0, 1.0 );"
  System\Shader_Vertex_Text + "   }"
EndProcedure

Init_Main()

;{ Opengl shader setup & routines

#GL_VERTEX_SHADER = $8B31
#GL_FRAGMENT_SHADER = $8B30

Prototype glCreateShader(type.l)
Prototype glCreateProgram()
Prototype glCompileShader(shader.l)
Prototype glLinkProgram(shader.l)
Prototype glUseProgram(shader.l)
Prototype glAttachShader(Program.l, shader.l)
Prototype glShaderSource(shader.l, numOfStrings.l, *strings, *lenOfStrings)
Prototype.i glGetUniformLocation(Program.i, name.p-ascii)
Prototype glUniform1i(location.i, v0.i)
Prototype glUniform2i(location.i, v0.i, v1.i)
Prototype glUniform1f(location.i, v0.f)
Prototype glUniform2f(location.i, v0.f, v1.f)
Prototype glGetShaderInfoLog(shader.i, bufSize.l, *length_l, *infoLog)

Prototype.i glGetProcAddress(name.p-ascii)

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    Global glGetProcAddress.glGetProcAddress = @glXGetProcAddress()
   
  CompilerCase #PB_OS_Windows
    Global glGetProcAddress.glGetProcAddress = @wglGetProcAddress()
   
  CompilerDefault
    CompilerError "Unsupported OS"
   
CompilerEndSelect

Global glCreateShader.glCreateShader = glGetProcAddress("glCreateShader")
Global glCreateProgram.glCreateProgram = glGetProcAddress("glCreateProgram")
Global glCompileShader.glCompileShader = glGetProcAddress("glCompileShader")
Global glLinkProgram.glLinkProgram = glGetProcAddress("glLinkProgram")
Global glUseProgram.glUseProgram = glGetProcAddress("glUseProgram")
Global glAttachShader.glAttachShader = glGetProcAddress("glAttachShader")
Global glShaderSource.glShaderSource = glGetProcAddress("glShaderSource")
Global glGetUniformLocation.glGetUniformLocation = glGetProcAddress("glGetUniformLocation")
Global glUniform1i.glUniform1i = glGetProcAddress("glUniform1i")
Global glUniform2i.glUniform2i = glGetProcAddress("glUniform2i")
Global glUniform1f.glUniform1f = glGetProcAddress("glUniform1f")
Global glUniform2f.glUniform2f = glGetProcAddress("glUniform2f")
Global glGetShaderInfoLog.glGetShaderInfoLog = glGetProcAddress("glGetShaderInfoLog")

Procedure Shader_Compile_Link_Use(Vertex.s,Fragment.s,Use.i=1)
  Protected VertShader.i, FragShader.i, *TxtPointer, Program.i
  Protected Textlength.i, Mytext.s = Space(1024)
 
  ;/ Compile Vertex shader
  VertShader.i = glCreateShader(#GL_VERTEX_SHADER)
  *TxtPointer = Ascii(Vertex)
  glShaderSource(VertShader, 1, @*TxtPointer, #Null)
  glCompileShader(VertShader)
  ;debug "Vert: "+VertShader
  glGetShaderInfoLog(VertShader,1023,@Textlength,@Mytext)
  ;debug MyText
  ;/ Compile Fragment Shader
  FragShader.i = glCreateShader(#GL_FRAGMENT_SHADER)
  *TxtPointer = Ascii(Fragment)
  glShaderSource(FragShader, 1, @*TxtPointer, #Null)
  glCompileShader(FragShader)
  ;debug "Frag: "+FragShader
  glGetShaderInfoLog(FragShader,1023,@Textlength,@Mytext)
  ;debug MyText
 
  ;/ Create Shader Program
  Program = glCreateProgram()
  glAttachShader(Program,VertShader)
  ;debug "Attached Vert Shader"
  glAttachShader(Program,FragShader)
  ;debug "Attached Frag Shader"
  glLinkProgram(Program)
  ;debug "Link program"
 
  If Use = 1
    glUseProgram(Program)
  EndIf
 
  ProcedureReturn Program
EndProcedure
;}

Procedure Shader_Set(Fragment.i, shader$="")
 
  If System\Shader_Program <> 0 ;/ delete the previous shaders
    glUseProgram(0)             ;
  EndIf
 
  If Fragment = -2 ; run the shader   
    System\Shader_Fragment_Text = GetGadgetText(#Gad_Editor)   
  ElseIf Fragment = -1 ; load the shader
    System\Shader_Fragment_Text = shader$+Chr(10)
  Else
    Select Fragment
      Case 0
        System\Shader_Fragment_Text = "uniform vec2 resolution;"+Chr(10)
        System\Shader_Fragment_Text + "uniform float time;"+Chr(10)
        System\Shader_Fragment_Text + ""+Chr(10)
        System\Shader_Fragment_Text + "void main( void ) {"+Chr(10)
        System\Shader_Fragment_Text + "   vec2 st = gl_FragCoord.xy/resolution;"+Chr(10)
        System\Shader_Fragment_Text + "   gl_FragColor = vec4(st.x,st.y,0.0,1.0);"+Chr(10)
        System\Shader_Fragment_Text + "}"+Chr(10)
       
    EndSelect
  EndIf
 
  System\Shader_Program = Shader_Compile_Link_Use(System\Shader_Vertex_Text,System\Shader_Fragment_Text)
 
  If System\Shader_Program = 0
    MessageRequester("Error?","Kein Shader verfügbar",#PB_MessageRequester_Ok)
    End
  EndIf
 
  ;/ store shader uniform locations
  ;debug "Shader: "+System\Shader_Program
  System\Shader_Uniform_Time = glGetUniformLocation(System\Shader_Program, "time")
  ;System\Shader_Uniform_Mouse = glGetUniformLocation(System\Shader_Program, "mouse")
  System\Shader_Uniform_Resolution = glGetUniformLocation(System\Shader_Program, "resolution")
  System\Shader_Uniform_SurfacePosition.i = glGetUniformLocation(System\Shader_Program, "surfacePosition")
 
  Global u_image = glGetUniformLocation(System\Shader_Program, "u_image")
 
  Debug "Time location: "+System\Shader_Uniform_Time
  Debug "Mouse location: "+System\Shader_Uniform_Mouse
  Debug "Res location: "+System\Shader_Uniform_Resolution
  Debug "SurfacePos location: "+System\Shader_Uniform_SurfacePosition
 
  SetGadgetText(#Gad_Editor,System\Shader_Fragment_Text)
 
EndProcedure

Procedure OpenShader()
  Define filename$ ="", txt$ = ""
 
  filename$ = OpenFileRequester("Öffne Shader","","All|*.*",0)
 
  If filename$ <> ""
   
    If ReadFile(0, filename$)
      While Eof(0) = 0           
        txt$ + ReadString(0) +Chr(10)
      Wend
      CloseFile(0)
      Shader_Set(-1,txt$)
     
    Else
      MessageRequester("Information","Kann die Datei nicht öffnen!")
    EndIf
   
  EndIf
 
EndProcedure
Procedure SaveShader()
  Define filename$ =""
 
  filename$ = SaveFileRequester("Save","","txt|*.txt",0)
 
  If filename$ <> ""
   
    If OpenFile(0, filename$)
      WriteStringN(0, GetGadgetText(#Gad_Editor))
      CloseFile(0)
    EndIf
   
  EndIf
 
EndProcedure
Procedure RunShader()
 
  Shader_Set(-2)
 
EndProcedure

Shader_Set(0)

Procedure Render()
  ;ClearScreen(RGB(0,0,100))
 
  ;   StartDrawing(ScreenOutput())
  ;   DrawAlphaImage(ImageID(image), 0, 0)
  ;   *DrawGLBuffer = DrawingBuffer()  ;Was mache ich jetzt damit ?
  ;   StopDrawing()
 
  ;// Bind the texture To the polygons
  glBindTexture_(#GL_TEXTURE_RECTANGLE_NV, glSpriteTexture)
 
  ;/ set shader Uniform values
  glUniform2f(System\Shader_Uniform_Resolution,System\Shader_Width,System\Shader_Height)
  glUniform1f(System\Shader_Uniform_Time,(System\App_CurrentTime-System\App_StartTime) / 1000.0)
  glUniform2i(System\Shader_Uniform_SurfacePosition.i,1.0,1.0)
  ;glUniform1i(????)
 
  ;// Set the primitive color To white
  glColor3f_(Red(tint) / 255.0, Green(tint) / 255.0, Blue(tint) / 255.0)
 
  ;   glBegin_(#GL_QUADS)
  ;   glTexCoord2i_(0, h) : glVertex2f_(-1, -1)
  ;   glTexCoord2i_(w, h) : glVertex2f_(1, -1)
  ;   glTexCoord2i_(w, 0) : glVertex2i_(1, 1)
  ;   glTexCoord2i_(0, 0) : glVertex2i_(-1, 1)
  ;   glEnd_()
 
  glBegin_(#GL_QUADS)
  glTexCoord2i_(0, h) : glVertex2f_(0, 0)
  glTexCoord2i_(w, h) : glVertex2f_(w, 0)
  glTexCoord2i_(w, 0) : glVertex2f_(w, h)
  glTexCoord2i_(0, 0) : glVertex2f_(0, h)
  glEnd_()
 
  System\Frames + 1
  If System\App_CurrentTime > System\FPS_Timer
    System\FPS = System\Frames
    System\Frames = 0
    System\FPS_Timer = System\App_CurrentTime  + 1000
    SetWindowTitle(#Window_Main,"GLSL Test - FPS: "+Str(System\FPS))
  EndIf
 
EndProcedure


Repeat
  Repeat
   
    System\Event = WindowEvent()
   
    Select System\Event
       
      Case #PB_Event_Menu
        Select EventMenu()
          Case #Menu_Open
            OpenShader()
          Case #Menu_Save
            SaveShader()
          Case #Menu_Run
            RunShader()
           
        EndSelect
       
      Case #PB_Event_CloseWindow       
        System\Exit = #True
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Gad_ShaderSelector_Combo
            Select EventType()
              Case #PB_EventType_Change
                ;debug "Set to: "+GetGadgetState(#Gad_ShaderSelector_Combo)
                Shader_Set(GetGadgetState(#Gad_ShaderSelector_Combo))
            EndSelect
        EndSelect
    EndSelect
   
  Until System\Event = 0
 
 
  System\App_CurrentTime = ElapsedMilliseconds()
 
  Render()
  ;FlipBuffers()
  SetGadgetAttribute(screenGL, #PB_OpenGL_FlipBuffers, #True)
 
Until System\Exit


Zuletzt geändert von ccode_new am 03.11.2018 22:02, insgesamt 3-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 19:42 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Wie müsste ich die Sache mit dem "u_image" angehen ?

Code:
precision mediump float;
uniform sampler2D u_image;
varying vec2 surfacePosition;
void main() {
    vec4 color = texture2D(u_image, surfacePosition);
    float grey = (0.2126 * color.r) + (0.7152 * color.g) + (0.0722 * color.b);");
    color.rgb += (grey - color.rgb);
    gl_FragColor = color;
}


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 21:46 
Offline
Benutzeravatar

Registriert: 29.08.2004 08:37
ccode_new hat geschrieben:
Wie müsste ich die Sache mit dem "u_image" angehen ?
Da kommt der Multitexturing-Index der gebundenen Textur rein mit glUniform1i.

_________________
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 03.11.2018 21:52 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo DarkDragon!

Hast du ein Beispiel für mich ?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 04.11.2018 12:19 
Offline
Benutzeravatar

Registriert: 29.08.2004 08:37
ccode_new hat geschrieben:
Hallo DarkDragon!

Hast du ein Beispiel für mich ?
Momentan nicht, aber hier ist ein Tutorial: https://learnopengl.com/Getting-started/Textures. Unter dem Punkt "Texture Units" siehst du wie das gemeint ist. Du hast irgendwo deine Textur generiert mit glGenTexture, dann gebunden via glBindTexture, die Pixeldaten reingeladen mit glTexImage2D etc. und dann kannst du damit arbeiten. Du kannst viele Texturen auf ein einziges Objekt legen und sie entsprechend miteinander mischen im Shader. Das macht man indem man vor dem Rendern des Objekts die Texturen mittels

Code:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2);

die Texturen einbindet. Die sampler2Ds müssen dann auf die int Werte 0 und 1 festgelegt werden. Ohne glActiveTexture würde man immer mit 0 arbeiten.

_________________
Angenommen es gäbe einen Algorithmus mit imaginärer Laufzeit O(i * n), dann gilt O((i * n)^2) = O(-1 * n^2) d.h. wenn man diesen Algorithmus verschachtelt ist er fertig, bevor er angefangen hat.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 04.11.2018 15:05 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo zu schwarzer Drache und alle anderen.

Ich habe den Code für Windows und Linux noch etwas optimiert.
Unter Windows hat die Intel-GPU Probleme mit dem Vertex-Shader und Fragment-Shader gehabt.
Die GPU verlangt unter Windows eine Versionsnummer.
Und unter Window verlangt die Intel-GPU eine Vertex-Positionsübergabe wie folgt:

gl_Position = ftransform();

Außerdem werden Bilder unter Linux von OpenGL mit einer umgedrehten Matrix-Texture behandelt.
Und die Farbwertübergaben unterscheiden sich bei Windows und Linux. (Beim selben Bild!)

Alles daher optimiert.

Hier steht jetzt der funktionierende Code.

Code:
;Das Beispiel wurde Windows und Linux optimiert.

EnableExplicit
InitSprite()

UsePNGImageDecoder()
UseJPEGImageDecoder()

;Wichtig! Unter Windows sind Versionsangaben am Anfang der Vertex/Fragment-Shader Pflicht!

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    Import ""
      glXGetProcAddress(s.p-ascii) As "glXGetProcAddress"
    EndImport
   
  CompilerCase #PB_OS_Windows
    CompilerIf Subsystem("OpenGL") = #False
      MessageRequester("Error", "Setze das Subsystem zu OpenGL: Compiler... Compiler Options")
      End
    CompilerEndIf
   
    CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
      Import "opengl32.lib"
        wglGetProcAddress(s.p-ascii) As "_wglGetProcAddress@4"
      EndImport
     
    CompilerElse   
      Import "opengl32.lib"
        wglGetProcAddress(s.p-ascii) As "wglGetProcAddress"
      EndImport
     
    CompilerEndIf
   
  CompilerDefault
    CompilerError "Unsupported OS"
   
CompilerEndSelect

Enumeration ;/ Window
  #Window_Main
EndEnumeration
Enumeration ;/ Gadget
  #Gad_Editor
  #Gad_ShaderSelector_Combo
EndEnumeration
Enumeration ;/ Menu
  #Menu_Open
  #Menu_Save
  #Menu_Run
EndEnumeration

Structure System
  Width.i
  Height.i
  Shader_Width.i
  Shader_Height.i
  Event.i
  Exit.i
  MouseX.i
  MouseY.i
 
  App_CurrentTime.i
  App_StartTime.i
  Editor_LastText.s
 
  Shader_Vertex_Text.s
  Shader_Fragment_Text.s
  Shader_Vertex.i
  Shader_Fragment.i
  Shader_Program.i
 
  Shader_Uniform_Time.i
  Shader_Uniform_Resolution.i
  Shader_Uniform_Mouse.i
  Shader_Uniform_SurfacePosition.i
 
  Shader_Image.i
 
  FPS_Timer.i
  Frames.i
  FPS.i
EndStructure

Global System.System

#GL_TEXTURE_RECTANGLE_NV=$84F5
#GL_CLAMP_TO_EDGE=$812F

#GL_BGR = $80E0
#GL_BGRA = $80E1

Global screenGL, screenColor=RGBA(0, 0, 0, 0)
Global glSpriteTexture, w, h, image

Global Base64Image.s
Restore B64Image
Read.s Base64Image

Procedure.i Base64CatchImage(Image.i, Base64.s)
 
  Protected Base64Size.i, *ImageBuffer, ImageSize.i, OK.i
 
  Base64Size = Len(Base64)
  *ImageBuffer = AllocateMemory(Base64Size)
 
  If *ImageBuffer
    ImageSize = Base64Decoder(Base64, *ImageBuffer, Base64Size)
    If ImageSize
      OK = CatchImage(Image, *ImageBuffer)
    EndIf
    FreeMemory(*ImageBuffer)
  EndIf
 
  ProcedureReturn OK
 
EndProcedure

Procedure SetupOpenGL()
 
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  glOrtho_(0, 1, 0, 1, -1000.0, 1000.0)
 
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
 
  glEnable_(#GL_CULL_FACE)
 
  glPushAttrib_(#GL_DEPTH_BUFFER_BIT | #GL_LIGHTING_BIT);
 
  glDisable_(#GL_DEPTH_TEST)
 
  glDisable_(#GL_LIGHTING)
 
  glDisable_(#GL_BLEND) ;Einige Blend-Einstellungen können unter Window zum Flackern führen !!!
 
EndProcedure

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
 
  glEnable_(#GL_TEXTURE_2D)
 
  glGenTextures_(1, @TextureHandle)
  glBindTexture_(#GL_TEXTURE_2D, TextureHandle)
 
  ImageW = ImageWidth(ImageHandle)
  ImageH = ImageHeight(ImageHandle)
 
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      If ImageD = 32
        glTexImage2D_(#GL_TEXTURE_2D, 0, #GL_RGBA, ImageW, ImageH, 0, #GL_RGBA, #GL_UNSIGNED_BYTE, MemoryAddress)
      Else
        glTexImage2D_(#GL_TEXTURE_2D, 0, #GL_RGB, ImageW, ImageH, 0, #GL_RGB, #GL_UNSIGNED_BYTE, MemoryAddress)
      EndIf
    CompilerCase #PB_OS_Windows
      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
  CompilerEndSelect
 
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
 
  ProcedureReturn TextureHandle
 
EndProcedure

Procedure Init_Main()
  Protected MyLoop.i
 
  System\Width.i = 1024
  System\Height = 480
  System\Shader_Width = 640
  System\Shader_Height = 480
 
  OpenWindow(#Window_Main,0,0,System\Width, System\Height,"",#PB_Window_SystemMenu)
  ;OpenWindowedScreen(WindowID(#Window_Main), 0, 0, 640, 480)
  screenGL=OpenGLGadget(#PB_Any, 0, 0, System\Shader_Width, System\Shader_Height)
 
  SetupOpenGL()
 
  ;-OpenGL-Image ?
  ;LoadImage(0, "render.jpg")
  Debug Base64CatchImage(0, Base64Image)
 
  w=640 : h=480
  image=CreateImage(#PB_Any, w, h, 32, RGB(255, 255, 255)) ; white background
  If StartDrawing(ImageOutput(image))
    DrawImage(ImageID(0), 0, 0, ImageWidth(image), ImageHeight(image))
    DrawText(10, 10, "Testbild.")
    StopDrawing()
   
    glSpriteTexture = SetupGLTexture(image)
  EndIf
 
  If CreateMenu(0, WindowID(#Window_Main))
    MenuTitle("File")
    MenuItem(#Menu_Open,"Open")
    MenuItem(#Menu_Save,"Save")
    MenuBar()
    MenuItem(#Menu_Run,"Run Shader")
  EndIf
 
  ComboBoxGadget(#Gad_ShaderSelector_Combo,System\Shader_Width+4,2,System\Width - (System\Shader_Width+8),24)
  AddGadgetItem(#Gad_ShaderSelector_Combo,-1,"Shader: "+Str(1))
  AddGadgetItem(#Gad_ShaderSelector_Combo,-1,"Shader: "+Str(2))
  AddGadgetItem(#Gad_ShaderSelector_Combo,-1,"Shader: "+Str(3))
 
  SetGadgetState(#Gad_ShaderSelector_Combo,0)
 
  EditorGadget(#Gad_Editor,System\Shader_Width+4,30,System\Width - (System\Shader_Width+8),System\Height-30)
 
  System\App_StartTime = ElapsedMilliseconds()
 
  System\Shader_Vertex_Text = "#version 130"+#CRLF$ ;Version ist Pflicht!
  System\Shader_Vertex_Text + "attribute vec2 surfacePosAttrib;"
  System\Shader_Vertex_Text + "   void main() {"+#CRLF$
  System\Shader_Vertex_Text + "      gl_Position = ftransform();"+#CRLF$ ;ftranform() ist wie ein bisschen Magie
  System\Shader_Vertex_Text + "   }"+#CRLF$
 
EndProcedure

Init_Main()

;{ Opengl shader setup & routines

#GL_VERTEX_SHADER = $8B31
#GL_FRAGMENT_SHADER = $8B30

Prototype glCreateShader(type.l)
Prototype glCreateProgram()
Prototype glCompileShader(shader.l)
Prototype glLinkProgram(shader.l)
Prototype glUseProgram(shader.l)
Prototype glAttachShader(Program.l, shader.l)
Prototype glShaderSource(shader.l, numOfStrings.l, *strings, *lenOfStrings)
Prototype.i glGetUniformLocation(Program.i, name.p-ascii)
Prototype glUniform1i(location.i, v0.i)
Prototype glUniform2i(location.i, v0.i, v1.i)
Prototype glUniform1f(location.i, v0.f)
Prototype glUniform2f(location.i, v0.f, v1.f)
Prototype glGetShaderInfoLog(shader.i, bufSize.l, *length_l, *infoLog)

Prototype.i glGetProcAddress(name.p-ascii)

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    Global glGetProcAddress.glGetProcAddress = @glXGetProcAddress()
   
  CompilerCase #PB_OS_Windows
    Global glGetProcAddress.glGetProcAddress = @wglGetProcAddress()
   
  CompilerDefault
    CompilerError "Unsupported OS"
   
CompilerEndSelect

Global glCreateShader.glCreateShader = glGetProcAddress("glCreateShader")
Global glCreateProgram.glCreateProgram = glGetProcAddress("glCreateProgram")
Global glCompileShader.glCompileShader = glGetProcAddress("glCompileShader")
Global glLinkProgram.glLinkProgram = glGetProcAddress("glLinkProgram")
Global glUseProgram.glUseProgram = glGetProcAddress("glUseProgram")
Global glAttachShader.glAttachShader = glGetProcAddress("glAttachShader")
Global glShaderSource.glShaderSource = glGetProcAddress("glShaderSource")
Global glGetUniformLocation.glGetUniformLocation = glGetProcAddress("glGetUniformLocation")
Global glUniform1i.glUniform1i = glGetProcAddress("glUniform1i")
Global glUniform2i.glUniform2i = glGetProcAddress("glUniform2i")
Global glUniform1f.glUniform1f = glGetProcAddress("glUniform1f")
Global glUniform2f.glUniform2f = glGetProcAddress("glUniform2f")
Global glGetShaderInfoLog.glGetShaderInfoLog = glGetProcAddress("glGetShaderInfoLog")

Procedure Shader_Compile_Link_Use(Vertex.s,Fragment.s,Use.i=1)
  Protected VertShader.i, FragShader.i, *TxtPointer, Program.i
  Protected Textlength.i, Mytext.s = Space(1024)
 
  ;/ Compile Vertex shader
  VertShader.i = glCreateShader(#GL_VERTEX_SHADER)
  *TxtPointer = Ascii(Vertex)
  glShaderSource(VertShader, 1, @*TxtPointer, #Null)
  glCompileShader(VertShader)
  Debug "Vert: "+VertShader
  glGetShaderInfoLog(VertShader,1023,@Textlength,@Mytext)
  Debug PeekS(@MyText, -1, #PB_Ascii)
  ;/ Compile Fragment Shader
  FragShader.i = glCreateShader(#GL_FRAGMENT_SHADER)
  *TxtPointer = Ascii(Fragment)
  glShaderSource(FragShader, 1, @*TxtPointer, #Null)
  glCompileShader(FragShader)
  Debug "Frag: "+FragShader
  glGetShaderInfoLog(FragShader,1023,@Textlength,@Mytext)
  Debug PeekS(@MyText, -1, #PB_Ascii)
 
  ;/ Create Shader Program
  Program = glCreateProgram()
  glAttachShader(Program,VertShader)
  ;debug "Attached Vert Shader"
  glAttachShader(Program,FragShader)
  ;debug "Attached Frag Shader"
  glLinkProgram(Program)
  ;debug "Link program"
 
  If Use = 1
    glUseProgram(Program)
  EndIf
 
  ProcedureReturn Program
EndProcedure
;}

Procedure Shader_Set(Fragment.i, shader$="")
 
  If System\Shader_Program <> 0 ;/ delete the previous shaders
    glUseProgram(0)
  EndIf
 
  If Fragment = -2 ; run the shader   
    System\Shader_Fragment_Text = GetGadgetText(#Gad_Editor)   
  ElseIf Fragment = -1 ; load the shader
    System\Shader_Fragment_Text = shader$+#CRLF$
  Else
    Select Fragment
      Case 0
        System\Shader_Fragment_Text = "#version 120"+#CRLF$
        System\Shader_Fragment_Text + "uniform vec2 resolution;"+#CRLF$
        System\Shader_Fragment_Text + "uniform float time;"+#CRLF$
        System\Shader_Fragment_Text + ""+#CRLF$
        System\Shader_Fragment_Text + "void main( void ) {"+#CRLF$
        System\Shader_Fragment_Text + "   vec2 pos = gl_FragCoord.xy/resolution;"+#CRLF$
        System\Shader_Fragment_Text + "   gl_FragColor = vec4(pos.x,pos.y,0.0,1.0);"+#CRLF$
        System\Shader_Fragment_Text + "}"+#CRLF$
      Case 1
        System\Shader_Fragment_Text = "#version 120"+#CRLF$
        System\Shader_Fragment_Text + "//Gray-Image (Linux-Version)"+#CRLF$
        System\Shader_Fragment_Text + "uniform sampler2D color_texture;"+#CRLF$
        System\Shader_Fragment_Text + "uniform vec2 resolution;"+#CRLF$
        System\Shader_Fragment_Text + "void main() {"+#CRLF$
        System\Shader_Fragment_Text + "   vec2 pos = gl_FragCoord.xy/resolution;"+#CRLF$
        System\Shader_Fragment_Text + "   pos.x = 1.0 - pos.x;"+#CRLF$
        System\Shader_Fragment_Text + "   vec4 color = texture2D(color_texture, -pos);"+#CRLF$
        System\Shader_Fragment_Text + "   float grey = (0.2126 * color.r) + (0.7152 * color.g) + (0.0722 * color.b);"+#CRLF$
        System\Shader_Fragment_Text + "   color.rgb += (grey - color.rgb);"+#CRLF$
        System\Shader_Fragment_Text + "   gl_FragColor = color;"+#CRLF$
        System\Shader_Fragment_Text + "}"+#CRLF$
      Case 2
        System\Shader_Fragment_Text = "#version 120"+#CRLF$
        System\Shader_Fragment_Text + "//Gray-Image (Windows-Version)"+#CRLF$
        System\Shader_Fragment_Text + "uniform sampler2D color_texture;"+#CRLF$
        System\Shader_Fragment_Text + "uniform vec2 resolution;"+#CRLF$
        System\Shader_Fragment_Text + "void main() {"+#CRLF$
        System\Shader_Fragment_Text + "   vec2 pos = gl_FragCoord.xy/resolution;"+#CRLF$
        System\Shader_Fragment_Text + "   vec4 color = texture2D(color_texture, pos);"+#CRLF$
        System\Shader_Fragment_Text + "   float grey = (0.2126 * color.r) + (0.7152 * color.g) + (0.0722 * color.b);"+#CRLF$
        System\Shader_Fragment_Text + "   color.rgb += (grey - color.rgb);"+#CRLF$
        System\Shader_Fragment_Text + "   gl_FragColor = color;"+#CRLF$
        System\Shader_Fragment_Text + "}"+#CRLF$
       
    EndSelect
  EndIf
 
  System\Shader_Program = Shader_Compile_Link_Use(System\Shader_Vertex_Text,System\Shader_Fragment_Text)
 
  If System\Shader_Program = 0
    MessageRequester("Error?","Kein Shader verfügbar",#PB_MessageRequester_Ok)
    End
  EndIf
 
  ;/ store shader uniform locations
  Debug "Shader: "+System\Shader_Program
  System\Shader_Uniform_Time = glGetUniformLocation(System\Shader_Program, "time")
  ;System\Shader_Uniform_Mouse = glGetUniformLocation(System\Shader_Program, "mouse")
  System\Shader_Uniform_Resolution = glGetUniformLocation(System\Shader_Program, "resolution")
  System\Shader_Uniform_SurfacePosition.i = glGetUniformLocation(System\Shader_Program, "surfacePosition")
 
  System\Shader_Image = glGetUniformLocation(System\Shader_Program, "color_texture")
 
  glBindTexture_(#GL_TEXTURE_2D, glSpriteTexture)
  glUniform1i(System\Shader_Image, 0)
 
  Debug "Time location: "+System\Shader_Uniform_Time
  ;Debug "Mouse location: "+System\Shader_Uniform_Mouse
  Debug "Res location: "+System\Shader_Uniform_Resolution
  Debug "SurfacePos location: "+System\Shader_Uniform_SurfacePosition
 
  SetGadgetText(#Gad_Editor,System\Shader_Fragment_Text)
 
EndProcedure

Procedure OpenShader()
  Define filename$ ="", txt$ = ""
 
  filename$ = OpenFileRequester("Öffne Shader","","All|*.*",0)
 
  If filename$ <> ""
   
    If ReadFile(0, filename$, #PB_Ascii)
      While Eof(0) = 0           
        txt$ + ReadString(0, #PB_Ascii, #PB_Any) + #CRLF$
      Wend
      CloseFile(0)
      Shader_Set(-1,txt$)
     
    Else
      MessageRequester("Information","Kann die Datei nicht öffnen!")
    EndIf
   
  EndIf
 
EndProcedure
Procedure SaveShader()
  Define filename$ =""
 
  filename$ = SaveFileRequester("Save","","txt|*.txt",0)
 
  If filename$ <> ""
   
    If OpenFile(0, filename$)
      WriteStringN(0, GetGadgetText(#Gad_Editor))
      CloseFile(0)
    EndIf
   
  EndIf
 
EndProcedure
Procedure RunShader()
 
  Shader_Set(-2)
 
EndProcedure

Shader_Set(0)

Procedure Render()
  glEnable_(#GL_TEXTURE_2D)
  glMatrixMode_(#GL_TEXTURE);
  glLoadIdentity_()
 
  glEnable_(#GL_STENCIL_TEST);
  glStencilFunc_(#GL_ALWAYS, 1, $FFFFFFFF);
  glStencilOp_(#GL_REPLACE, #GL_REPLACE, #GL_REPLACE);
  glEnable_(#GL_ALPHA_TEST)
  glAlphaFunc_(#GL_GREATER  ,0.0)
 
  ;/ set shader Uniform values
  glUniform2f(System\Shader_Uniform_Resolution,System\Shader_Width,System\Shader_Height)
  glUniform1f(System\Shader_Uniform_Time,(System\App_CurrentTime-System\App_StartTime) / 1000.0)
  glUniform2i(System\Shader_Uniform_SurfacePosition.i,1.0,1.0)
  glUniform1i(glGetUniformLocation(System\Shader_Program, "color_texture"), #GL_TEXTURE)
 
  ;glBindTexture_(#GL_TEXTURE_2D, glSpriteTexture)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      glBegin_(#GL_QUADS)
      glTexCoord2i_(0, h) : glVertex2f_(0, 0)
      glTexCoord2i_(w, h) : glVertex2f_(w, 0)
      glTexCoord2i_(w, 0) : glVertex2f_(w, h)
      glTexCoord2i_(0, 0) : glVertex2f_(0, h)
      glEnd_()
    CompilerCase #PB_OS_Windows
      glBegin_(#GL_QUADS)
      glTexCoord2i_(0, 0) : glVertex2f_(0, 0)
      glTexCoord2i_(w, 0) : glVertex2f_(w, 0)
      glTexCoord2i_(w, h) : glVertex2f_(w, h)
      glTexCoord2i_(0, h) : glVertex2f_(0, h)
      glEnd_()
  CompilerEndSelect
 
  glDisable_(#GL_TEXTURE)
 
  System\Frames + 1
  If System\App_CurrentTime > System\FPS_Timer
    System\FPS = System\Frames
    System\Frames = 0
    System\FPS_Timer = System\App_CurrentTime  + 1000
    SetWindowTitle(#Window_Main,"GLSL Test - FPS: "+Str(System\FPS))
  EndIf
 
EndProcedure


Repeat
  Repeat
   
    System\Event = WindowEvent()
   
    Select System\Event
       
      Case #PB_Event_Menu
        Select EventMenu()
          Case #Menu_Open
            OpenShader()
          Case #Menu_Save
            SaveShader()
          Case #Menu_Run
            RunShader()
           
        EndSelect
       
      Case #PB_Event_CloseWindow       
        System\Exit = #True
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Gad_ShaderSelector_Combo
            Select EventType()
              Case #PB_EventType_Change
                Shader_Set(GetGadgetState(#Gad_ShaderSelector_Combo))
            EndSelect
        EndSelect
    EndSelect
   
  Until System\Event = 0
 
 
  System\App_CurrentTime = ElapsedMilliseconds()
 
  Render()
 
  SetGadgetAttrib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XOmMkDHpTt/5VFShsijmAn3fL1pN57dKhVgxpS2OtLnQ2ThiehzSrJtOSeKgXFBP40X7hYm8znrgUvmEYFQqxPHans3PWjmEPZtzE5pdxxUTc0vmbV460uYdibdtIxSdcjtUAkzzS+ZluKXNYCVZCtAk65qPcKN35Ur9UP1JFb5sCnb9q+9QFqXzMjNKzAlVstg9KazZNMDjpmmbu1SMn8wbcUVExooe4ih/FTqKKqO5PQX+KlPQUUUpDQq96Nx4ooofwgPHWmt0oooGLQzGiinIBdxpVJ4ooqegChio4pu45oopyEP3GkY8UUU0DEUmnJ92iipYITcetOU5FFFAxvrQjHkUUUogxASCaVutFFUgDuaKKKgD//Z"
EndDataSection



Zuletzt geändert von ccode_new am 06.11.2018 19:35, insgesamt 1-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 04.11.2018 20:35 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Guten Abend!

Ich glaube ich mache irgend etwas bei den Shadern falsch.

Also ich habe eine geteilte Variable (Kommunikation zwischen Fragment- und Vertex-Shader):

varying vec2 texCoord;

Diese Variable soll die Texturkoordinaten übermitteln.

Aber ich bekomme immer nur ein komplett graues Bild.

color_texture ist mein übergebenes Bild.

Fragment-Shader
Code:
#version 120

uniform sampler2D color_texture;
uniform vec2 resolution;
varying vec2 texCoord;

void main() {
   //vec2 st = gl_FragCoord.xy/resolution;
    //vec4 color = texture2D(color_texture, gl_TexCoord[0].st);
    vec4 color = texture2D(color_texture, texCoord);
    float grey = (0.2126 * color.r) + (0.7152 * color.g) + (0.0722 * color.b);
    color.rgb += (grey - color.rgb);
   gl_FragColor = color;
}


Der Vertex-Shader hat die selbe geteilte Variable:
texCoord

Und ich übergebe so: (was wahrscheinlich falsch ist)
System\Shader_Vertex_Text + " texCoord = surfacePosAttrib;"

Also ich sehe immernoch viele Fragezeichen.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: OpenGL Shader Frage
BeitragVerfasst: 04.11.2018 21:51 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Keine Ideen ?

Mal noch eine andere Frage:

Wie könnte man am besten if-Abfragen in Shadern vermeiden, den diese Bremsen Shader stark aus.
Am besten alles mit Übergabe-Variablen managen, oder ?


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 17 Beiträge ]  Gehe zu Seite 1, 2  Nächste

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste


Sie dürfen keine neuen Themen in diesem Forum erstellen.
Sie dürfen keine Antworten zu Themen in diesem Forum erstellen.
Sie dürfen Ihre Beiträge in diesem Forum nicht ändern.
Sie dürfen Ihre Beiträge in diesem Forum nicht löschen.

Suche nach:
Gehe zu:  
cron

 


Powered by phpBB © 2008 phpBB Group | Deutsche Übersetzung durch phpBB.de
subSilver+ theme by Canver Software, sponsor Sanal Modifiye