Monkey2 OpenGL Experiments

About Monkey 2 Forums Monkey 2 Projects Monkey2 OpenGL Experiments

This topic contains 13 replies, has 4 voices, and was last updated by  EdzUp 2 years, 4 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #4461

    cocon
    Participant

    Here is the basic OpenGL rendering test for Monkey2:

    Later on I will try to figure out the Matrix4 class and make it 3D. If you have any other ideas say it here. 🙂

    #4492

    Mark Sibly
    Keymaster

    Very cool!

    Technically speaking, you’re meant to bracket your GL code (outside of OnRenderGL) calls between BeginGL() and EndGL() or you’ll be affecting the ‘shared’ context, but it seems to be working anyway!

    I’ve added a few docs to GLWindow too.

    #4518

    cocon
    Participant

    Hi Mark, I don’t know why are there two gl contexts in your design, one for GLWindow and one for Window. Is it mostly for resource organization? Essentially the BeginGL/EndGL performs that swap.

     

    #4519

    Mark Sibly
    Keymaster

    Hi Mark, I don’t know why are there two gl contexts in your design,

    A couple of reasons:

    • Since I have no idea what GL states custom non-mojo code is modifying, using a single context would mean mojo would have to push/pop/reset (or do something fancy ) with *ALL* GL state before/after any custom GL code runs. This would involved resetting viewport, framebuffer, texture bindings etc which is slow.
    • It allows for the possibility of users creating GL3/GL4 contexts (TODO – might not work).

    Essentially the BeginGL/EndGL performs that swap.

    Yes, but it only happens inside OnRender(). The constructor is still running in mojo’s GL context. Again, not sure why it’s working (your glClearColor should be affecting the mojo GL context) but it looks like creating a GL context is also making it current. This could be an Angle thing though.

    #4714

    cocon
    Participant

    I did not think of that. Indeed you wouldn’t “trust” the user messing with the original context of mojo in case something goes wrong. Nice one!

    #5310

    cocon
    Participant

    Now I have created a 3D cube example.

    Update 29 Nov 2016: I have fixed some odd problems with the cube and cleaned up the example.The only problem is that I get weird draw Z order in the faces of the cube.
    This problem is fixed, I have declared the order of vertices in a proper manner.
    The vertex declaration is from a C++ glm example, the matrix math is from OpenTK library.
    I switched into using the Monogame math since it’s much lean and clean implementation.

    #5387

    Jesse
    Participant

    Nice indeed. Some years Ago I was trying to learn OpenGL so I looked at a few tutorials and started learning it. But with out much luck. At the time I had a project I was working on and didn’t really concentrate on learning it. I did managed to convert a few tutorials from C++ to BlitzMax. When I saw your project, I remembered I had translated a C++ OpenGL cube to Blizmax. I pulled it out and tried to see If I could convert it to Monkey2 GLES but no luck. I don’t know enough about OpenGL to do it. Here is the source and my lousy attempt at converting it to monkey2:

    source code with Blitzmax executable:

    https://www.dropbox.com/s/x8w95ggaj7tv6bq/texturecube.zip?dl=0

    source code Only:

    Attachments:
    1. texturecube.zip
    #5476

    cocon
    Participant

    Nice example, I would try to extract as many useful elements as possible.

    Another user in the forums created a cool 3D example with Monkey2, it would be a nice idea to hotlink for easy access.
    http://monkey2.monkey-x.com/forums/topic/monkey2-opengl-experiments/#post-5310

    Perhaps I will start doing texture loading as well to create a nice snippet and proceed also adding some further abstractions. Like a Mesh class or a Texture class, without going into heavy implementations.

    #5607

    EdzUp
    Participant

    Would it be possible to use OpenGL 1.x with this system, the reason I am wondering is simply MonkeyX2 could actually replace all BRL products. Max and MX1 run with OpenGL 1.x (IIRC 1.4) which would be cool to have a renderer that would cater for these systems as well.

    After looking in Currys recently there were several Laptops that had old Intel chips in them that to be honest would be along those lines?

    #5650

    cocon
    Participant

    OpenGL 1.x can be used in C and in other languages (I have used C# OpenTK a lot). In Monkey2 theoretically a wrapper could be written to access the OpenGL 1.x library functions. However doing so, would mean that a tremendous good strategy would exist, it’s a huge investment writing for legacy hardware. 🙂

    #5651

    cocon
    Participant

    After a long time, since I found a chance today I created this little fancy OpenGL example.

    Video:
    https://1drv.ms/v/s!AquVr9J7xRcsgXYmcIlKcvFD94Lw

    It was some code I made a few years ago for OpenTK, now I ported it to Monkey2, I don’t remember where exactly I got the shader from, if you know who made it you can inform me so I can add credits (lots of thanks to the developer if he/she is reading).

    Apart from that shader, if you replace the fragment part with any shader from here http://glslsandbox.com/ you could have virtually any GLSL sample available. Keep in mind to the Uniform variables only and some GLSL specifications (there are some differences between GLES and GLSL and you might get errors).

    #5654

    EdzUp
    Participant

    very interesting 🙂

     

    will look into 1.x GL as it would be a nice exercise in working the grey cells 🙂

    #5667

    cocon
    Participant

    Hi EdzUp, you could jump straight into action and try to do some tutorials. You could use Blitzmax or C++ according to what you feel more comfortable with.

    In the exact example, to draw 2 triangles ala GL1 I would simply use these statements: glBegin, glVertex, glEnd. This is the core of all the rendering pipeline (the fixed function pipeline). If you can draw let’s say a triangle, or a colored cube, you can draw and navigate inside a humongous level created with Blender. On the other hand the modern shader based pipeline is much more tricky to get started and understand. There is a need for the perfect combination of these elements before you draw anything: shader, vertex buffer, vertex attributes.

    #5681

    EdzUp
    Participant

    I’ve been coding for some thirty odd years (since ’81 😉 ). I would normally use glDrawElements to render stuff as glBegin etc is convoluted for rendering more complex stuff

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.