int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL); glutInitContextVersion (4, 0); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitWindowSize (800, 600); glutInitWindowPosition (300, 200); glutCreateWindow (argv[0]); glload::LoadFunctions(); initializeGL(); glutDisplayFunc(paintGL); glutReshapeFunc(resizeGL); glutMainLoop(); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( "Color Cube" ); glewExperimental = GL_TRUE; glewInit(); init(); glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); glutReshapeFunc( reshape ); glutMainLoop(); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA ); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( "Simple GLSL example" ); glewExperimental = GL_TRUE; glewInit(); init(); glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitContextVersion(3, 3); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow("GPGPU 3. labor: glsl"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(motion); glutMainLoop(); return (0); }
int main(int argc, char** argv) { /* Initialize GLUT; set double buffered window and RGBA color model */ glutInit(&argc, argv); // NEW re-able keyboard for camera modes /*Intel HD Fix*/ glutInitContextVersion(3, 3); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(750, 750); glutInitWindowPosition(200, 100); glutCreateWindow("CG Proseminar - Assignment 1"); /*Initialize GL extension wrangler - Intel HD Fix*/ glewExperimental = GL_TRUE; /* Initialize GL extension wrangler */ GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } /* Setup scene and rendering parameters */ Initialize(); /* Specify callback functions;enter GLUT event processing loop, * handing control over to GLUT */ glutIdleFunc(OnIdle); glutDisplayFunc(Display); glutKeyboardFunc(Keyboard); // NEW re-enable keyboard for camera modes glutMouseFunc(Mouse); glutMainLoop(); /* ISO C requires main to return int */ return 0; }
// Main routine. int main(int argc, char **argv) { glutInit(&argc, argv); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("experimentTriangles.cpp"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }
int main(int argc, char** argv) { char program_name[64] = "Wave Equation with C"; char messages[N_MESSAGE_LINES][256] = { " - Keys used: '0', '1', 't', 'f', 'ESC'" }; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInitWindowSize(800, 800); glutInitContextVersion(4, 2); glutInitContextProfile(GLUT_CORE_PROFILE); glutCreateWindow(program_name); greetings(program_name, messages, N_MESSAGE_LINES); initialize_glew(); initialize_renderer(); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); glutMainLoop(); return 0; }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(512, 512); #ifdef __APPLE__ glutInitDisplayMode(GLUT_RGBA | GLUT_3_2_CORE_PROFILE); glutCreateWindow(argv[0]); #else glutInitDisplayMode(GLUT_RGBA); 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); glutMainLoop(); }
int main(int argc, char **argv) { glutInit(&argc,argv); glutCreateWindow("Lab 1"); glutInitContextVersion(4,3); glutInitContextProfile(GLUT_CORE_PROFILE | GLUT_COMPATIBILITY_PROFILE); // TODO: Look this up glewInit(); init(); objects.push_back(triangle); objects.push_back(square); objects.push_back(hex); glutDisplayFunc(showStuff); glutMouseFunc(onMouse); glutMainLoop(); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( "Color Cube" ); glewInit(); init(); glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); glutMouseFunc( mouse ); glutIdleFunc( idle ); glutMainLoop(); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH ); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 2, 1 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( "Schwarz - lab4" ); glewInit(); init(); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( 512, 512 ); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow( "robot" ); glewExperimental = GL_TRUE; glewInit(); init(); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyboard ); glutMouseFunc( mouse ); glutCreateMenu( menu ); glutAddMenuEntry( "torso", Torso ); glutAddMenuEntry( "head1", Head1 ); glutAddMenuEntry( "head2", Head2 ); glutAddMenuEntry( "right_upper_arm", RightUpperArm ); glutAddMenuEntry( "right_lower_arm", RightLowerArm ); glutAddMenuEntry( "left_upper_arm", LeftUpperArm ); glutAddMenuEntry( "left_lower_arm", LeftLowerArm ); glutAddMenuEntry( "right_upper_leg", RightUpperLeg ); glutAddMenuEntry( "right_lower_leg", RightLowerLeg ); glutAddMenuEntry( "left_upper_leg", LeftUpperLeg ); glutAddMenuEntry( "left_lower_leg", LeftLowerLeg ); glutAddMenuEntry( "quit", Quit ); glutAttachMenu( GLUT_MIDDLE_BUTTON ); glutMainLoop(); return 0; }
//------------------------------------------------------------------------------ int main (int argc, char* argv[]) { cudaGLSetGLDevice(0); glutInit(&argc, argv); glutInitContextVersion(3, 3); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutCreateWindow(""); glewExperimental = TRUE; glewInit(); initGL(); initSim(); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(mouseMotion); glutKeyboardFunc(keyboard); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); glutMainLoop(); return 0; }
void InitWindow(int argc, char* argv[]) { glutInit(&argc, argv); #if defined(FREEGLUT) glutInitContextVersion(3, 3); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS ); #endif 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); #if defined(FREEGLUT) glutCloseFunc(Cleanup); #endif }
void freeglut::StartMainLoop() { running = true; if (MainLoopLock->TryLock() == wxMUTEX_NO_ERROR) { int tmpWindow = glutCreateWindow("GLEW init"); glutShowWindow(); initGlew(); std::cout << "OpenGL: " << glGetString(GL_VENDOR) << std::endl; std::cout << "OpenGL: " << glGetString(GL_RENDERER) << std::endl; std::cout << "OpenGL: " << glGetString(GL_VERSION) << std::endl; glutHideWindow(); glutDestroyWindow(tmpWindow); unsigned int displayMode = GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL; glutInitDisplayMode (displayMode); glutInitContextVersion (3, 0); glutInitContextProfile(GLUT_CORE_PROFILE); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); while (running) { glutMainLoopEvent(); QueueLock->Lock(); if (!callbackQueue.empty()) { callbackQueue.front()->callback(); callbackQueue.pop(); } QueueLock->Unlock(); } for (std::map<int,freeglutWindow*>::iterator it=windows.begin(); it!=windows.end(); ++it) { glutDestroyWindow(it->first); } windows.clear(); MainLoopLock->Unlock(); } }
// MAIN FUNCTION int main (int argc, char * argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(INITIAL_WIDTH,INITIAL_HEIGHT); glutInitContextVersion(3,3); glutInitContextProfile(GLUT_CORE_PROFILE); glutCreateWindow("Ruber System"); glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err != GLEW_OK) { 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)); } init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutTimerFunc(timerDelay, intervalTimer, 1); glutIdleFunc(display); glutMainLoop(); printf("Processing Finished.\n"); return 0; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); uint32_t displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL; // displayMode = defaults... glutInitDisplayMode( displayMode ); glutInitContextVersion( 3, 0 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutInitContextFlags( GLUT_DEBUG ); int width = 500, height = 500; glutInitWindowSize( width, height ); int window = glutCreateWindow( argv[0] ); glload::LoadFunctions(); glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ); if( !glload::IsVersionGEQ( 3, 0 ) ) { std::cout << "You have OpenGL " << glload::GetMajorVersion(); std::cout << "." << glload::GetMinorVersion() << " but this needs 3.0.\n"; glutDestroyWindow( window ); } if( glext_ARB_debug_output ) { glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB ); glDebugMessageCallbackARB( DebugFunc, (void*) 15 ); } init(); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 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; glutInitDisplayMode(displayMode); glutInitContextVersion (3, 3); glutInitContextProfile(GLUT_CORE_PROFILE); #ifdef DEBUG glutInitContextFlags(GLUT_DEBUG); #endif glutInitWindowSize (width, height); glutInitWindowPosition (300, 200); glutCreateWindow (argv[0]); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); glload::LoadFunctions(); if(glext_ARB_debug_output) { glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(DebugFunc, (void*)15); } init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
void GlutGlWindowImpl::init(WindowEventHandler* eventHandler, int width, int height, const std::string& caption, bool fullScreen) { GlutGlWindowImpl::eventHandler = eventHandler; int argc = 0; char* argv = nullptr; glutInit(&argc, &argv); glutInitContextVersion(openGlVersionMajor, openGlVersionMinor); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow((caption + "-GLUT").c_str()); if (fullScreen) { glutFullScreen(); } glutIdleFunc(GlutGlWindowImpl::onUpdate); glutDisplayFunc(GlutGlWindowImpl::onDraw); glutReshapeFunc(GlutGlWindowImpl::onResize); }
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.3 glutInitContextVersion (3, 3); // Контекст будет поддерживать отладку и "устаревшую" функциональность, которой, например, может пользоваться библиотека 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_3) { cerr << "OpenGL 3.3 not supported" << endl; return 1; } #ifdef USE_CORE_OPENGL glutDestroyWindow(window_handle); glutInitContextProfile(GLUT_CORE_PROFILE); window_handle = glutCreateWindow("OpenGL basic sample"); #endif // Трассировка ошибок по callback'у glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(gl_debug_proc, NULL); // выключить все трассировки glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE , GL_DONT_CARE, 0, NULL, false); // включить сообщения только об ошибках glDebugMessageControlARB(GL_DONT_CARE, GL_DEBUG_TYPE_ERROR_ARB, GL_DONT_CARE, 0, NULL, true ); // подписываемся на оконные события 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 { g_triangle.reset(new triangle_demo_t()); // Вход в главный цикл приложения glutMainLoop(); } catch( std::exception const & except ) { std::cout << except.what() << endl; return 1; } return 0; }
static void init_glut(void) { const struct piglit_gl_test_config *test_config = glut_fw.gl_fw.test_config; char *argv[] = {"piglit"}; int argc = 1; unsigned flags = GLUT_RGB; if (test_config->window_visual & PIGLIT_GL_VISUAL_RGBA) flags |= GLUT_ALPHA; if (test_config->window_visual & PIGLIT_GL_VISUAL_DEPTH) flags |= GLUT_DEPTH; if (test_config->window_visual & PIGLIT_GL_VISUAL_STENCIL) flags |= GLUT_STENCIL; if (test_config->window_visual & PIGLIT_GL_VISUAL_ACCUM) flags |= GLUT_ACCUM; if (test_config->window_visual & PIGLIT_GL_VISUAL_DOUBLE) flags |= GLUT_DOUBLE; else flags |= GLUT_SINGLE; /* * MacOSX GLUT. * * This will request a core profile. It will always return the highest * version supported. * * See: * /System/Library/Frameworks/GLUT.framework/Headers/glut.h * https://developer.apple.com/opengl/capabilities/ */ #if GLUT_MACOSX_IMPLEMENTATION >= 4 if (test_config->supports_gl_core_version >= 31) { flags |= GLUT_3_2_CORE_PROFILE; } #endif glutInit(&argc, argv); glutInitWindowPosition(0, 0); glutInitWindowSize(test_config->window_width, test_config->window_height); glutInitDisplayMode(flags); /* * FreeGLUT */ #ifdef PIGLIT_USE_GLUT_INIT_ERROR_FUNC glutInitErrorFunc(error_func); #else (void)error_func; #endif #ifdef GLUT_CORE_PROFILE if (test_config->supports_gl_core_version) { glutInitContextVersion(test_config->supports_gl_core_version / 10, test_config->supports_gl_core_version % 10); if (test_config->supports_gl_core_version >= 32) { glutInitContextProfile(GLUT_CORE_PROFILE); } } else { glutInitContextVersion(test_config->supports_gl_compat_version / 10, test_config->supports_gl_compat_version % 10); if (test_config->supports_gl_compat_version >= 32) { glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); } } int context_flags = 0; /* There are no 3.1 core profiles -- the closest is 3.1 context without * ARB_compatibility or a 3.2 core context --, and setting * forward-compatible flag should ensure we don't get a 3.1 context w/ * ARB_compatibility. */ if (test_config->require_forward_compatible_context || test_config->supports_gl_core_version == 31) { context_flags |= GLUT_FORWARD_COMPATIBLE; } if (test_config->require_debug_context) { context_flags |= GLUT_DEBUG; } if (context_flags) { glutInitContextFlags(context_flags); } #endif glut_fw.window = glutCreateWindow("Piglit"); glutDisplayFunc(display); glutReshapeFunc(default_reshape_func); glutKeyboardFunc(piglit_escape_exit_key); #ifdef PIGLIT_USE_OPENGL piglit_dispatch_default_init(PIGLIT_DISPATCH_GL); #endif }
GlutWindow::GlutWindow(const Parameters ¶ms) : Window(params) { int argc = 1; char *argv[1] = { (char*) "dummy" }; if (INSTANCES.size() == 0) { glutInit(&argc, argv); } glutInitDisplayMode(GLUT_DOUBLE | (params.alpha() ? GLUT_ALPHA : 0) | (params.depth() ? GLUT_DEPTH : 0) | (params.stencil() ? GLUT_STENCIL : 0) | (params.multiSample() ? GLUT_MULTISAMPLE : 0)); #ifdef USEFREEGLUT //Init OpenGL context glutInitContextVersion(params.major(), params.minor()); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | (params.debug() ? GLUT_DEBUG : 0)); #endif glutInitWindowSize(params.width(), params.height()); windowId = glutCreateWindow(params.name().c_str()); size = vec2i(params.width(), params.height()); damaged = false; timer.start(); t = 0.0; dt = 0.0; if (params.width() == 0 && params.height() == 0) { glutFullScreen(); } if (false) { glutCreateMenu(NULL);//do nothing, only used to avoid a warning } INSTANCES[windowId] = this; glutDisplayFunc(redisplayFunc); glutReshapeFunc(reshapeFunc); glutIdleFunc(idleFunc); glutMouseFunc(mouseClickFunc); glutMotionFunc(mouseMotionFunc); glutPassiveMotionFunc(mousePassiveMotionFunc); glutKeyboardFunc(keyboardFunc); glutKeyboardUpFunc(keyboardUpFunc); glutSpecialFunc(specialKeyFunc); glutSpecialUpFunc(specialKeyUpFunc); glutIgnoreKeyRepeat(1); // should be mouse enter/leave events, // but implemented in freeglut with get/loose focus glutEntryFunc(focusFunc); assert(glGetError() == 0); glewExperimental = GL_TRUE; glewInit(); glGetError(); #ifdef USEFREEGLUT if (params.debug()) { assert(glDebugMessageCallbackARB != NULL); glDebugMessageCallbackARB(debugCallback, NULL); } #endif }
/*----------------------------------------------------------------------------------------------- Description: Governs window creation, the initial OpenGL configuration (face culling, depth mask, even though this is a 2D demo and that stuff won't be of concern), the creation of geometry, and the creation of a texture. Parameters: argc (From main(...)) The number of char * items in argv. For glut's initialization. argv (From main(...)) A collection of argument strings. For glut's initialization. Returns: False if something went wrong during initialization, otherwise true; Exception: Safe Creator: John Cox (3-7-2016) -----------------------------------------------------------------------------------------------*/ bool init(int argc, char *argv[]) { glutInit(&argc, argv); // I don't know what this is doing, but it has been working, so I'll leave it be for now int windowWidth = 500; // square 500x500 pixels int windowHeight = 500; unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL; displayMode = defaults(displayMode, windowWidth, windowHeight); glutInitDisplayMode(displayMode); // create the window // ??does this have to be done AFTER glutInitDisplayMode(...)?? glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition(300, 200); // X = 0 is screen left, Y = 0 is screen top int window = glutCreateWindow(argv[0]); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); // OpenGL 4.3 was where internal debugging was enabled, freeing the user from having to call // glGetError() and analyzing it after every single OpenGL call, complete with surrounding it // with #ifdef DEBUG ... #endif blocks // Note: https://blog.nobel-joergensen.com/2013/02/17/debugging-opengl-part-2-using-gldebugmessagecallback/ int glMajorVersion = 4; int glMinorVersion = 4; glutInitContextVersion(glMajorVersion, glMinorVersion); glutInitContextProfile(GLUT_CORE_PROFILE); #ifdef DEBUG glutInitContextFlags(GLUT_DEBUG); // if enabled, #endif // glload must load AFTER glut loads the context glload::LoadTest glLoadGood = glload::LoadFunctions(); if (!glLoadGood) // apparently it has an overload for "bool type" { printf("glload::LoadFunctions() failed\n"); return false; } else if (!glload::IsVersionGEQ(glMajorVersion, glMinorVersion)) { // the "is version" check is an "is at least version" check printf("Your OpenGL version is %i, %i. You must have at least OpenGL %i.%i to run this tutorial.\n", glload::GetMajorVersion(), glload::GetMinorVersion(), glMajorVersion, glMinorVersion); glutDestroyWindow(window); return 0; } else if (glext_ARB_debug_output) { // condition will be true if GLUT_DEBUG is a context flag glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(DebugFunc, (void*)15); } // these OpenGL initializations are for 3D stuff, where depth matters and multiple shapes can // be "on top" of each other relative to the most distant thing rendered, and this barebones // code is only for 2D stuff, but initialize them anyway as good practice (??bad idea? only // use these once 3D becomes a thing??) glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); // FreeType needs to load itself into particular variables // Note: FT_Init_FreeType(...) returns something called an FT_Error, which VS can't find. // Based on the useage, it is assumed that 0 is returned if something went wrong, otherwise // non-zero is returned. That is the only explanation for this kind of condition. if (FT_Init_FreeType(&gFtLib)) { fprintf(stderr, "Could not init freetype library\n"); return false; } // Note: FT_New_Face(...) also returns an FT_Error. const char *fontFilePath = "FreeSans.ttf"; // file path relative to solution directory if (FT_New_Face(gFtLib, fontFilePath, 0, &gFtFace)) { fprintf(stderr, "Could not open font '%s'\n", fontFilePath); return false; } gProgramId = CreateProgram(); // pick out the attributes and uniforms used in the FreeType GPU program char textTextureName[] = "textureSamplerId"; gUniformTextSamplerLoc = glGetUniformLocation(gProgramId, textTextureName); if (gUniformTextSamplerLoc == -1) { fprintf(stderr, "Could not bind uniform '%s'\n", textTextureName); return false; } //char textColorName[] = "color"; char textColorName[] = "textureColor"; gUniformTextColorLoc = glGetUniformLocation(gProgramId, textColorName); if (gUniformTextColorLoc == -1) { fprintf(stderr, "Could not bind uniform '%s'\n", textColorName); return false; } // start up the font texture atlas now that the program is created and uniforms are recorded gAtlasPtr = new atlas(gFtFace, 48); // create the vertex buffer that will be used to create quads as a base for the FreeType // glyph textures glGenBuffers(1, &gVbo); if (gVbo == -1) { fprintf(stderr, "could not generate vertex buffer object\n"); return false; } // all went well return true; }
int main(int argc, char** argv) { /* set up our GLUT window */ glutInit(&argc, argv); glutInitWindowSize(512, 512); /* Ask GLUT to for a double buffered, full color window that * includes a depth buffer */ #ifdef __APPLE__ glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); #else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitContextVersion(3,2); glutInitContextProfile(GLUT_CORE_PROFILE); #endif glutCreateWindow(argv[0]); // set window title to executable name /* Initialize GLEW */ glewExperimental = GL_TRUE; GLenum glewError = glewInit(); if(glewError != GLEW_OK) { fprintf(stderr, "Error initializing GLEW: %s\n", glewGetErrorString(glewError)); exit(EXIT_FAILURE); } /* When experimental features are turned on in GLEW, the first * call to glGetError() or kuhl_errorcheck() may incorrectly * report an error. So, we call glGetError() to ensure that a * later call to glGetError() will only see correct errors. For * details, see: * http://www.opengl.org/wiki/OpenGL_Loading_Library */ glGetError(); // setup callbacks glutDisplayFunc(display); glutKeyboardFunc(keyboard); /* Compile and link a GLSL program composed of a vertex shader and * a fragment shader. */ program = kuhl_create_program("ogl3-triangle.vert", "ogl3-triangle.frag"); glUseProgram(program); kuhl_errorcheck(); /* Set the uniform variable in the shader that is named "red" to the value 1. */ glUniform1i(kuhl_get_uniform("red"), 1); kuhl_errorcheck(); /* Good practice: Unbind objects until we really need them. */ glUseProgram(0); /* Create kuhl_geometry structs for the objects that we want to * draw. */ init_geometryTriangle(&triangle, program); init_geometryQuad(&quad, program); dgr_init(); /* Initialize DGR based on environment variables. */ projmat_init(); /* Figure out which projection matrix we should use based on environment variables */ float initCamPos[3] = {0,0,10}; // location of camera float initCamLook[3] = {0,0,0}; // a point the camera is facing at float initCamUp[3] = {0,1,0}; // a vector indicating which direction is up viewmat_init(initCamPos, initCamLook, initCamUp); /* Tell GLUT to start running the main loop and to call display(), * keyboard(), etc callback methods as needed. */ glutMainLoop(); /* // An alternative approach: while(1) glutMainLoopEvent(); */ exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { #if defined(__APPLE__) glfwInit(); glfwEnable(GLFW_AUTO_POLL_EVENTS); /* No explicit call to glfwPollEvents() */ glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #if defined(NDEBUG) glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_FALSE); #else glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif GLboolean Result = glfwOpenWindow(512, 512, 0, 0, 0, 0, 16, 0, GLFW_WINDOW); assert(Result == GL_TRUE); glewExperimental = GL_TRUE; glewInit(); /* if(::LoadFunctions() == LS_LOAD_FAILED) { exit(1); } glTexImage3D = (PFNGLTEXIMAGE3DPROC)glfwGetProcAddress("glTexImage3D"); */ glfwSetWindowTitle("triangles"); // glfwSetMousePosCallback(cursor_position_callback); // glfwSetWindowCloseCallback(close_callback); // glfwSetKeyCallback(glfw_key); // glfwSetKeyCallback(special); // glfwSetCharCallback(keyboard); // glfwSetWindowSizeCallback(reshape); GLint MajorVersionContext = 0; GLint MinorVersionContext = 0; glGetIntegerv(GL_MAJOR_VERSION, &MajorVersionContext); glGetIntegerv(GL_MINOR_VERSION, &MinorVersionContext); printf("OpenGL version = %d.%d\n", MajorVersionContext, MinorVersionContext); init(); print_summary(); while(true) { if(terminating) break; display(); } glfwTerminate(); exit(EXIT_SUCCESS); return 0; #else glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(512, 512); glutInitContextVersion(4,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); } init(); glutDisplayFunc(display); glutMainLoop(); #endif }
int main(int argc, char** argv) { if(argc == 2) { modelFilename = argv[1]; modelTexturePath = NULL; } else if(argc == 3) { modelFilename = argv[1]; modelTexturePath = argv[2]; } else { printf("Usage:\n" "%s modelFile - Textures are assumed to be in the same directory as the model.\n" "- or -\n" "%s modelFile texturePath\n", argv[0], argv[0]); exit(1); } /* set up our GLUT window */ glutInit(&argc, argv); glutInitWindowSize(512, 512); /* Ask GLUT to for a double buffered, full color window that * includes a depth buffer */ #ifdef __APPLE__ glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); #else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInitContextVersion(3,2); glutInitContextProfile(GLUT_CORE_PROFILE); glutCreateWindow(argv[0]); // set window title to executable name #endif glEnable(GL_MULTISAMPLE); /* Initialize GLEW */ glewExperimental = GL_TRUE; GLenum glewError = glewInit(); if(glewError != GLEW_OK) { fprintf(stderr, "Error initializing GLEW: %s\n", glewGetErrorString(glewError)); exit(EXIT_FAILURE); } /* When experimental features are turned on in GLEW, the first * call to glGetError() or kuhl_errorcheck() may incorrectly * report an error. So, we call glGetError() to ensure that a * later call to glGetError() will only see correct errors. For * details, see: * http://www.opengl.org/wiki/OpenGL_Loading_Library */ glGetError(); // setup callbacks glutDisplayFunc(display); glutKeyboardFunc(keyboard); /* Compile and link a GLSL program composed of a vertex shader and * a fragment shader. */ program = kuhl_create_program(GLSL_VERT_FILE, GLSL_FRAG_FILE); dgr_init(); /* Initialize DGR based on environment variables. */ projmat_init(); /* Figure out which projection matrix we should use based on environment variables */ float initCamPos[3] = {0,0,2}; // location of camera float initCamLook[3] = {0,0,0}; // a point the camera is facing at float initCamUp[3] = {0,1,0}; // a vector indicating which direction is up viewmat_init(initCamPos, initCamLook, initCamUp); // Clear the screen while things might be loading glClearColor(.2,.2,.2,1); glClear(GL_COLOR_BUFFER_BIT); glutSwapBuffers(); /* Tell GLUT to start running the main loop and to call display(), * keyboard(), etc callback methods as needed. */ glutMainLoop(); /* // An alternative approach: while(1) glutMainLoopEvent(); */ exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { char *modelFilename = NULL; char *modelTexturePath = NULL; int currentArgIndex = 1; // skip program name int usageError = 0; while(argc > currentArgIndex) { if(strcmp(argv[currentArgIndex], "--fit") == 0) fitToView = 1; else if(strcmp(argv[currentArgIndex], "--origin") == 0) showOrigin = 1; else if(modelFilename == NULL) { modelFilename = argv[currentArgIndex]; modelTexturePath = NULL; } else if(modelTexturePath == NULL) modelTexturePath = argv[currentArgIndex]; else { usageError = 1; } currentArgIndex++; } // If we have no model to load or if there were too many arguments. if(modelFilename == NULL || usageError) { printf("Usage:\n" "%s [--fit] [--origin] modelFile - Textures are assumed to be in the same directory as the model.\n" "- or -\n" "%s [--fit] [--origin] modelFile texturePath\n" "If the optional --fit parameter is included, the model will be scaled and translated to fit within the approximate view of the camera\n" "If the optional --origin parameter is included, a box will is drawn at the origin and unit-length lines are drawn down each axis.\n", argv[0], argv[0]); exit(EXIT_FAILURE); } /* set up our GLUT window */ glutInit(&argc, argv); glutInitWindowSize(512, 512); glutSetOption(GLUT_MULTISAMPLE, 4); // set msaa samples; default to 4 /* Ask GLUT to for a double buffered, full color window that * includes a depth buffer */ #ifdef __APPLE__ glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); #else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInitContextVersion(3,2); glutInitContextProfile(GLUT_CORE_PROFILE); #endif glutCreateWindow(argv[0]); // set window title to executable name glEnable(GL_MULTISAMPLE); /* Initialize GLEW */ glewExperimental = GL_TRUE; GLenum glewError = glewInit(); if(glewError != GLEW_OK) { fprintf(stderr, "Error initializing GLEW: %s\n", glewGetErrorString(glewError)); exit(EXIT_FAILURE); } /* When experimental features are turned on in GLEW, the first * call to glGetError() or kuhl_errorcheck() may incorrectly * report an error. So, we call glGetError() to ensure that a * later call to glGetError() will only see correct errors. For * details, see: * http://www.opengl.org/wiki/OpenGL_Loading_Library */ glGetError(); // setup callbacks glutDisplayFunc(display); glutKeyboardFunc(keyboard); /* Compile and link a GLSL program composed of a vertex shader and * a fragment shader. */ program = kuhl_create_program(GLSL_VERT_FILE, GLSL_FRAG_FILE); dgr_init(); /* Initialize DGR based on environment variables. */ projmat_init(); /* Figure out which projection matrix we should use based on environment variables */ float initCamPos[3] = {0,1.55,2}; // 1.55m is a good approx eyeheight float initCamLook[3] = {0,0,0}; // a point the camera is facing at float initCamUp[3] = {0,1,0}; // a vector indicating which direction is up viewmat_init(initCamPos, initCamLook, initCamUp); // Clear the screen while things might be loading glClearColor(.2,.2,.2,1); glClear(GL_COLOR_BUFFER_BIT); // Load the model from the file modelgeom = kuhl_load_model(modelFilename, modelTexturePath, program, bbox); if(showOrigin) origingeom = kuhl_load_model("../models/origin/origin.obj", NULL, program, NULL); init_geometryQuad(&labelQuad, program); kuhl_getfps_init(&fps_state); /* Tell GLUT to start running the main loop and to call display(), * keyboard(), etc callback methods as needed. */ glutMainLoop(); /* // An alternative approach: while(1) glutMainLoopEvent(); */ exit(EXIT_SUCCESS); }
static int InitContext(lua_State *L) /* init_context([major, minor, context, debug]) * * type | profile | features * --------------------------------------------------------- * core full | core | current release * compatible full | compatible | all ever * forward compatible f.c. | core | non-deprecated */ { int major, minor, context, flags, profile; if(!lua_isnoneornil(L, 1)) /* set */ { major = luaL_checkinteger(L, 1); minor = luaL_checkinteger(L, 2); flags = profile = 0; context = ContextCodes[checkoption(L, 3, NULL, ContextStrings)]; switch(context) { case MOONGL_CORE: profile |= GLUT_CORE_PROFILE; break; case MOONGL_COMPATIBLE: profile |= GLUT_COMPATIBILITY_PROFILE; break; case MOONGL_FORWARD_COMPATIBLE: flags |= GLUT_FORWARD_COMPATIBLE; profile |= GLUT_CORE_PROFILE; break; default: return luaL_error(L, UNEXPECTED_ERROR); } if(lua_isboolean(L, 4)) { if(lua_toboolean(L, 4)) flags |= GLUT_DEBUG; } else if(!lua_isnoneornil(L, 4)) return luaL_argerror(L, 4, "boolean expected"); glutInitContextVersion(major, minor); glutInitContextFlags(flags); glutInitContextProfile(profile); } major = glutGet(GLUT_INIT_MAJOR_VERSION); minor = glutGet(GLUT_INIT_MINOR_VERSION); profile = glutGet(GLUT_INIT_PROFILE); flags = glutGet(GLUT_INIT_FLAGS); lua_pushinteger(L, major); lua_pushinteger(L, minor); if(profile & GLUT_CORE_PROFILE) { if(flags & GLUT_FORWARD_COMPATIBLE) lua_pushstring(L, "forward compatible"); else lua_pushstring(L, "core"); } else if(profile & GLUT_COMPATIBILITY_PROFILE) lua_pushstring(L, "compatible"); else lua_pushstring(L, "default"); lua_pushboolean(L, (flags & GLUT_DEBUG)); return 4; }
int main(int argn,char *args){ GLenum GlewInitResult; glutInit(&argn,args); glutInitContextVersion(4, 4); 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(releaseResources); glewExperimental = GL_TRUE; // make and test the initialization GlewInitResult = glewInit(); if(GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); exit(EXIT_FAILURE); } // Prints information about current machine fprintf(stdout,"INFO: OpenGL Version: %s\n\n",glGetString(GL_VERSION)); printf("INFO: Extensions:\n"); const GLubyte *array = glGetString(GL_EXTENSIONS); if(array==0)printf("NULL"); else printf("%s\n",array); // Initialize resources static const char *VS_CONSTANT[]={ "#version 440 core\n" "void main(void){" "const vec4 vertices[]=vec4[](vec4( 0.5,-0.4,-1.0,1.0)" ",vec4(-0.5,-0.4,-1.0,1.0)" ",vec4( 0.5, 0.4,1.0,1.0)" ",vec4(-0.5, 0.4,1.0,1.0));" "gl_Position=vertices[gl_VertexID];" "}" }; static const char *FS_CONSTANT[]={ "#version 440 core\n" "out vec4 color;" "void main(void){" "color = vec4(0.0,1.0,0.0,1.0);" "}" }; // Create the program constProgram = glCreateProgram(); GLint status; // Create fragment shader GLuint fs=glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fs,1,FS_CONSTANT,0); glCompileShader(fs); glGetShaderiv(fs,GL_COMPILE_STATUS,&status); if(status == GL_FALSE){ GLint length; glGetShaderiv(fs,GL_INFO_LOG_LENGTH,&length); GLchar *info = calloc(length,sizeof(GLchar)); glGetShaderInfoLog(fs,length,NULL,info); info[length-1]='\n'; (void)write(2,info,length); free(info); exit(20); } // Create constant shader GLuint vs=glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs,1,VS_CONSTANT,0); glCompileShader(vs); glGetShaderiv(vs,GL_COMPILE_STATUS,&status); if(status == GL_FALSE){ GLint length; glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &length); GLchar *info = calloc(length, sizeof(GLchar)); glGetShaderInfoLog(vs, length, NULL, info); info[length-1]='\n'; (void)write(2,info,length); free(info); exit(20); } // Link first program glAttachShader(constProgram,fs); glAttachShader(constProgram,vs); glLinkProgram(constProgram); glGetProgramiv(constProgram,GL_LINK_STATUS,&status); if(status==GL_FALSE){ GLint length; glGetShaderiv(vs,GL_INFO_LOG_LENGTH,&length); GLchar *info = calloc(length,sizeof(GLchar)); glGetShaderInfoLog(constProgram,length,NULL,info); (void)write(2,"glLinkProgram failed: \n",23); (void)write(2,info,length); free(info); exit(21); } // Programs are saved so delete shaders glDeleteShader(fs); glDeleteShader(vs); glGenVertexArrays(1,&vao); glBindVertexArray(vao); // Start the main loop glutMainLoop(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); return 0; }
/** * Main */ int main(int argc, char** argv) { // Print the keyboard commands printf("i - Reset to initial view\n"); printf("R - Roll 5 degrees clockwise r - Counter-clockwise\n"); printf("P - Pitch 5 degrees clockwise p - Counter-clockwise\n"); printf("H - Heading 5 degrees clockwise h - Counter-clockwise\n"); printf("X - Slide camera right x - Slide camera left\n"); printf("Y - Slide camera up y - Slide camera down\n"); printf("F - Move camera forward f - Move camera backwards\n"); printf("V - Faster mouse movement v - Slower mouse movement\n"); // Initialize free GLUT glutInit(&argc, argv); glutInitContextVersion(3, 2); //glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); // Using this causes LineWidth to error glutInitContextProfile(GLUT_CORE_PROFILE); // Set up depth buffer and double buffering glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInitWindowPosition(100, 100); glutInitWindowSize(640, 480); // Set callback methods glutCreateWindow("Phong Shading"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(mouseMotion); glutKeyboardFunc(keyboard); // Initialize Open 3.2 core profile if (gl3wInit()) { fprintf(stderr, "gl3wInit: failed to initialize OpenGL\n"); return -1; } if (!gl3wIsSupported(3, 2)) { fprintf(stderr, "OpenGL 3.2 not supported\n"); return -1; } printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); // Set the clear color to black glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Enable the depth buffer glEnable(GL_DEPTH_TEST); // Enable back face polygon removal glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); // Enable mutlisample anti-aliasing glEnable(GL_MULTISAMPLE); // Construct scene ConstructScene(); glutMainLoop(); return 0; }