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)
}
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);
}
Related
How can I:
1) properly set Gtk::Notebook in Gtk::HeaderBar like:
window.add(box);
2) implement autohide tabs ( animated like css transitions with scale(0) and scale(1) ) ?
My code:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main app(argc, argv);
Gtk::Window window;
window.set_default_size(200, 200);
Gtk::HBox box;
Gtk::HeaderBar titlebar;
Gtk::Notebook notebook;
Gtk::TextView text;
notebook.append_page(text, "First");
box.pack_start(notebook);
titlebar.set_custom_title(box);
window.set_titlebar(titlebar);
window.show_all_children();
return app.run(window);
}
For example, in my "test.txt" file
2 3
2 4
2 5
When I show in my OpenGL/C++ ( I'm using graph to represent it )
so when I go to my "test.txt" file and change some value and want to see
the new graph with new data without stop and recompile back.
isn't any way to refresh it?
NOTE: glutPostRedisplay() not working.
Thanks
void drawScene(void)
{
readFile(inFile);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,0.0);
histogram();
linestrip();
piechart2012();
piechart2013();
glFlush();
//readFile(inFile);
}
int main( int argc, char **argv )
{
glutInit (&argc, argv); /* Initialise OpenGL */
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
printInteraction();
glutCreateWindow ( "square.cpp" ); /* Create the window */
glutDisplayFunc (drawScene); /* Register the "display" function */
glutReshapeFunc(resize);
glutKeyboardFunc(keyInput);
setup();
glutMainLoop(); /* Enter the OpenGL main loop */
return 0;
}
Using glutKeyboardFunc in a very simple exemple, i could get it to work very easily :
void special(int key, int x, int y) {
printf("key %d\n", key);
}
void keyboard(unsigned char key, int x, int y) {
printf("key %d\n", key);
}
void display() {}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("GLUT Program");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMainLoop();
return EXIT_SUCCESS;
}
but using it with a very complex display function, the keyboard routine is never called, I am not sure about the part that prevents this call from working so i am just asking here for ideas about what could be the cause, i can't really post the code because that would be the entire project... i am using freeglut with an opengl context and glm for math computation.
Nevertheless here is the new call :
static void loop_function() {
glutSetWindow(win);
Scene::unique_scene->mainloop();
}
I am a bit lost about what to do to find the error, if someone could enlighten me i would be grateful.
Having an infinite loop in the glutDisplayFunc is not the way to go, it is called automatically at the end of the glutKeyboardFunc if you added the call
glutPostRedisplay();
I am trying to implement zoom in or zoom out operations using mouse scroll button
by glutMouseWheelFunc in opengl . I have implemted the code as below :
#include<GL/freeglut.h>
void mouseWheel(int button, int dir, int x, int y)
{
printf("in mouse wheel \n");
if (dir > 0)
{
// Zoom in
ztrans = ztrans - 1.0;
printf("scroll in = %0.3f\n ",ztrans);
}
else
{
// Zoom out
ztrans = ztrans + 1.0;
printf("scroll out = %0.3f\n ",ztrans);
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
// general initializations
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 400);
glutCreateWindow("Rotation");
// register callbacks
glutReshapeFunc(changeSize);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutIgnoreKeyRepeat(1);
glutMouseFunc(mouseButton);
glutMotionFunc(mouseMove);
glutMouseWheelFunc(mouseWheel); // Register mouse wheel function
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}
On executing, it is not calling the registered callback function(mouseWheel) . My system has freeglut3 installed.
try using
a static int inside void mouseWheelmethod, and then use it in renderScene
like this
static int k;
static int ztrans
void mouseWheel(int button, int dir, int x, int y)
{
k = dir; // int dir is +1 of -1 based on the direction of the wheel motion
ztrans = ztrans + k;
}
This worked for me,
Try this and feedback, GoodLuck .
I have created a simple Visual Studio Express 2010 C++ project using GLUT and OpenGL,
it compiles and runs ok, except that the window it creates receives no events..
the close/minimize buttons don't do anything (not even mouseover) no context menu on the task bar on right click, and the window doesn't come to the foreground when clicked if partially covered.
The project is set up as a console application, I can close the program by closing the console.
I have this in main:
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("MyApp");
glutIdleFunc(main_loop_function);
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
if (GLEW_VERSION_1_3)
{
fprintf(stdout, "OpenGL 1.3 is supported \n");
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
GL_Setup(window_width, window_height);
glutMainLoop();
}
You miss a display callback. Could you try:
void display();
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("MyApp");
/// glutIdleFunc(main_loop_function);
glutDisplayFunc(display);
// ...
glutMainLoop();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
Also, your idle function seems bad, if you effectively loop inside that function. Glut is callback oriented. You don't need to create a loop, but rather rely on idle, mouse, keyboard, display and resize callbacks. If you don't do so, you are going to miss window manager events.
EDIT:
If you want to create an animation, you could use:
glutIdleFunc(idleFunc);
void idleFunc(){
glutPostRedisplay();
}