Search code examples
openglvisual-c++c++-cli

OpenGL with winform C++/CLR


Is it possible to call the function

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Window");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(mouseMovement); //check for mousemovement
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;
}

inside a button click event ? where display,keyboard etc are different functions

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    {
          main(); -------(Not sure of syntax)
    }

Solution

  • I got it. Just had to create a class the call the function as an object in the button click event and it was working as I wanted. Thanks for the help anyways

    Just declared a class in the header file

    class foo
    {
    public:
        foo();
        ~foo();
        int main(int argc, char **argv);
    
    };
    

    Defined the main function in the .cpp as

     foo::foo()
        {
        }
    
    
        foo::~foo()
        {
        }
    
         - - - -  - - - - - - - - - - - - - -
        ------Other functions here-----
         - - - -  - - - - - - - - - - - - - -
        //main function    
        int foo::main(int argc, char **argv) {
            glutInit(&argc, argv);
            glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
            glutInitWindowSize(500, 500);
            -------------
            ----------
            glutMainLoop();
            return 0;
    }
    

    And finally call it in the button click event

    private: System::Void btn_Load_Click(System::Object^  sender, System::EventArgs^  e)  
    {
    
        foo Objct;
        int Arg1;
        char** Arg2;
        int functn = Objct.main(Arg1, Arg2);
    }