Mojo2 + OpenGL

Monkey Forums/Monkey Programming/Mojo2 + OpenGL

PixelPaladin(Posted 2016) [#1]
In the examples (bananas folder) there are two openGL examples but it seems like these are not compatible with mojo2. Does anyone have an idea how it could be possible to use openGL to render a 3d scene into a mojo2 canvas?


Nobuyuki(Posted 2016) [#2]
Switch from importing gles11 to gles20. Some of the finite state functions might not work, but see if there are direct equivalents in gles20...


PixelPaladin(Posted 2016) [#3]
Thanks Nobuyuku – I already tried that, but still had some problems. However, it works now.

I added the following function to mojo2.graphics:
Function ReInitVbos:Void()
	glBindBuffer GL_ARRAY_BUFFER,rs_vbo
	glEnableVertexAttribArray 0 ; glVertexAttribPointer 0,2,GL_FLOAT,False,BYTES_PER_VERTEX,0
	glEnableVertexAttribArray 1 ; glVertexAttribPointer 1,2,GL_FLOAT,False,BYTES_PER_VERTEX,8
	glEnableVertexAttribArray 2 ; glVertexAttribPointer 2,2,GL_FLOAT,False,BYTES_PER_VERTEX,16
	glEnableVertexAttribArray 3 ; glVertexAttribPointer 3,4,GL_UNSIGNED_BYTE,True,BYTES_PER_VERTEX,24
	glBindBuffer GL_ELEMENT_ARRAY_BUFFER,rs_ibo
End

(I call this function before I start 2D rendering using mojo2 commands.)

When rendering 3D content into an image I also noticed that in this case there was no depth buffer. So I added this
Local depth_rb:=glCreateRenderbuffer()
glBindRenderbuffer(GL_RENDERBUFFER, depth_rb)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, _width,_height)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rb)

to mojo2.graphics.Texture.Init() (before the call to glPopFramebuffer). This code adds a render buffer to Textures used as render target.