Tq Mike. I could probably repeat the texture by code.In mojo2 you can. But I am uncertain if you can achieve the textural effect, repeating texture, you want.
This definitely helps me to figure it out.Otherwise you could check this code out don't know who made it originally but it might be interesting to you.
Oh Yes, I could try Holzkopf module Thank you for pointing me in the right directionI'm thinking maybe you could use multiplication blend or a shader to mask normal draw operations?
Holzkopf I know have tried this kind of things before using Mojo2 here in the forum.
Strict
'#OPENGL_DEPTH_BUFFER_ENABLED=True
#OPENGL_GLES20_ENABLED=True
Import mojo2
Import opengl.gles20
Function Main:Int();New myClass;Return 0;End
Class myClass Extends App
Method OnCreate:Int()
SetUpdateRate(30)
Return 0
End
Method OnUpdate:Int()
Return 0
End
Method OnRender:Int()
glClearColor(0,0,0,1)
glClear(GL_COLOR_BUFFER_BIT)
'----------------------------
'
' OpenGL code here
'
'----------------------------
Return 0
End
End
Thank you for the hint.I will get back to you about it as soon as possible.
Just a pre hint, mojo2 uses opengles 2.
#OPENGL_GLES20_ENABLED=True
Import opengl.gles20
Import mojo2
Function Main:Int();New myClass;Return 0;End
Class myClass Extends App
Method OnCreate:Int()
SetUpdateRate(30)
Print glGetString(GL_VERSION)
CreateShader("attribute vec4 position;void main(){gl_Position = position;}","void main(){gl_FragColor = vec4(1.0,0.0,0.0,1.0);}")
DrawPolygon([-0.5,-0.5, 0.0,0.5, 0.5,-0.5])
Return 0
End
Method OnUpdate:Int()
Return 0
End
Method OnRender:Int()
glClearColor(0,0,0,1)
glClear(GL_COLOR_BUFFER_BIT)
glDrawArrays(GL_TRIANGLES,0,3)
Return 0
End
End
Function CheckGL()
Local err=glGetError()
If err Error "GL Error "+err
End
Function CreateShader(vertexGLSLCode:String,fragmentGLSLCode:String) 'Parameter needs GLSL code for both vertex and fragment shader
Local program = glCreateProgram()
'create vertex shader
Local vertexshader = glCreateShader(GL_VERTEX_SHADER)
glShaderSource(vertexshader,vertexGLSLCode)
glCompileShader(vertexshader)
Local params:Int[1]
glGetShaderiv(vertexshader,GL_COMPILE_STATUS,params)
If Not params[0] Print "Failed to compile vertexGLSLCode: "+glGetShaderInfoLog(vertexshader)
'create fragmen shader
Local fragmentshader = glCreateShader(GL_FRAGMENT_SHADER)
glShaderSource(fragmentshader,fragmentGLSLCode)
glCompileShader(fragmentshader)
glGetShaderiv(fragmentshader,GL_COMPILE_STATUS,params)
If Not params[0] Print "Failed to compile fragmentGLSLCode: "+glGetShaderInfoLog(fragmentshader)
'compile it
glAttachShader(program,vertexshader)
glAttachShader(program,fragmentshader)
glLinkProgram(program)
glGetProgramiv program,GL_LINK_STATUS,params
If Not params[0] Print "Failed to link program:"+glGetProgramInfoLog( program )
glValidateProgram(program)
glDeleteShader(vertexshader)
glDeleteShader(fragmentshader)
glUseProgram(program)
CheckGL()
End
Function DrawPolygon(poly:Float[])
'convert poly to DataBuffer to send to gpu
Local data:=New DataBuffer(poly.Length*4)
For Local i:=0 Until poly.Length
data.PokeFloat (i*4),poly[i]
Next
'create buffer in gpu and send above data
Local vbo=glCreateBuffer()
glBindBuffer(GL_ARRAY_BUFFER,vbo)
glBufferData(GL_ARRAY_BUFFER,data.Length,data,GL_STATIC_DRAW)
'tell gpu about the arrangement of our buffer
glEnableVertexAttribArray(0)
glVertexAttribPointer(0,2,GL_FLOAT,False,8,0)
glBindBuffer(GL_ARRAY_BUFFER,0)
End
' Cerberus X - Drawing Polygon using DrawTriangleFan() with Texture
Strict
Import mojo2
Function Main:Int()
Print "Press left mousebutton to set triangle-fan vertices."
Print "Press space-bar to toggle visibility of the vertex wireframe."
Print "Press Escape to reset vertices."
New MyApp()
Return 0
End
Class MyApp Extends App
Field myCanvas:Canvas
Field grabbed:Bool
Field material:Material
Field verts:Float[]
Field vList:FloatList
Field texcs:Float[]
'Field img:Image
Field isWireframeEnabled:Bool = True
Method OnCreate:Int()
vList = New FloatList()
myCanvas = New Canvas()
'Flags for Texture wrapping are: ClampST, MirroredRepeatST, RepeatST (S and T are horizontal and vertical dimensions)
'Image/Texture needs to be sized in power of two for repeating. At least on html5 Target.
material = Material.Load("eggs.png", Texture.RepeatST|Texture.Filter|Texture.Mipmap, Null )
'img = Image.Load("eggs.png", 0.5, 0.5, Image.RepeatST|Image.Filter|Image.Mipmap)
Return 0
End
Function DrawWireframe:Void(myCanvas:Canvas, verts:Float[])
myCanvas.SetLineWidth(2.0) ' Seems not to work on html5 Target.
Local circleSize:Float = 5.0
For Local i:Int=2 Until verts.Length() Step 2
myCanvas.SetColor(0,0.8,0)
myCanvas.DrawLine(verts[i-2], verts[i-1],verts[i], verts[i+1])
myCanvas.DrawLine(verts[0], verts[1],verts[i], verts[i+1])
myCanvas.DrawCircle(verts[i], verts[i+1], circleSize)
Next
If verts.Length()>=2
myCanvas.SetColor(0.8, 0, 0)
myCanvas.DrawCircle(verts[0], verts[1], circleSize)
EndIf
End
Method OnRender:Int()
myCanvas.Clear(.1, .1, .1)
myCanvas.SetColor(1.0, 1.0, 1.0)
myCanvas.DrawTriangleFan(verts, material, MouseX(), MouseY(), 1.5, 1.5)
'myCanvas.DrawTriangleFan(0, 0, verts, img, MouseX(), MouseY(), 1.5, 1.5)
If isWireframeEnabled DrawWireframe(myCanvas, verts)
myCanvas.Flush()
Return 0
End
Method OnUpdate:Int()
If MouseHit(0)
vList.AddLast(MouseX())
vList.AddLast(MouseY())
verts = vList.ToArray()
EndIf
If KeyHit(KEY_SPACE)
isWireframeEnabled = Not isWireframeEnabled
EndIf
If KeyHit(KEY_ESCAPE)
verts = []
vList.Clear()
EndIf
Return 0
End
End