MonkeyGL

Monkey Forums/Monkey Programming/MonkeyGL

AdamRedwoods(Posted 2011) [#1]
OpenGL module for monkey. TOTALLY EXPERIMENTAL! TOTALLY AWESOME!
Updated: Nov 3,2011

Updated: Dec 17, 2011
*****
NOW THAT OPENGL IS IN MONKEY v51 BY DEFAULT, this version will be here for curiosity coders and archeologists.


Working Targets: GLFW/MINGW (pc, mac) and Android and iOS
Perhaps: Flash11(alchemy offers possible connection), WebGL (ES 2.0 minimum)
Not: XNA (would need a different command set since it's not openGL)


I'll update this thread when I get the other targets working and expand capabilities. See examples in post below.

** NOTES & LIMITATIONS **
- incomplete set, but easily extendable
- Mr. Sibly has the right to remove any of this
- depth buffer in glfw and iOS needs to be manually added :(
-- perhaps I can discuss with MSibly to see if I can't get these switches added in the config file
-- for glfw targets in your monkey folder/targets (ex, main.cpp at the very bottom)
-- glfwOpenWindow( w,h, 8,8,8,8,16,8, WINDOW_MODE )
-- for iOS depth buffer see post below


*******************
monkeyGL.monkey


**********************
monkeyGL.cpp


******************
monkeyGL.java



AdamRedwoods(Posted 2011) [#2]
Here's a simple example, two non-textured triangles:




******************

Here's a major example of a textured cube:



Uncle(Posted 2011) [#3]
Yay youre a star. Will test this today :)

Just perfect :) Works very nicely on android.


outsider(Posted 2011) [#4]
This is great. Works very good on my android Samsung i5800


therevills(Posted 2011) [#5]
Cool...

Mr. Sibly has the right to remove any of this

I wouldnt worry about it, this is a legit mod :)

BTW change this code:
#if TARGET = "glfw" Or TARGET = "mingw"
'' Or TARGET = "ios"

Import "monkeyGL.cpp"

#elseif TARGET = "android"

Import "monkeyGL.java"

#endif

to this
Import "monkeyGL.${LANG}"


If your iOS code doesnt work you may need another cpp file, then you can use the ${TARGET} tag.


hardcoal(Posted 2011) [#6]
great news! someone is doing that what ive being waiting for! 3d!!
respect for the first milestone


Aman(Posted 2011) [#7]
Wonderful. For an experiment, I expected some serious performance issues. it is really good. Keep it up


AdamRedwoods(Posted 2011) [#8]
Big update tomorrow, really tired right now but it's rockin. I think I've hacked Monkey to pieces. :D


MikeHart(Posted 2011) [#9]
Awesome! Keep it up!


hardcoal(Posted 2011) [#10]
Thumbs up for Adam!! doing a holly job :)


AdamRedwoods(Posted 2011) [#11]
***MAJOR UPDATE*** Nov 1, 2011

As you can see above, I've changed everything, code examples and all.

Updates:
- textures
- glDrawElements()
- combined monkeyGL/ monkey 2D drawing
- enhanced pointers; you can now allocate buffers before the render routine (faster)
- expanded gl set


**Notes**
Whew! This overall was a bit of work to hack through monkey and all. Although I hacked it, I tried diligently to keep the interfacing clean for any changes that Mr. Sibly may want to make in his backend-- shouldn't effect monkeyGL at all.... except the garbage collector, as that was the hardest to figure out, but I'll keep an eye on that.

Don't forget-- you need to turn on the depth buffer for glfw and iOS to work. See above. Ask questions.

You're welcome to see how I extended monkey and made several trans.exe tricks to get code into various places. Notably the line:
Global GL_TRIANGLES = "GL_TRIANGLES" ''just experimenting

you can look at the exported code to see what that above is doing differently than the other gl constants.
The platform specific code are "pointers" which are just exposing arrays to the gl backend. Interesting stuff. The cpp code was notably challenging.

I didn't add all the gl constants and functions, but the rest should be very easy to add. If anyone does the complete set, send me the code and I'll post it.
Shaders? Probably doable, with a string pointer backend. Advanced users can give it a try. I just need to chill for a while then I'll look into it.


**Future**
I've only tested on Monkeyv44, so if others can verify it works on latest targets, thanks.
WebGL is slow as a dog, so we'll see if I can get to it-- but overall I'm not impressed by it.The demos use heavy GLSL shaders, which isn't available to all on the web. Flash 11/Stage3D looks better.
iOS-- I'll make sure it works when I get my MacMini upgraded to OSX10.6, about a week. I'll test on the simulator, but then would have to find a device to test on (future direction). Someone else could start and let me know what errors they're getting, I can usually work around it.


....and where does this lead me to next? Why miniB3D, of course!

//Adam of the Redwoods
www.adam.piettes.com
www.twopisoftware.com


Shinkiro1(Posted 2011) [#12]
Ok, I just tested this and wow ... it worked. Never thought it would be so easy to implemenet an extra OpenGL module.
Btw: when using your 2nd example ios throws an error on line 3285 ("glFrustum was not declared in this scope")

Now just wrap it in a nice package, like miniB3D (like you said) and you shall become a hero ...


Hima(Posted 2011) [#13]
This is brilliant! I was thinking about buying Blitzmax, considering how Monkey still not really that good at making PC games yet, but maybe I should wait for this instead? :D


AdamRedwoods(Posted 2011) [#14]
Slight problems with osx and ios, but after I clear them up, everything should be solid.
My short buffer pointer is getting chewed up...


AdamRedwoods(Posted 2011) [#15]
**** Update Nov 3 ****
Mac, iOS are working (on simulator). I haven't tested an actual iOS device.
Seems solid.


**** iOS Depth Buffer Note: ****
You'll need to turn the depth buffer on, which is a bit "codey". It may also decrease performance in 2D games on older hardware.


In the file: monkey/targets/ios/main.h
just under the "GLuint colorDepthbuffer;" add:
GLuint depthRenderbuffer;


In the file: monkey/targets/ios/main.mm
just after "glBindRenderBufferOES( ......, colorRenderbuffer);" add:
		// Depth buffer
		if (true) {
			glGenRenderbuffersOES(1, &depthRenderbuffer);

		}


in same file, just after "glGetRenderbufferParameterivOES(.... &backingHeight );" add:
	// Depth buffer
	if (true) {
		glBindFramebufferOES( GL_FRAMEBUFFER_OES,defaultFramebuffer );
		glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
		glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24_OES, backingWidth, backingHeight);
		glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
		
		glBindRenderbufferOES( GL_RENDERBUFFER_OES,colorRenderbuffer );
		glFramebufferRenderbufferOES( GL_FRAMEBUFFER_OES,GL_COLOR_ATTACHMENT0_OES,GL_RENDERBUFFER_OES,colorRenderbuffer );
	}


in same file, just after "dealloc ...etc.... colorRenderbuffer = 0; }" add:
	if (depthRenderbuffer) {
		glDeleteRenderbuffersOES(1, &depthRenderbuffer);
		depthRenderbuffer = 0;
	}


enjoy!


charlie(Posted 2011) [#16]
Oooh! This is interesting!

Looking forward to seeing how this progresses :)

Cheers
Charlie


Virtech(Posted 2011) [#17]
Apologies for dumb question, but were am I supposed to put the monkeyGL.monkey, monkeyGL.java and monkeyGL.cpp files?

Right now I have all files including examples inside the same folder on the desktop. When trying to run either examples for html5 target I get the following error:

Parsing...
H:/Monkey/Projects/MonkeyGL/monkeyGL.monkey<13> : Error : File 'H:/Monkey/Projects/MonkeyGL/monkeyGL.js' not found.
Abnormal program termination. Exit code: -1



AdamRedwoods(Posted 2011) [#18]
you can put the files in the same folder as your project, or you can create a new module folder "monkeyGL" in the monkey install folder (monkey/modules/monkeyGL).

There's no HTML5 target yet (webGL).


Hima(Posted 2011) [#19]
You should put this up on some kind of version control. Github, Google Project, SVN, etc. I think it'd be much easier for us to follow all the changes :)


MikeHart(Posted 2011) [#20]
On google code, a lot of us have our modules there. Join in please!