예제 #1
0
/// Adds a new view. Function has to be called just from the inside of view thread with a locked sync_view.
int add_view_in_thread(void* view_pars_ptr)
{
  error_if(need_safe_call(), "Calling add_view_in_thread from other thread.");
  ViewParams& view_params = *((ViewParams*)view_pars_ptr);

  //create GLUT window
  glutInitWindowPosition(view_params.x, view_params.y);
  glutInitWindowSize(view_params.width, view_params.height);
  int view_id = glutCreateWindow(view_params.title);
  glutSetWindowData(view_params.view);

  //initialize GLEW
  GLenum err = glewInit();
  error_if(err != GLEW_OK, "GLEW error: %s", glewGetErrorString(err));
  glew_initialized = true;

  //register callbacks
  glutDisplayFunc(on_display_stub);
  glutReshapeFunc(on_reshape_stub);
  glutMotionFunc(on_mouse_move_stub);
  glutPassiveMotionFunc(on_mouse_move_stub);
  glutMouseFunc(on_mouse_click_stub);
  glutKeyboardFunc(on_key_down_stub);
  glutSpecialFunc(on_special_key_stub);
  glutEntryFunc(on_entry_stub);
  glutCloseFunc(on_close_stub);

  //add to structures
  view_instances[view_id] = view_params.view;

  //call handlers
  view_params.view->on_create(view_id);

  return view_id;
}
예제 #2
0
void GlutViewer::threadFunction(int argc, char** argv)
{
	//Инициализация
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

	//Создание окна
	glutInitWindowSize(800, 800);
	windowId = glutCreateWindow("3D View");

	//Передаем в статическую функцию-обработчик указатель на класс
	glutSetWindowData(this);

	//Назначаем обработчики и ф-ию отрисовки
	glutDisplayFunc(renderSceneWrapper);
	glutSpecialFunc(keyPressedWrapper);
	glutKeyboardFunc(generalKeyPressedWrapper);
	glutIdleFunc(idleWrapper);
	glutMainLoop();

	//Сообщаем о том, что поток остановлен
	///closedMutex.lock();
	//closed = true;
	//closedMutex.unlock();
}
예제 #3
0
void open_main_window()
{
    int xtmp, ytmp;
    WindowParams bwin;
    WinUnion wun;

    init_main_menu();   /* the main menu must be created *before* the SIMM window */

    glueSetWindowPlacement(GLUT_NORMAL_WINDOW, GLUE_CENTER,
                           root.gldesc.max_screen_x,
                           root.gldesc.max_screen_y, 0, 0, NULL);

    bwin.id = glueOpenWindow("simm",no,GLUE_NO_WINDOW_FLAGS);

    glueSetWindowMinSize(950,700);

#if SIMM_DEMO_VERSION
    sprintf(buffer,"%s - Tryout Version (%s)", program_name, program_version);
#elif SIMM_VIEWER
    sprintf(buffer,"%s (%s)", program_name, program_version);
#elif defined WIN32
    strcpy(buffer, program_with_version);

    if (is_in_demo_mode())
        strcat(buffer, " - Demo Mode");
#else
    sprintf(buffer,"%s: %s, %s  %s", program_name, program_full_name,
            program_version, copyright_notice);
#endif

    mstrcpy(&bwin.name,buffer);
    glutSetIconTitle(program_name);
    glutSetWindowTitle(bwin.name);

    wun.tool = NULL;
    root.basewindow = add_window(&bwin,&wun,NOTYPE,-1,no,display_background,
                                 update_background,background);
    if (root.basewindow == -1)
        error(exit_program,tool_message);

    glutSetWindowData(bwin.id, root.basewindow);
    glueGetWindowOrigin(&root.surgwin.x1,&root.surgwin.y1);
    glueGetWindowSize(&xtmp,&ytmp);
    root.surgwin.x2 = root.surgwin.x1 + xtmp;
    root.surgwin.y2 = root.surgwin.y1 + ytmp;
}
예제 #4
0
파일: Engine.cpp 프로젝트: akkenoth/eel
void Engine::initGLUT() {
	int argc = 1;
	char *argv[] = {"Bin", NULL};
	glutInit(&argc, argv);

	if(context->core) {
		glutInitContextVersion(context->majorVersion, context->minorVersion);
		glutInitContextProfile(GLUT_CORE_PROFILE);
	} else {
		glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
	}

	glutInitDisplayMode(framebuffer->flags);
	glutInitWindowPosition(window->positionX, window->positionY);
	glutInitWindowSize(window->width, window->height);
	// in case GL_DEBUG_OUTPUT doesn't work
	// glutInitContextFlags(GLUT_DEBUG);
	glutCreateWindow(window->name.c_str());

	std::cout << "GLUT initialized\n";
	glEnable(GL_DEBUG_OUTPUT);

	glutSetWindowData(static_cast<void *>(this));

	glutIdleFunc(idleCallback);
	glutDisplayFunc(displayCallback);
	glutReshapeFunc(reshapeCallback);
	glutCloseFunc(closeCallback);

	glutKeyboardFunc(handleKeyboardCallback);
	glutKeyboardUpFunc(handleKeyboardUpCallback);
	glutSpecialFunc(handleKeyboardSpecialCallback);
	glutSpecialUpFunc(handleKeyboardSpecialUpCallback);
	glutMotionFunc(handleMouseMovement);
	glutPassiveMotionFunc(handleMouseMovement);

	initGLEW();

	glDebugMessageCallback(DebugOutput::printDebugOutput, NULL);
	//GLenum severity = GL_DEBUG_SEVERITY_LOW | GL_DEBUG_SEVERITY_MEDIUM | GL_DEBUG_SEVERITY_HIGH | GL_DEBUG_SEVERITY_NOTIFICATION;
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	std::cout << "Info | Vendor: " << glGetString(GL_VENDOR) << " | Renderer: " << glGetString(GL_RENDERER) << " | OpenGl version: " << glGetString(GL_VERSION) << std::endl;
}
예제 #5
0
/// Removes a new view. Function has to be called just from the inside of view thread with a locked sync_view.
int remove_view_in_thread(void* remove_params_ptr)
{
  debug_assert(!need_safe_call(), "E remove_view_in_thread called from other thread.");
  RemoveParams& params = *(RemoveParams*)remove_params_ptr;
  std::map<int, View*>::iterator found_view = view_instances.find(params.view_id);
  //debug_assert(found_view != view_instances.end(), "E removing of a view that is not registered");
  if (found_view == view_instances.end()) {
    debug_log("W removing of a view that is not registered\n");
    return -1;
  }

  //destroy window if requested (it will not be requested when remove is called as a reaction to on_close)
  if (params.destroy_glut_window)
  {
    //remove window from GLUT
    glutSetWindow(params.view_id);
    glutSetWindowData(NULL); //prevent stubs from being executed if there is still some message waiting for the window

    //call on-close event
    found_view->second->on_close();

    //finish removal of window from GLUT
    glutDestroyWindow(params.view_id);
  }

  //remove from structures
  view_instances.erase(found_view);

  //thread cleanup
  if (view_instances.size() == 0)
  {
    view_thread->should_quit = true;
    view_thread = NULL;

    //signal all events
    view_sync.signal_close();
    view_sync.signal_keypress();
    view_sync.signal_drawing_finished();
  }

  return 0;
}
예제 #6
0
void make_message_port(void)
{
    IntBox bbox;
    HelpStruct* hp;
    int windex;
    WindowParams mwin;
    WinUnion wun;
    SBoolean iconified;

    hp = &root.messages;

    hp->lines_per_page = 10;
    hp->window_width = 750;
    hp->window_height = 10*HELP_WINDOW_TEXT_Y_SPACING + 4;

    hp->line = (TextLine*)simm_malloc(100*sizeof(TextLine));
    if (hp->line == NULL)
        error(exit_program,tool_message);

    hp->num_lines_malloced = 100;
    hp->num_lines = 0;
    hp->starting_line = 0;
    hp->background_color = HELP_WINDOW_BACKGROUND;

    bbox.x2 = hp->window_width;
    bbox.x1 = bbox.x2 - 20;
    bbox.y2 = hp->window_height;
    bbox.y1 = 0;

    make_slider(&hp->sl,vertical_slider,bbox,0,(double)(hp->num_lines)*20.0,
                (double)(hp->lines_per_page)*20.0,(double)(hp->num_lines)*20.0,4.0,NULL,NULL);
    glueSetWindowPlacement(GLUT_NORMAL_WINDOW, GLUE_SOUTHWEST,
                           hp->window_width, hp->window_height,
                           0, 0, NULL);

#if defined WIN32 && SIMM_DEMO_VERSION
    iconified = is_in_demo_mode();
#else
    iconified = no;
#endif
    mwin.id = hp->window_id = glueOpenWindow("simmmess",iconified,GLUE_TOOL_WINDOW);

    glueSetWindowMinSize(500,100);
    mstrcpy(&mwin.name,"SIMM Messages");
    glutSetIconTitle("Messages");
    glutSetWindowTitle(mwin.name);

    wun.tool = NULL;

    windex = add_window(&mwin,&wun,NOTYPE,ZERO,no,draw_message_window,
                        update_message_window,messages_input);
    if (windex == -1)
        error(exit_program,tool_message);

    glutSetWindowData(mwin.id, windex);

    if (expirationMessage)
    {
        error(none, expirationMessage);

        FREE_IFNOTNULL(expirationMessage);
    }
}