Ejemplo n.º 1
0
int main(int argc, char** argv)
{
	glutInit(&argc, argv);

	int width = 500;
	int height = 500;
	unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
	displayMode = defaults(displayMode, width, height);

	glutInitDisplayMode (displayMode);
	glutInitContextVersion (3, 3);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);
#ifdef DEBUG
	glutInitContextFlags(GLUT_DEBUG);
#endif
	glutInitWindowSize (width, height); 
	glutInitWindowPosition (300, 200);
	int window = glutCreateWindow (argv[0]);

	glload::LoadFunctions();

	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

	if(!glload::IsVersionGEQ(3, 3))
	{
		printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
			glload::GetMajorVersion(), glload::GetMinorVersion());
		glutDestroyWindow(window);
		return 0;
	}

	if(glext_ARB_debug_output)
	{
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
		glDebugMessageCallbackARB(DebugFunc, (void*)15);
	}

	init();

	UserListener listener;
	Leap::Controller controller;
	controller.addListener(listener);

	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMainLoop();

	controller.removeListener(listener);

	return 0;
}
int main(int argc, char *argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);

    glutInitContextVersion(3, 3);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
    glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);

    glutCreateWindow("OpenGL basic");

    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (err != GLEW_OK) {
        std::cerr << "GLEW init error!";
        return -1;
    }

    glutReshapeFunc(reshape);
    glutDisplayFunc(draw);
    glutKeyboardFunc(keyboard);  

    initGL();

    glutMainLoop();
    return 0;
}
Ejemplo n.º 3
0
void 
DarkenManager::setupGL(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowPosition(20, 20);
    glutInitWindowSize(WINDOW_SIZE_WIDTH, WINDOW_SIZE_HEIGHT);
    glutInitContextVersion (3, 2); 
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG); 

    glutCreateWindow( argv[0] );

    glewInit();
    glewExperimental = GL_TRUE; // Required in openGL 3.1 forward compatible contexts because
    // GL_EXTENSIONS is deprecated argument for glGetString
    GLenum glewErr = glewInit();
    if(glewErr != GLEW_OK)
    {
        std::stringstream err;
        err << "Error initializing GLEW: " << glewGetErrorString(glewErr);
        throw std::runtime_error(err.str());
    }
    glGetError(); // glewInit finner ikke extension stringen
    // men setter funksjonspekere for core funksjoner

}
Ejemplo n.º 4
0
uint GraphicsCore::Initialize(int argc, char** argv)
{
	// initialise freeGLUT
	glutInit(&argc, argv);

	// create Window on O/S using freeGLUT
	glutInitWindowSize(windowWidth, windowHeight); // specify size of window
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

	// create window with freeGLUT
	int windowHandle = glutCreateWindow(windowTitle);
	if (windowHandle < 1) { printf("ERROR: creating window\n"); exit(1); }

	// get version info and print it to the console (have a look to see what version you can support)
	const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
	const GLubyte* vendor = glGetString(GL_VENDOR); // vendor
	const GLubyte* version = glGetString(GL_VERSION); // version as a string
	const GLubyte* glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); // glsl version string
	GLint major, minor;
	glGetIntegerv(GL_MAJOR_VERSION, &major); // get integer (only if gl version > 3)
	glGetIntegerv(GL_MINOR_VERSION, &minor); // get dot integer (only if gl version > 3)
	printf("OpenGL on %s %s\n", vendor, renderer);
	printf("OpenGL version supported %s\n", version);
	printf("GLSL version supported %s\n", glslVersion);
	printf("Will now set GL to version %i.%i\n", major, minor);
	
	// force GL to use a specific version
	glutInitContextVersion(major, minor); // set version of gl to 4.1
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); // do not allow deprecated
	glutInitContextProfile(GLUT_CORE_PROFILE); // force current version of spec
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	// start GLEW (that's it! - we could also use GLEW to check for driver support of all GL extensions)
	GLenum glErr = glGetError();
	while (glErr != GL_NO_ERROR) {
		printf("glError: %s\n", gluErrorString(glErr));
	}

	// set-up callbacks. we can also do a keyboard and mouse input callback, and various others (see freeGLUT website)
	//glutDisplayFunc(renderCallback); // register rendering callback
	glutReshapeFunc(resizeCallback); // register callback for reshape

	// set colour to clear screen buffer to
	glClearColor(0.1f, 0.1f, 0.1f, 1.0f);

	// enable some useful GL behaviours
	glEnable(GL_DEPTH_TEST); // enable depth-testing
	glDepthFunc(GL_LESS); // set depth-testing function type
	glEnable(GL_CULL_FACE); // enable culling of back-faces
	glCullFace(GL_BACK); // enable culling of back-faces
	glFrontFace(GL_CCW); // use clock-wise 'winding' to define order used to make fronts of polygons
	
	// start GLEW (that's it! - we could also use GLEW to check for driver support of all GL extensions)
	GLenum err = glewInit();
	if (GLEW_OK != err) {
		printf("ERROR starting GLEW: %s\n", glewGetErrorString(err));
	}

	return 1;
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitContextVersion(4, 0);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
		GLUT_ACTION_GLUTMAINLOOP_RETURNS);
	glutInitWindowSize(winw, winh);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	if (glutCreateWindow("Waiting for framerate data...") < 1) {
		fprintf(stderr, "ERROR: Could not create a window.\n");
		return EXIT_FAILURE;
	}
	GLenum result = glewInit();
	if (result != GLEW_OK) {
		fprintf(stderr, "ERROR: %s\n", glewGetErrorString(result));
		return EXIT_FAILURE;
	}
	createshaders();
	createvbo();
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutReshapeFunc(resize);
	glutTimerFunc(0, timer, 0);
	fprintf(stdout, "INFO: OpenGL Version: %s\n", glGetString(GL_VERSION));
	glutMainLoop();
	return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
int main(int argc, char** argv)
{
//	msgpr::initialize(print);
	glutInit(&argc, argv);
	glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
#ifdef  __APPLE__
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE);
	glutCreateWindow(argv[0]);
#else
	//glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
	glutInitContextVersion(3,3);
	glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);
	glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
	glutCreateWindow(argv[0]);
	if (glewInit()) {
		std::cerr << "Unable to initialize GLEW ... exiting" << std::endl;
		exit(EXIT_FAILURE);
	}
#endif
	init();
	glutDisplayFunc(display);
#ifdef __FREEGLUT_H__
	glutMouseWheelFunc(mouse_wheel);
#endif
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(special);
	glutTimerFunc(30, timer, 1);
	glutMainLoop();
}
int main(int argc, char **argv) {
  // Initialization of GLUT
  glutInit(&argc, argv);
  glutInitContextVersion(3, 1);
  glutInitContextFlags(GLUT_DEBUG);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  glutInitWindowSize(512, 512);
  glutCreateWindow( __FILE__ );

  // Init GLEW
  GLenum err = glewInit();
  if (GLEW_OK != err) {
    std::cerr << "Error: " << glewGetErrorString(err) << std::endl;
    return 1;
  } 

  if(!GLEW_VERSION_3_1) {
    std::cerr << "Driver does not support OpenGL 3.1" << std::endl;  
    return 1;
  }
  
  // Attach handlers
  glutDisplayFunc(myDisplay);
  glutReshapeFunc(myReshape);
  
  // A nasty trick to get a shutdown handler
  atexit(myShutdown);
  
  // Application specific initialization
  myInit();
  
  // Run the GLUT main loop
  glutMainLoop();
  return 0;
}
Ejemplo n.º 8
0
int main(int argc, char** argv) {
    glutInit(&argc, argv);

    glutInitContextVersion(3, 3);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(800, 600);
    glutInitWindowPosition(100, 100);
    glutCreateWindow(argv[0]);

    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutSpecialFunc(keybs);
    glutKeyboardFunc(keyPress);
    glutKeyboardUpFunc(keyRel);
    glutTimerFunc(50, animate, 0);
    glutMainLoop();

    delete [] Vertices;
    delete [] Colors;
    delete [] Indices;

    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char** argv)
{
   int menuA;
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   /* add command line argument "classic" for a pre-3.x context */
   if ((argc != 2) || (strcmp (argv[1], "classic") != 0)) {
      glutInitContextVersion (3, 1);
      glutInitContextFlags (GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
   }
   glutInitWindowSize (500, 500); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   dumpInfo ();
   init ();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape);
   glutKeyboardFunc (keyboard);

   /* Add a menu. They have their own context and should thus work with forward compatible main windows too. */
   menuA = glutCreateMenu(samplemenu);
   glutAddMenuEntry("Sub menu A1 (01)",1);
   glutAddMenuEntry("Sub menu A2 (02)",2);
   glutAddMenuEntry("Sub menu A3 (03)",3);
   glutSetMenu(menuA);
   glutAttachMenu(GLUT_RIGHT_BUTTON);

   glutMainLoop();
   return 0;
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
Application::Application(const std::string& title, int width, int height)
{
    static int argc = 1;
    static const char* argv[] = { "AVT" };
    glutInit(&argc, (char**)argv);

    glutInitContextVersion(3, 3);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    mMouseX = mMouseY = 0;
    mNow = mDelta = 0.0f;
    mLastTime = timestamp();
    mWindow = new Window(title, width, height);
    mRenderer = new Renderer;

    gCurrentInstance = this;
//	glutCloseFunc(cleanupCallBack);
    glutDisplayFunc(displayCallback);
    glutIdleFunc(idleCallback);
    glutMouseFunc(mouseCallback);
    glutMotionFunc(motionCallback);
    glutReshapeFunc(reshapeCallback);
    glutKeyboardFunc(keyboardCallback);
}
Ejemplo n.º 12
0
static int InitContextFlags(lua_State *L)
    {
    int i, n, rc;
    int opt, val, arg = 1;
    if(!lua_isnoneornil(L, 1)) /* set */
        {
        val = 0;
        while(!lua_isnoneornil(L, arg))
            { 
            opt = checkoption(L, arg, NULL, FlagsStrings);
            val |= FlagsCodes[opt];
            arg++;
            }
        glutInitContextFlags(val);
        }
    /* get */   
    n = sizeof(FlagsCodes)/sizeof(FlagsCodes[0]);
    rc = 0;
    val = glutGet(GLUT_INIT_FLAGS);
    for(i = 0; i <n; i ++)
        {
        if(val & FlagsCodes[i])
            { lua_pushstring(L, FlagsStrings[i]); rc++; }
        }
    return rc;
    }
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	/* add command line argument "classic" for a pre-3.x context */
	if ((argc != 2) || (strcmp(argv[1], "classic") != 0)) {
		glutInitContextVersion(3, 3);
		glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
	}
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	int windowID = glutCreateWindow("Stenciltest");
	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glutDestroyWindow(windowID);
		return 1;
	}

	init();
	readback_buffer();
	writeback_buffer();
	readback_buffer();
	glutDisplayFunc(draw);
	glutKeyboardFunc(keyboard);
	glutMainLoop();

	return 0;
}
//Initialization functions
void initWindow(int argc, _TCHAR* argv[], const BratsGLUtilities::WindowData& winData)
{
	//Initialize glut and pass "command-line" parameters to it.
	glutInit(&argc, (char**) argv);	//TODO: Find out the correct type of C++ 
									//cast to use
	//Initialize an OpenGL context.
	//Get an OpenGL 4.1 compatible context -
	glutInitContextVersion(4, 1);
#ifndef REQUEST_DEBUG_PROFILE
	//which is forward compatible (General) -
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
#else
	//which is forward compatible and a debug context (For debug builds) -
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
#endif
	//and is a core profile context without Fixed Function Pipeline stuff.
	glutInitContextProfile(GLUT_CORE_PROFILE);

	//Tell GLUT to return to the main program on window close.
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, 
		GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	//Initialize OpenGL for double buffering, RGBA colour and depth buffering.
	glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA  | GLUT_DOUBLE);

	//Initialize a GLUT window from the winData struct passed in.
	glutInitWindowSize(winData.width, winData.height);
	
	//Try creating a GLUT window.
	int windowHandle = glutCreateWindow(winData.windowTitle.c_str());
	//See if that worked
	//If window creation failed, report an error and exit with a fail status.
	if(windowHandle < 1)
	{
		std::cerr << "Failed to create rendering window." << std::endl;
		exit(EXIT_FAILURE);
	}

	//Register callbacks.
	glutDisplayFunc(draw);
	glutReshapeFunc(resize);

	//Initialize OpenGL state (and GLEW).
	initGL();
}
Ejemplo n.º 16
0
int main(int argc, char **argv) {

//  GLUT initialization
	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA|GLUT_MULTISAMPLE);

	glutInitContextVersion (4, 2);
	glutInitContextProfile (GLUT_CORE_PROFILE );
	glutInitContextFlags(GLUT_DEBUG);

	glutInitWindowPosition(100,100);
	glutInitWindowSize(640,360);
	glutCreateWindow("Lighthouse3D - Simplest Demo");

//  Callback Registration
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);


//	return from main loop
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

//	Init GLEW
	glewExperimental = GL_TRUE;
	glewInit();
	if (glewIsSupported("GL_VERSION_4_2"))
		printf("Ready for OpenGL 4.2\n");
	else {
		printf("OpenGL 4.2 not supported\n");
		exit(1);
	}

   printf ("Vendor: %s\n", glGetString (GL_VENDOR));
   printf ("Renderer: %s\n", glGetString (GL_RENDERER));
   printf ("Version: %s\n", glGetString (GL_VERSION));
   printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));
   int param;
   glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &param);
   if (param == GL_CONTEXT_CORE_PROFILE_BIT)
	   printf("Context Profile: Core\n");
   else
	   printf("Context Profile: Compatibility\n");
   glGetIntegerv(GL_CONTEXT_FLAGS, &param);

	setupShaders();
	initGL();

	//  GLUT main loop
	glutMainLoop();

	return(1);

}
Ejemplo n.º 17
0
void initGlut(int argc, char ** argv)
{
	glutInit(&argc, argv);	
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
	glutInitContextVersion(3, 3);
	glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
	glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
	glutInitWindowSize(WIDTH, HEIGHT);

	windowHandler = glutCreateWindow("Graphic Engine 0.001");
}
/*-----------------------------------------------------------------------------------------------
Description:
    Program start and end.
Parameters:
    argc    The number of strings in argv.
    argv    A pointer to an array of null-terminated, C-style strings.
Returns:
    0 if program ended well, which it always does or it crashes outright, so returning 0 is fine
Exception:  Safe
Creator:    John Cox (2-13-2016)
-----------------------------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);

    int width = 500;
    int height = 500;
    unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
    displayMode = Defaults(displayMode, width, height);

    glutInitDisplayMode(displayMode);
    glutInitContextVersion(4, 4);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    // enable this for automatic message reporting (see OpenGlErrorHandling.cpp)
#define DEBUG
#ifdef DEBUG
    glutInitContextFlags(GLUT_DEBUG);
#endif

    glutInitWindowSize(width, height);
    glutInitWindowPosition(300, 200);
    int window = glutCreateWindow(argv[0]);

    glload::LoadTest glLoadGood = glload::LoadFunctions();
    // ??check return value??

    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

    if (!glload::IsVersionGEQ(3, 3))
    {
        printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
            glload::GetMajorVersion(), glload::GetMinorVersion());
        glutDestroyWindow(window);
        return 0;
    }

    if (glext_ARB_debug_output)
    {
        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
        glDebugMessageCallbackARB(DebugFunc, (void*)15);
    }

    Init();

    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(Keyboard);
    glutMainLoop();

    CleanupAll();

    return 0;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
int main(int argc, char **argv) {

//  GLUT initialization
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA|GLUT_MULTISAMPLE);

	glutInitContextVersion (3, 3);
	glutInitContextProfile (GLUT_CORE_PROFILE );
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);

	glutInitWindowPosition(100,100);
	glutInitWindowSize(WinX, WinY);
	WindowHandle = glutCreateWindow(CAPTION);

//  Callback Registration
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(idle);

//	Mouse and Keyboard Callbacks
	glutKeyboardFunc(keyPressed);	//Funcao a ser chamada ao pressionar uma tecla 
	glutIgnoreKeyRepeat(1);		//Impedir que, ao pressionar uma tecla continuamente, seja chamada a funcao keyPressed repetidamente
	glutKeyboardUpFunc(keyReleased);	//Funcao a ser chamada ao libertar uma tecla
	glutMouseFunc(processMouseButtons);
	glutMotionFunc(processMouseMotion);
	glutMouseWheelFunc ( mouseWheel ) ;
	glutTimerFunc(0,timer,0);
	glutTimerFunc(0, refresh, 0);
	glutTimerFunc(0, iterate, 0);

//	return from main loop
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

//	Init GLEW
	glewExperimental = GL_TRUE;
	glewInit();

	printf ("Vendor: %s\n", glGetString (GL_VENDOR));
	printf ("Renderer: %s\n", glGetString (GL_RENDERER));
	printf ("Version: %s\n", glGetString (GL_VERSION));
	printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));

	if (!setupShaders()) return(1);

	init();

	//  GLUT main loop
	glutMainLoop();

	return(0);
}
Ejemplo n.º 21
0
/** main function */
int main(int argc, char* argv[])
{
	std::cout << "Starting ex0..." << std::endl;
	
	// Initialize GLUT
    glutInit(&argc, argv) ;
#ifdef __APPLE__
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE) ;
#else
	glutInitContextVersion(3, 3);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
	glutInitContextProfile(GLUT_CORE_PROFILE);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
#endif
    glutInitWindowSize(WINDOW_SIZE, WINDOW_SIZE);
    glutInitWindowPosition(WINDOW_POS_X, WINDOW_POS_Y);
    glutCreateWindow("CG Ex0");
	
	// Initialize GLEW
    glewExperimental = GL_TRUE;
    int glewStatus = glewInit();
    if (glewStatus != GLEW_OK) {
        std::cerr << "Unable to initialize GLEW ... exiting" << std::endl;
        exit(1);
    }
	
#ifdef __APPLE__
    GLint sync = 1;
    CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &sync);
#endif
		
	// Set callback functions:
    glutDisplayFunc(display) ;
    glutReshapeFunc(windowResize) ;
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutTimerFunc(100, timer, 0);   // uint millis int value
	
	// Init anything that can be done once and for all:
	_model.init();

	// Set clear color to black:
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	
	// Start events/drawing loop
	glutMainLoop();
	
	return 0;
}
Ejemplo n.º 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);
}
Ejemplo n.º 23
0
GLUTwrapper::GLUTwrapper ( EventHandlerBase *h )
{
  if (handler)
    {
      std::cerr << "Only one instance of the GLUTwrapper class allowed!" << std::endl;
      std::exit(1);
    }

  int a = h->getArgc();
  glutInit(&a,h->getArgv());
  glutInitContextVersion (3, 3);
  glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);

  glutInitWindowSize(h->getWindowWidth(),h->getWindowHeight());
  glutInitWindowPosition(10,10);
  glutInitDisplayMode(h->getWindowMode());
  windowID = glutCreateWindow("A window");

  glewExperimental=GL_TRUE;
  GLenum err=glewInit();
  if(err!=GLEW_OK)
  {
    //Problem: glewInit failed, something is seriously wrong.
    cout<<"glewInit failed, aborting."<<endl;
    exit(1);
  }
  //if (glewIsSupported("GL_VERSION_3_1"))
  //  cout << "Ready for OpenGL 3.1" << endl;
  //else
  //  {
  //    cerr << "OpenGL 3.1 not supported" << endl;
  //    exit(1);
  //  }

  handler = h;

  glutMouseFunc(mouseButton);
  glutMotionFunc(activeMotion);
  glutPassiveMotionFunc(passiveMotion);
  glutIdleFunc(idleFunction);
  glutDisplayFunc(draw);
  glutVisibilityFunc(visibilityFunction);
  glutSpecialFunc(specialFunction);
  glutEntryFunc(entryFunction);
  glutKeyboardFunc(keyPressed);
  glutReshapeFunc(resize);

  h->initializeGL();
}
Ejemplo n.º 24
0
// Make a window for doing OpenGL
void makeWindow(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitContextVersion(4, 2);
	#ifdef DEBUG
		glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
	#else
		glutInitContextFlags(GLUT_COMPATIBILITY_PROFILE);
	#endif

	// Open window / full screen
	#ifdef FULLSCREEN
		char modeString[255] = "";
		sprintf(modeString, "%dx%d:24", WINDOW_WIDTH, WINDOW_HEIGHT);
		glutGameModeString(modeString);
		glutEnterGameMode();
	#else
		glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
		glutCreateWindow(WINDOW_TITLE);
	#endif

	// Use GLEW, and make sure it imports EVERYTHING
	glewExperimental = GL_TRUE;
	glewInit();

	#ifdef DEBUG
		registerGlDebugLogger(GL_DEBUG_SEVERITY_MEDIUM);
	#endif

	// Set up OpenGL features
	glEnable(GL_DEPTH_TEST);
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
}
Ejemplo n.º 25
0
//Ruft alle FreeGLUT Funktionen um ein Window zu öffnen auf
void InitWindow(int argc, char* argv[])
{
    //Initialisiert die FreeGLUT lib (ist die erste FreeGLUT Funktion, die aufgerufen werden sollte)
    glutInit(&argc, argv);

    //*************Angabe des OpenGL Kontextes*************
    glutInitContextVersion(3, 3);//OpenGL Version 3.3
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);//Setzt die Kompatibilität so, dass es auch mit späteren OpenGL Versionen funktioniert
    glutInitContextProfile(GLUT_CORE_PROFILE);//nutzt OpenGL nur mit den neuesten Funktionen (compatibility mode = um ältere Versionen zu nutzen)
    //*****************************************************

    //GLUT_ACTION_ON_WINDOW_CLOSE und GLUT_ACTION_GLUTMAINLOOP_RETURNS bewirkt, dass die mainLoop Funktion das Programm nicht beendet sondern zum Programm zurückkehrt
    glutSetOption(
        GLUT_ACTION_ON_WINDOW_CLOSE,
        GLUT_ACTION_GLUTMAINLOOP_RETURNS
    );

    //setzt die Größe des render-Fensters
    glutInitWindowSize(CurrentWidth, CurrentHeight);

    //Displaymode gibt an, wie das Gerät die Szene rendern soll
    //GLUT_DEPTH = enthält die Tiefeninformation von Z für jeden Pixel (verhindert, dass neue Objekte nicht Objekte näher an der Kamera überlappen)
    //GLUT_DOUBLE = Flag um doppelbuffering zu aktivieren (reduziert flackern - 2 Buffer werden immer wieder Ausgewechselt - einer zum anzeigen, der andere zum rendern)
    //GLUT_RGBA = Flag um Farbkompositionen anzugeben (RGBA = Rot, Grün, Blau, Alpha)
    //es sind mehrere zusätzliche Optionen möglich
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    //erstellt ein Window und speichert das Handle dazu in WindowHandle (Parameter ist Window Title String)
    WindowHandle = glutCreateWindow("Test");

    //Handle checken, ob er kleiner als 1 ist, wenn ja wird Error geworfen und Programm beendet
    if(WindowHandle < 1)
    {
        fprintf(
            stderr,
            "ERROR: Could not create a new rendering window.\n"
        );
        glutExit();
    }

    //Glut function callbacks
    //TODO: add keyboard and mouse functions
    glutTimerFunc(0, TimerFunction, 0); //startet direkt die Funktion TimerFunction und übergibt 0 (damit der Titel am anfang nicht geändert wird)
    glutReshapeFunc(ResizeFunction); //wird jedes mal aufgerufen, wenn das Window verkleinert oder vergrößert wird
    glutDisplayFunc(RenderFunction); //wird jedes mal ausgeführt, wenn die szene auf den Bildschirm gezeichnet werden soll
    glutIdleFunc(IdleFunction); //macht die Idle Funktion bekannt
    glutKeyboardFunc(KeyEventProcessing);
}
Ejemplo n.º 26
0
int main (int argc, char **argv) {
    glutInit(&argc, argv);
    // Done TODO: activate stencil buffer //
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
    glutInitContextVersion(3,3);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    windowWidth = 512;
    windowHeight = 512;
    glutInitWindowSize(windowWidth, windowHeight);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Exercise 10 - Shadow Volumes");

    glutDisplayFunc(updateGL);
    glutIdleFunc(idle);
    glutKeyboardFunc(keyboardEvent);
    glutMouseFunc(mouseEvent);
    glutMotionFunc(mouseMoveEvent);

    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (GLEW_OK != err) {
        std::cout << "(glewInit) - Error: " << glewGetErrorString(err) << std::endl;
    }
    std::cout << "(glewInit) - Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;

    // init stuff //
    initGL();

    // init matrix stacks with identity //
    glm_ProjectionMatrix.push(glm::mat4(1));
    glm_ModelViewMatrix.push(glm::mat4(1));

    initShader();
    initScene();

    // start render loop //
    if (enableShader()) {
        glutMainLoop();
        disableShader();

        // clean up allocated data //
        deleteShader();
    }

    return 0;
}
Ejemplo n.º 27
0
int main(int argc, char* argv[]) {
    glutInit(&argc, argv);
    glutInitContextVersion(3, 0);
    glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
    glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA);
    glutInitWindowSize(windowWidth, windowHeight);
    glutCreateWindow("GPGPU 3. labor: glsl");

    init();

    glutDisplayFunc(draw);
    glutMouseFunc(mouse);
    glutMainLoop();

    return (0);
}
Ejemplo n.º 28
0
void setupGLUT(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(WinX, WinY);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    WindowHandle = glutCreateWindow(CAPTION);
    if(WindowHandle < 1) {
        std::cerr << "ERROR: Could not create a new rendering window." << std::endl;
        exit(EXIT_FAILURE);
    }
}
Ejemplo n.º 29
0
void init_graphics(int nargs, char** args, const char* title_bar, int x, int y)
{
/*KKCODEBLOCKSSUCKS*/#define SKMK_GLUT
#ifdef SKMK_GLUT
   glutInit(&nargs, args);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);
   //kk glutInitContextVersion(3, 3);
   glutInitContextVersion(3, 1);
   glutInitContextProfile(GLUT_CORE_PROFILE);
#ifdef SKMK_DEBUG
   glutInitContextFlags(GLUT_DEBUG);
#endif
   glutInitWindowSize(x, y);
   glutInitWindowPosition(300, 300);
   int window = glutCreateWindow(title_bar);

   ogl_load_funcs();
   glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

   skmk.ogl_state = malloc(sizeof(struct ogl_state));
   init_ogl(skmk.ogl_state); //!!

   glutDisplayFunc(ogl_draw);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);

   glutMainLoop();
#elif SKMK_SDL2
   //SDL_GLContext glcontext = SDL_GL_CreateContext(SDL_WINDOW);
   {
   SDL_Init(SDL_INIT_EVERYTHING); //TODO: Check errors
   K_SDL_WINDOW =
      SDL_CreateWindow(title_bar, 0, 0, x, y,
                       SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
   K_GL_CONTEXT = SDL_GL_CreateContext(K_SDL_WINDOW);
   ogl_init();
   }
#else
   #error You have to either use GLUT or SDL.
#endif
}
Ejemplo n.º 30
0
int main (int argc, char **argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitContextVersion(3,3);
  glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
  glutInitContextProfile(GLUT_CORE_PROFILE);

  glutInitWindowSize (512, 512);
  glutInitWindowPosition (100, 100);
  glutCreateWindow("Exercise 03 - More Bunnies!");

  glutDisplayFunc(updateGL);
  glutIdleFunc(idle);
  glutKeyboardFunc(keyboardEvent);

  glewExperimental = GL_TRUE;
  GLenum err = glewInit();
  if (GLEW_OK != err) {
    std::cout << "(glewInit) - Error: " << glewGetErrorString(err) << std::endl;
  }
  std::cout << "(glewInit) - Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;

  // init stuff //
  initGL();

  // init matrix stacks //
  glm_ProjectionMatrix.push(glm::mat4(2.414214, 0.000000, 0.000000, 0.000000, 0.000000, 2.414214, 0.000000, 0.000000, 0.000000, 0.000000, -1.002002, -1.000000, 0.000000, 0.000000, -0.020020, 0.000000));
  glm_ModelViewMatrix.push(glm::mat4(0.707107, -0.408248, 0.577350, 0.000000, 0.000000, 0.816497, 0.577350, 0.000000, -0.707107, -0.408248, 0.577350, 0.000000, 0.000000, 0.000000, -1.732051, 1.000000));

  initShader();
  initScene();

  // start render loop //
  if (enableShader()) {
    glutMainLoop();
    disableShader();

    // clean up allocated data //
    deleteScene();
    deleteShader();
  }

  return 0;
}