void initGL(int *argc, char **argv)
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowSize(width, height);
    glutCreateWindow(sSDKsample);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);

#if defined (__APPLE__) || defined(MACOSX)
    atexit(cleanup);
#else
    glutCloseFunc(cleanup);
#endif

    printf("Press '+' and '-' to change filter width\n");
    printf("0, 1, 2 - change filter order\n");

    glewInit();

    if (!glewIsSupported("GL_VERSION_2_0 GL_ARB_vertex_buffer_object GL_ARB_pixel_buffer_object"))
    {
        fprintf(stderr, "Required OpenGL extensions missing.");
        exit(EXIT_FAILURE);
    }
}
Пример #2
0
void register_callbacks(void) {
	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(reshape);
	glutTimerFunc(100, timer_scene, 0);
	glutCloseFunc(cleanup);
}
Пример #3
0
void create_window(int argc, char* argv[]) {
	glutInit(&argc, argv);
	glutInitContextVersion(DOBO_MAJOR_VERSION, DOBO_MINOR_VERSION);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);

	glutSetOption(
		GLUT_ACTION_ON_WINDOW_CLOSE,
		GLUT_ACTION_GLUTMAINLOOP_RETURNS
	);
	glutInitWindowSize(window_width, window_height);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	window_handle = glutCreateWindow(WINDOW_TITLE_PREFIX);

	if(window_handle < 1) {
		fprintf(
			stderr,
			"ERROR: Could not create a rendering window.\n"
		);
		exit(EXIT_FAILURE);
	}

	glutReshapeFunc(window_resize_func);
	glutDisplayFunc(window_render_func);
	glutIdleFunc(idle_func);
	glutTimerFunc(0, timer_func, 0);
	glutCloseFunc(shutdown);
	glutKeyboardFunc(keyboard_func);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
int initGL(int *argc, char **argv)
{
    printf("Initializing GLUT...\n");
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(imageW, imageH);
    glutInitWindowPosition(512 - imageW / 2, 384 - imageH / 2);
    glutCreateWindow(argv[0]);
    glutDisplayFunc(displayFunc);
    glutKeyboardFunc(keyboard);
    glutTimerFunc(REFRESH_DELAY, timerEvent,0);
    printf("OpenGL window created.\n");

#if defined (__APPLE__) || defined(MACOSX)
    atexit(cleanup);
#else
    glutCloseFunc(cleanup);
#endif

    glewInit();
    printf("Loading extensions: %s\n", glewGetErrorString(glewInit()));

    if (!glewIsSupported("GL_VERSION_1_5 GL_ARB_vertex_buffer_object GL_ARB_pixel_buffer_object"))
    {
        fprintf(stderr, "Error: failed to get minimal extensions for demo\n");
        fprintf(stderr, "This sample requires:\n");
        fprintf(stderr, "  OpenGL version 1.5\n");
        fprintf(stderr, "  GL_ARB_vertex_buffer_object\n");
        fprintf(stderr, "  GL_ARB_pixel_buffer_object\n");
        fflush(stderr);
        return false;
    }

    return 0;
}
Пример #5
0
bool
CameraCalib::InitGlutUI(int argc, WCHAR* argvW[]) {
	srand(unsigned int(time(NULL)));

	const size_t len = wcsnlen(argvW[0], 1024);
	std::unique_ptr<char[]> argvuq(new char[len + 1]);
	char *pStr = (argvuq.get());
	size_t lastChar = 0;
	wcstombs_s(&lastChar, pStr, len, argvW[0], len - 1);
	pStr[lastChar] = '\0';
	char **argv = &pStr;
	argc = 1;

	glutInit(&argc, argv);
	glutInitWindowSize(windowRect[0], windowRect[1]);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); //
	mainWnd = glutCreateWindow("CameraCalib");

	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		std::wcout << L"Camera Calib" << glewGetErrorString(err) << std::endl;
		return false;
	}
	
	glutDisplayFunc(clbDisplay);
	glutKeyboardFunc(clbKeys);
	glutReshapeFunc(clbReshape);
	glutMouseFunc(clbMouse);
	glutCloseFunc(clbExitFunc);

	glEnable(GL_DEPTH_TEST);
	return true;
}
Пример #6
0
void game_init(int* argc, char** argv, const char* title) {
  glutInit(argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  glutInitWindowSize(800, 600);
  glutInitContextVersion(3, 1);
  glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
  glutInitContextProfile(GLUT_CORE_PROFILE);
  glutCreateWindow(title);
  glewExperimental = true;
  glewInit();

  glutKeyboardFunc(keyboard_down);
  glutKeyboardUpFunc(keyboard_up);
  glutSpecialFunc(keyboard_special_down);
  glutSpecialUpFunc(keyboard_special_up);
  glutCloseFunc(window_close);

  glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

  bodies = list_new();
  body_program = pipeline_new(
    shader_new(SHADER_VERTEX, "body.vert"),
    shader_new(SHADER_FRAGMENT, "body.frag"));

  glGenVertexArrays(1, &body_vao);
  glBindVertexArray(body_vao);

  pipeline_attribute(body_program, "coord", 0);
  pipeline_attribute(body_program, "color", 1);
}
Пример #7
0
static void registerCallbacks ()
{
  glutIdleFunc(gst_glut_IdleFunc);
  glutKeyboardFunc(gst_glut_KeyboardFunc);
  glutSpecialFunc(gst_glut_SpecialFunc);
  glutReshapeFunc(gst_glut_ReshapeFunc);
  glutVisibilityFunc(gst_glut_VisibilityFunc);
  glutDisplayFunc(gst_glut_DisplayFunc); 
  glutMouseFunc(gst_glut_MouseFunc);
  glutMotionFunc(gst_glut_MotionFunc);
  glutPassiveMotionFunc(gst_glut_PassiveMotionFunc);
  glutEntryFunc(gst_glut_EntryFunc);
  glutKeyboardUpFunc(gst_glut_KeyboardUpFunc);
  glutSpecialUpFunc(gst_glut_SpecialUpFunc);
  glutMenuStateFunc(gst_glut_MenuStateFunc);
  glutMenuStatusFunc(gst_glut_MenuStatusFunc);
  glutOverlayDisplayFunc(gst_glut_OverlayDisplayFunc);
  glutWindowStatusFunc(gst_glut_WindowStatusFunc);
  glutSpaceballMotionFunc(gst_glut_SpaceballMotionFunc);
  glutSpaceballRotateFunc(gst_glut_SpaceballRotateFunc);
  glutSpaceballButtonFunc(gst_glut_SpaceballButtonFunc);
  glutButtonBoxFunc(gst_glut_ButtonBoxFunc);
  glutDialsFunc(gst_glut_DialsFunc);
  glutTabletMotionFunc(gst_glut_TabletMotionFunc);
  glutTabletButtonFunc(gst_glut_TabletButtonFunc);
  glutWMCloseFunc(gst_glut_WMCloseFunc);

#if 0
  glutJoystickFunc(gst_glut_JoystickFunc);
  glutMouseWheelFunc(gst_glut_MouseWheelFunc);
  glutCloseFunc(gst_glut_CloseFunc);
  glutMenuDestroyFunc(gst_glut_MenuDestroyFunc);
#endif
}
Пример #8
0
inline Int flua_createGLUTWindow(char* title, int width, int height, bool fullscreen = false) {
    glutInitWindowPosition((flua_getScreenWidth() - width) / 2, (flua_getScreenHeight() - height) / 2);
    glutInitWindowSize(width, height);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_ALPHA | GLUT_RGB | GLUT_DEPTH);

    int winId = glutCreateWindow(title);

    //flua_setVSync(true);

    // Force first call (not called automatically on Windows)
#ifdef _WIN32
    flua_onReshape(width, height);
#endif


    // Mouse
    glutMotionFunc(flua_onMouseMove);
    glutPassiveMotionFunc(flua_onMouseMove);
    glutReshapeFunc(flua_onReshape);

    // Keyboard
    glutKeyboardFunc(flua_onKeyDown);
    glutKeyboardUpFunc(flua_onKeyUp);
    glutSpecialFunc(flua_onSpecialKeyDown);
    glutSpecialUpFunc(flua_onSpecialKeyUp);

    glutCloseFunc(flua_onClose);
    flua_glutRunFlag = true;

    return winId;
}
Пример #9
0
int main(int argc, char* argv[]) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(400, 350);
  glutInitContextVersion(3, 3);
  glutInitContextProfile(GLUT_CORE_PROFILE);
  glutCreateWindow("465 Raw Texture {b, f, t} : front view");
  // initialize and verify glew
  glewExperimental = GL_TRUE;  // needed my home system 
  GLenum err = glewInit();  
  if (GLEW_OK != err) 
      printf("GLEW Error: %s \n", glewGetErrorString(err));      
    else {
      printf("Using GLEW %s \n", glewGetString(GLEW_VERSION));
      printf("OpenGL %s, GLSL %s\n", 
        glGetString(GL_VERSION),
        glGetString(GL_SHADING_LANGUAGE_VERSION));
      }
  // initialize scene
  init();
  // set glut callback functions
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);
  glutTimerFunc(40, spin, 1);
  glutCloseFunc(cleanUp);  // freeglut only
  // Note: glutSetOption is only available with freeglut
  glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
              GLUT_ACTION_GLUTMAINLOOP_RETURNS);
  glutMainLoop();
  printf("exit main() \n");
  return 0;
  }
Пример #10
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;
}
Пример #11
0
// -----------------------------------------------
Window::Window() :
    mId(0),
    mKeys(),
    mMouseButtons(),
    mMousePos(),
    mPreviousMousePos(),
    mMouseForce(),
    mMouseMoved(false),
    mClosed(false) {

    if (!mInitialised) {
        mInitialised = true;
        int argc = 0;
        glutInit(&argc, nullptr);
        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
    }

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(defaultSize.x(), defaultSize.y());
    mId = glutCreateWindow("wzy::Window");

    if (!mId)
        throw Exception("Unable to create wzy::Window.");

    glutDisplayFunc(displayFunc);
    glutReshapeFunc(reshapeFunc);
    glutKeyboardFunc(keyboardFunc);
    glutKeyboardUpFunc(keyboardUpFunc);
    glutMouseFunc(mouseFunc);
    glutMotionFunc(motionFunc);
    glutPassiveMotionFunc(passiveMotionFunc);
    glutCloseFunc(closeFunc);

    mWindows.insert(std::make_pair(mId, this));
}
Пример #12
0
//-----------------implementation of windows class-------------------------------
Window::Window (int *argc, char *argv[], int window_width, int window_height, const char *window_title)
{
	//init camera
	camera.width = window_width;
	camera.height = window_height;
	is_close = false;
	camera.center = vector2d (0, 2.0);
	camera.scale = 5.0;
	//init keyboard
	for (int i = 0; i < 256; i++)
		keys[i] = false;

	//start logging
	InitLog ();

	//create window
	glutInit (argc, argv);
	glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowSize (camera.width, camera.height);
	handle = glutCreateWindow (window_title);

	//set callbacks
	glutDisplayFunc (display);
	glutReshapeFunc (reshape);
	glutCloseFunc (close);
	glutKeyboardFunc (key_down);
	glutKeyboardUpFunc (key_up);
	glutMotionFunc (mouse_move);
	glutPassiveMotionFunc (mouse_move);
	glutMouseFunc (mouse_press);
	glutMouseWheelFunc (mouse_wheel);
	log (LOG_INFO, "Window \"%s\" created succesfully", window_title);
}
Пример #13
0
int
main(int argc, char *argv[])
{
    signal(SIGTERM, &writeToDisk);
    signal(SIGINT, &writeToDisk);
    if(argc < 2)
    {
        std::cout << "no IP address specified, defaulting to loopback..." << std::endl;
        openGLSocket = setupSocket("127.0.0.1", 8999);
    }
    else
    {
        std::cout << "using provided address: " << argv[1] << std::endl;
        openGLSocket = setupSocket(argv[1], 8999);
    }
    init();
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutInitWindowSize((int) width, (int) height);
    wd = glutCreateWindow("Client Buffer" /* title */ );
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboardHandler);
    glutSpecialFunc(specialKeyHandler);
    glutReshapeFunc(reshape);
    glutIdleFunc(socketHandler);
    glutCloseFunc(glutWriteToDisk);
#ifndef __APPLE__
    glewInit();
#endif
    /* start the GLUT main loop */
    glutMainLoop();
    return 0;
}
Пример #14
0
void InitWindow(int argc, char* argv[])
{
  glutInit(&argc, argv);
  
  glutInitContextVersion(3, 3);
  glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
  glutInitContextProfile(GLUT_CORE_PROFILE);

  glutSetOption(
    GLUT_ACTION_ON_WINDOW_CLOSE,
    GLUT_ACTION_GLUTMAINLOOP_RETURNS
  );
  
  glutInitWindowSize(CurrentWidth, CurrentHeight);

  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

  WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

  if(WindowHandle < 1) {
    fprintf(
      stderr,
      "ERROR: Could not create a new rendering window.\n"
    );
    exit(EXIT_FAILURE);
  }
  
  glutReshapeFunc(ResizeFunction);
  glutDisplayFunc(RenderFunction);
  glutIdleFunc(IdleFunction);
  glutTimerFunc(0, TimerFunction, 0);
  glutCloseFunc(Cleanup);
}
Пример #15
0
int main(int argc, char **argv)
{
	// set window values
	win1.width = 640*1.5;
	win1.height = 480*1.5;
	win1.title = "Tutorial 4";
	win1.fovAngle = 45;
	win1.zNear = 0.1f;
	win1.zFar = 500.0f;

	//initialize and run program
	glutInit(&argc, argv);                                      // GLUT initialization
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);  // Display Mode
	glutInitWindowSize(win1.width, win1.height);					// set window size
	win1.id = glutCreateWindow(win1.title);					    // create Window

	glutDisplayFunc(display);									// register Display Function
	glutKeyboardUpFunc(keyboardUp);								    // register Keyboard Handler
	glutKeyboardFunc(keyboardDown);								    // register Keyboard Handler
	glutSpecialUpFunc(specialUp);
	glutSpecialFunc(specialDown);
	glutCloseFunc(close);

	GLenum res = glewInit();
	if (res != GLEW_OK) {
		fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
		return 1;
	}

	initShaders();
	initialize();
	glutMainLoop();												// run GLUT mainloop
	return 0;
}
Пример #16
0
int main(int argc, char *argv[]) {
	/* Start logging */
	hvLogInit(HV_LOG_DEBUG, stdout);
	hvPrint("Krzysztof Abramowicz (http://abramowicz.info/, [email protected])");
	hvPrint("HyperVision Design Stage One (ISO C '99 + OpenGL 3.3 + GLUT 2.6)");
	hvLogTabWidth(4);
/*d
	hvLogLimits();
	hvLogFloats();
*/
	/* Initialise window and canvas */
	hvAppInitWindow(curWidth, curHeight, PROGRAM_NAME);
	hvAppInitCanvas();

	/* Register callbacks */
	hvAppEvent(HV_RESHAPE, hvaReshape);
	hvAppEvent(HV_DISPLAY, hvaDisplay);
	hvAppEvent(HV_SPECIAL, hvaSpecial);
	hvAppEvent(HV_KEYBOARD, hvaKeyboard);
	hvAppEvent(HV_IDLE, hvaIdle);

	/* Build shaders */
	shaderProgram = hvCreateProgram(HV_VSHADER_PHONG, HV_FSHADER_PHONG);
	hvInfo("Shader program built (phong lighting model)");
/*d
	hvProgramInfo(&shaderProgram);
*/
	/* Construct models */
	letterH = hvCreateStockModel(HV_MODEL_H);
	hvModelColor(&letterH, rgb(.1f, .8f, .1f));
	hvInfo("model \"", hvModelName(&letterH), "\" created (", hvNum(hvModelFaces(&letterH)), " triangles)");

	letterV = hvCreateStockModel(HV_MODEL_V);
	hvModelColor(&letterV, rgb(.1f, .1f, .8f));
	hvInfo("model \"", hvModelName(&letterV), "\" created (", hvNum(hvModelFaces(&letterV)), " triangles)");
/*e
	cube = hvCreateStockModel(HV_MODEL_CUBE);
	hvModelColor(&cube, rgb(1.0f, .5f, .0f));
*/
	/* Calculate the view matrix */
	hvMatrixViewCamera(&viewMatrix, vec(camX, 0, camZ), vec(0, 0, 0), vec(0, 1, 0));
	hvDebug("View matrix preview:");
	hvMatrixPrintFC(&viewMatrix);

		/* Playing ground :-) */
		glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glPointSize(4.0f);
		if (argc > 0 && argv[0][0] != '\0')
			hvDebug("Prgram name: ", argv[0]);

	/* enter the main loop */
	glutCloseFunc(hvaClean);
	glutTimerFunc(0, hvaTimer, 0);
	hvInfo("Entering main rendering loop...");
	glutMainLoop();	
	hvInfo("Exited successfully");
	hvLogTerm();
}
Пример #17
0
int main( int argc, char ** argv ) {
   // Размеры окна по-умолчанию
   size_t const default_width  = 800;
   size_t const default_height = 800;

   glutInit               (&argc, argv);
   glutInitWindowSize     (default_width, default_height);
   // Указание формата буфера экрана:
   // - GLUT_DOUBLE - двойная буферизация
   // - GLUT_RGB - 3-ёх компонентный цвет
   // - GLUT_DEPTH - будет использоваться буфер глубины
   glutInitDisplayMode    (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   // Создаем контекст версии 3.2
   glutInitContextVersion (3, 0);
   // Контекст будет поддерживать отладку и "устаревшую" функциональность, которой, например, может пользоваться библиотека AntTweakBar
  // glutInitContextFlags   (GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
   // Указание либо на core либо на compatibility профил
   //glutInitContextProfile (GLUT_COMPATIBILITY_PROFILE );
   int window_handle = glutCreateWindow("OpenGL basic sample");

   // Инициализация указателей на функции OpenGL
   if (glewInit() != GLEW_OK) {
      cerr << "GLEW init failed" << endl;
      return 1;
   }

   // Проверка созданности контекста той версии, какой мы запрашивали
   if (!GLEW_VERSION_3_0) {
      cerr << "OpenGL 3.0 not supported" << endl;
      return 1;
   }

   // подписываемся на оконные события
   glutReshapeFunc(reshape_func);
   glutDisplayFunc(display_func);
   glutIdleFunc   (idle_func   );
   glutCloseFunc  (close_func  );
   glutKeyboardFunc(keyboard_func);

   // подписываемся на события для AntTweakBar'а
   glutMouseFunc        ((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
   glutMotionFunc       ((GLUTmousemotionfun)TwEventMouseMotionGLUT);
   glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
   glutSpecialFunc      ((GLUTspecialfun    )TwEventSpecialGLUT    );
   TwGLUTModifiersFunc  (glutGetModifiers);

   try {
      // Создание класса-примера
      prog_state_ptr.reset(new prog_state());
      // Вход в главный цикл приложения
      glutMainLoop();
   }
   catch( std::exception const & except ) {
      std::cout << except.what() << endl;
      return 1;
   }

   return 0;
}
Пример #18
0
void setupCallbacks() 
{
    glutCloseFunc(cleanup);
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutReshapeFunc(reshape);
    glutTimerFunc(0,timer,0);
}
Пример #19
0
//
// Function: lcdGlutClose
//
// Callback for glut window close event
//
static void lcdGlutClose(void)
{
  // Attempt to shutdown gracefully
  glutCloseFunc(NULL);
  glutDestroyWindow(winGlutWin);
  deviceActive = GLCD_FALSE;
  lcdGlutInitArgs.winClose();
}
Пример #20
0
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int
main(int argc, char **argv)
{
    pArgc = &argc;
    pArgv = argv;

    char *ref_file = NULL;

    printf("%s Starting...\n\n", sSDKsample);

    if (checkCmdLineFlag(argc, (const char **)argv, "file"))
    {
        fpsLimit = frameCheckNumber;
        getCmdLineArgumentString(argc, (const char **)argv, "file", &ref_file);
    }

    if (ref_file)
    {
        chooseCudaDevice(argc, argv, false);

        loadVolumeData(argv[0]);

        runAutoTest(ref_file, argv[0]);
    }
    else
    {
        // First initialize OpenGL context, so we can properly set the GL for CUDA.
        // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop.
        initGL(&argc, argv);

        // use command-line specified CUDA device, otherwise use device with highest Gflops/s
        chooseCudaDevice(argc, argv, true);

        // OpenGL buffers
        initGLBuffers();

        loadVolumeData(argv[0]);
    }

    printf("Press space to toggle animation\n"
           "Press '+' and '-' to change displayed slice\n");

#if defined (__APPLE__) || defined(MACOSX)
    atexit(cleanup);
#else
    glutCloseFunc(cleanup);
#endif

    glutMainLoop();

    exit(EXIT_SUCCESS);
}
Пример #21
0
////////////////////////////////////////////////////////////////////////////////
// Main
//
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
	const GLuint CONTEXT_MAJOR = 4;
	const GLuint CONTEXT_MINOR = 2;

	// init glut
	glutInit(&argc, argv);
	glutInitContextVersion(CONTEXT_MAJOR ,CONTEXT_MINOR);

	glutInitContextFlags(GLUT_DEBUG);
	glutInitContextProfile(GLUT_CORE_PROFILE);

//	glutInitContextFlags(GLUT_DEBUG | GLUT_FORWARD_COMPATIBLE);
//	glutInitContextProfile(GLUT_CORE_PROFILE);


	// build window
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(0, 0);
	glutCreateWindow("OpenGL");

	// init glew
	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if(GLEW_OK != err)
	{
		std::stringstream ss;
		ss << err;
		std::cerr << "glewInit() gave error " << ss.str() << std::endl;
		return 1;
	}

	// glewInit generates an INVALID_ENUM error for some reason...
	glGetError();

	// set callbacks
	glutCloseFunc(&on_clean);
	glutReshapeFunc(&on_resize);
	glutDisplayFunc(&on_update);
	glutKeyboardFunc(&on_key_down);
	glutMouseFunc(&on_mouse_button);
	glutPassiveMotionFunc(&on_mouse_motion);
	glutMotionFunc(&on_mouse_motion);
	glutMouseWheelFunc(&on_mouse_wheel);

	// run
	on_init();
//	glutMainLoop();

	return 0;
}
Пример #22
0
gl_window init_gl_context(int w, int h, const char* name){
  glutInit(0,0);//might need to pass a non-null pontier as first arg
  glutInitContextVersion(3,3);
  glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
  glutSetOption(GLUT_MULTISAMPLE, 4);//4xAA
  glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
                GLUT_ACTION_GLUTMAINLOOP_RETURNS);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA |
                      GLUT_DEPTH | GLUT_MULTISAMPLE);
  glutInitWindowSize(w,h);
  glutCreateWindow(name);
  atexit(glutExit);
  glutCloseFunc(glut_set_window_should_close);
}
Пример #23
0
void AssignFunctions(){
	glutReshapeFunc(ResizeFunction);
	glutDisplayFunc(RenderFunction);
	glutIdleFunc(IdleFunction);
	glutTimerFunc(0, TimerFunction, 0);
	glutKeyboardFunc(KeyboardFunction);
	glutSpecialFunc(SpecialKeyFunction);
	glutKeyboardUpFunc(KeyboardReleasedFunction);
	glutSpecialUpFunc(SpecialKeyReleasedFunction);
	glutMotionFunc(MouseMovementFunction);
	glutPassiveMotionFunc(MouseMovementFunction);
	glutMouseFunc(MouseClickedFunction);
	glutCloseFunc(Cleanup);
}
Пример #24
0
 void CView::InitializeCallbacks(void)
 {
   // register callbacks
   //glutIgnoreKeyRepeat(1);
   glutDisplayFunc(CGlutCallbacks::DisplayCallback);
   glutReshapeFunc(CGlutCallbacks::ReshapeCallback);
   glutKeyboardFunc(CGlutCallbacks::KeyboardPressedCallback);
   glutKeyboardUpFunc(CGlutCallbacks::KeyboardReleasedCallback);
   glutSpecialFunc(CGlutCallbacks::KeyboardPressedCallback);
   glutSpecialUpFunc(CGlutCallbacks::KeyboardReleasedCallback);
   glutMouseFunc(CGlutCallbacks::MouseKeyCallback);
   glutMotionFunc(CGlutCallbacks::MouseMoveCallback);
   glutPassiveMotionFunc(CGlutCallbacks::MousePassiveMoveCallback);
   glutCloseFunc(CGlutCallbacks::FinalizeCallback);
 }
Пример #25
0
void gemglutwindow :: destroyMess(void)
{
  if(makeCurrent()) {
    s_windowmap.erase(m_window);

    int window=m_window;
    m_window=0; // so that we no longer receive any event
    glutCloseFunc     (NULL);
    glutDestroyWindow(window);
    glutMainLoopEvent();
    glutMainLoopEvent();

  }
  destroy();
}
Пример #26
0
void gemglutwindow :: destroyMess(void)
{
  if(makeCurrent()) {
    int window=m_window;
    m_window=0; // so that we no longer receive any event
    glutCloseFunc     (NULL);
    glutDestroyWindow(window);
    glutMainLoopEvent();
    glutMainLoopEvent();

    /* now that the window is destroyed, remove it from the list of available windows */
    s_windowmap.erase(window);
  }
  destroy();
}
Пример #27
0
void initGL(int *argc, char **argv)
{
    // initialize GLUT callback functions
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(width, height);
    glutCreateWindow("CUDA bicubic texture filtering");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutReshapeFunc(reshape);
    glutTimerFunc(REFRESH_DELAY, timerEvent, 0);

#if defined (__APPLE__) || defined(MACOSX)
    atexit(cleanup);
#else
    glutCloseFunc(cleanup);
#endif

    initMenus();

    glewInit();

    if (!glewIsSupported("GL_VERSION_2_0 "
                         "GL_ARB_pixel_buffer_object "
                        ))
    {
        fprintf(stderr, "Required OpenGL extensions are missing.");
        exit(EXIT_FAILURE);
    }

#if USE_BUFFER_TEX

    if (!glewIsSupported("GL_EXT_texture_buffer_object"))
    {
        fprintf(stderr, "OpenGL extension: GL_EXT_texture_buffer_object missing.\n");
        exit(EXIT_FAILURE);
    }

    if (!glewIsSupported("GL_NV_gpu_program4"))
    {
        fprintf(stderr, "OpenGL extension: GL_NV_gpu_program4 missing.\n");
        exit(EXIT_FAILURE);
    }

#endif
}
Пример #28
0
int main(int argc, char ** argv)
{
	//init OpenGL context
	initGlut(argc, argv);
	initGlew();

	OnInit();
	glutCloseFunc(OnShutDown);
	glutDisplayFunc(OnRender);
	glutReshapeFunc(OnResize);
	glutMouseFunc(OnMouseDown);
	glutMotionFunc(OnMouseMove);
	glutKeyboardFunc(OnKeyDown);
	glutIdleFunc(OnIdle);
	glutMainLoop();
	return 0;
}
Пример #29
0
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;
}
Пример #30
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow("aGPhys - 5) (Einfache Stoffsimulation)");
    glutDisplayFunc(display);
    glutReshapeFunc(resize);
    glutIdleFunc(idle);
    glutKeyboardFunc(key);
    glutMouseFunc(mouseButton);
    glutMotionFunc(mouseMove);
    glutCloseFunc(shutdown);

	init();
    glutMainLoop();

	return 0;
}