OpenGL context



  • On 10/08/2014 at 06:24, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R14 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi Folks,

    is someone able to shed some light on how to create and work with an OpenGL context using the C4D_CreateOpenGLContext()? I'm trying to create a preview in a GeUserArea, and I'm needing OGL because I need a little more grunt than what the native draws can provide. Something similar to a material preview. I'm not after OGL support, but rather on how to get it started with as much c4d-related code as possible. There is just nothing anywhere on how to use the native-SDK objects on this matter.

    I can briefly describe what I'm trying to do, as creating an OGL context, draw into it, then use glReadPixels() on the memory buffer to transfer the draw pixel data into a BaseBitmap.

    My hand is being forced on this, as it's a significant part of the plugin and I can't get any further without this now. I'm a user at the OpenGL community, but I would rather use as much c4d-related code as I can before delving too much into doing it outside of the native-SDK objects. As I mentioned, I'm not after OGL support in general, but rather on how to create and work with a context using C4D SDK objects so that I can retrieve it's pixel data - i.e. setting the context up and making it current.

    Regards,

    WP.

    EDIT: spelling update



  • On 10/08/2014 at 14:01, xxxxxxxx wrote:

    if you are after a material preview (in a separate window other than Cinema4D viewport) , you may escape with any OpenGL (like Qt OpenGL which is awesome and got its own frame buffers/widgets)



  • On 11/08/2014 at 05:49, xxxxxxxx wrote:

    Hi Mohamed,

    I had been playing around with ogl and glew - maybe it'll be easier to just use them. Though it seems a pity given the sdk provides a context creator to begin with. You'd think the developers would want you to use their 'stuff' before turning to something outside the sdk.

    The c4d gl header has a bunch of objects in there, don't know if you've seen that, but even with that there - there's still nothing on how you're suppose to use what's in it. I can't for instance, find anything in the sdk on making the created context current. There might be something there to do that! But I can't find any mention of this.

    WP.

    EDIT: spelling mistake corrected!



  • On 11/08/2014 at 07:12, xxxxxxxx wrote:

    well, I know this 🙂, header got everything, but nothing about how to implement them together

    I strongly recommend that you watch this playlist of modern OpenGL "it is written similar to GLEW but using Qt"

    https://www.youtube.com/playlist?list=PLRwVmtr-pp06qT6ckboaOhnm9FxmzHpbY



  • On 11/08/2014 at 15:28, xxxxxxxx wrote:

    Qt is a very nice OpenGL interface.  My programming friend swears by it.  Have also played with glut and glu in that regards.



  • On 12/08/2014 at 04:53, xxxxxxxx wrote:

    Thanks Rob and Mohamed,

    I haven't used Qt, but the tutorial videos I've been through so far have been quite helpful - thanks for the link Mohamed.

    Will see if I can build a bridge between the two systems.

    WP.



  • On 12/08/2014 at 10:13, xxxxxxxx wrote:

    The bridge is the hardest part.
    I've been able to create simple Win32 dialogs.  And splash screens with win32 gizmos.
    But since C4D does not receive Windows messages. It's impossible for me to do anything substantial with any outside programs.

    There's a big world of GUI stuff out there.
    But we can't use it because there's no way to get C4D to communicate with them.
    At least none that I've seen.

    -ScottA



  • On 12/08/2014 at 12:46, xxxxxxxx wrote:

    @Scotta I think the connection may be easier than what you think using Qt Tongue

    mainly, you will have a class inheritance from Cinema4D base classes "like a cube object or anything", this class got its private variables that you want to modify

    you will have another class which inherits from Qt widgets, once you click or trigger Qt widget it will send a call back (called SIGNALS and SLOTS) , Qt got its own interface which is very powerful and easy to use

    to connect them, very simple!!, make the Qt class a friend of the Cinema4D class so it will modify its private variables

    this is not tested, but I guess it should work



  • On 12/08/2014 at 13:31, xxxxxxxx wrote:

    I'd love to see an example of this using QT.

    Right now the most advanced thing I can do with Win32 is control the position, size, and  Min/Max settings of the C4D windows. I posted a working example of that on my site.
    But I've never found any information about doing QT<--->C4D.

    It would be wonderful to be able to use QT inside of C4D.

    -ScottA



  • On 15/08/2014 at 06:55, xxxxxxxx wrote:

    Well, I can get a QWidget dialog to show alongside my plugins', but as soon as I start introducing QGLWidget objects cinema crashes on startup. No reports are given.

    Friending the classes I don't think will solve the bridge because I can't find anything on setting a QWidget's window handle, which means you end up with more than one dialog object. And I'm trying to avoid using non-sdk dialogs - if anything just because the dialog and all the plugin's gui elements are already built into the sdk dialog.

    Unless this can be done without needing a QWidget dialog open (and without cinema crashing when QGLWidget's are introduced) then I don't think this will solve the gap between an SDK dialog and an opengl context draw. You might be able to get the draw from the open QWidget's window, but you have to have another window open to do this which defeats the purpose of trying to bring this altogether under the one SDK dialog.

    This is becoming very frustrating - and with lots of lost development time (weeks)

    WP.



  • On 15/08/2014 at 07:28, xxxxxxxx wrote:

    avoid QGLWidget ... , use Qt 5.2 new QOpenGL classes, they inherit from QWidget
    check the hello Triangle example in Qt 5.2, it shows the new OpenGL class in Qt 5.2



  • On 15/08/2014 at 14:50, xxxxxxxx wrote:

    I took a look at one of my Win32 tests to refresh my memory.
    And the problem is more than just sharing classes.

    I built a Win32 dialog with a Win32 button gizmo on it. And when I press the button it tells c4d to create a sphere object. But nothing happens until I move the mouse cursor around in C4D. Because there's no way for C4D to know that my Win32 dialog has executed a change in C4D.
    This problem happens because C4D can't receive messages from my Win32 dialog.
    I would expect this same problem to exist using QT, or anything else.

    Without C4D able to receive messages from Windows or outside GUI managers. I don't see how C4D can use them? Except in very limited cases.
    For example: Splash screens that don't require communication with C4D.

    The Maya developers needed to write a special bridge for QT. So I'm guessing that Maxon would also need to write something similar in order for us to use it the same way.
    And based on the negative feedback I got from one of the Maxon developers about QT...That will never happen.

    -ScottA



  • On 15/08/2014 at 15:07, xxxxxxxx wrote:

    I will do an example soon showing why Qt is different 🙂 , about 2 weeks from now as I'm currently busy in other stuff, but I'm sure that the solution is as simple as class bridges

    it is all about "triggering the event loop in Cinema4D" , when you click a command plugin in Cinema4D "for example" , you trigger an event which forces Cinema4D to reply with a callback, the same concept here, trigger an event in Qt, you will get a callback from Qt, tell it to update events in Cinema4D at the end (I'm sure there is a call for this event update), and it should work



  • On 15/08/2014 at 17:29, xxxxxxxx wrote:

    OK thanks.
    There's no information on doing things like this with C4D. So it will be nice to see an example.

    Win32 also uses a callback method. And what you're describing sounds fairly generic.
    If it works with QT then it might also work with Win32.

    -ScottA



  • On 15/08/2014 at 18:55, xxxxxxxx wrote:

    When I woke up this morning it occurred to me that Qt might have an FBO equivalent - but I'm not sure where I read that, or what it needs to work so far as handles etc are concerned. That said, I'll take a look into the latest release of Qt. I had been using 4.x inline with the tutorial videos for the purpose of seeing how Qt worked in general.

    Scott - I don't suppose the developer(s) had any suggestions as to what we could/should use instead?

    WP.



  • On 15/08/2014 at 20:01, xxxxxxxx wrote:

    He just said that QT was slow. And that some Maya users were complaining about it when I asked for Maxon to support QT.
    I've built a couple of plugins for Maya. And used QT GUIs. And never saw any speed problems with it. But I've only done a couple basic plugins with it.

    It was at that time that I realized that Maxon thinks their gui framework is just fine and dandy being stuck in the 90's. And doesn't need any updating to modern WYSIWYG standards.
    And that's when I started playing around with Win32 stuff to see if I could write my own gui stuff for my C4D plugins.

    I'd prefer to use Win32 gui's over QT because it's already there in V.S. And I don't write Mac plugins.
    But if there's a way to make QT talk to C4D I'd love to use it.

    -ScottA



  • On 15/08/2014 at 22:15, xxxxxxxx wrote:

    to be honest, C4D framework is faster than Qt, but Qt is kinda more robust "you can design what you want without limitations"


Log in to reply