bool initGL(int width, int height, bool fullscreen) { glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); int fs = fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW; if(!glfwOpenWindow( width, height, 8, 8, 8, 8, 32, 8, fs)) { printf("Could not create GLFW-window\n"); return false; } glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { printf("Could not init GLEW\n"); return false; } printf("Successfully created OpenGL-window, version %i.%i\n", glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR), glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR)); return true; }
/* GLFW test. Simple. */ TEST(GLFWTest, Simple) { try { if (!glfwInit()) { THROW_GL_EXCEPTION(GLException::RunTimeError, "glfwInit"); } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (!glfwOpenWindow(1280, 720, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfwTerminate(); THROW_GL_EXCEPTION(GLException::RunTimeError, "glfwOpenWindow"); } GLUtil::InitializeGlew(); GLUtil::EnableDebugOutput(); glfwTerminate(); } catch (const GLException& e) { FAIL() << GLTestUtil::PrintGLException(e); } }
bool __stdcall OGLStartup() { // Attempt to start up GLFW f1("Attempting to start up GLFW"); if(!glfwInit()) { e("Could not start up GLFW!"); SetVError(V_ERR_OGL_GLFWINIT); return false; } // Create window hints f1("Setting window hints"); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, V_OGL_ANTIALIAS); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want 4.0! glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Create the window f1("Creating main window"); if(!glfwOpenWindow(V_OGL_WINDOW_W, V_OGL_WINDOW_H, 0,0,0,0,0,0, V_OGL_WINMODE)) { e("Could not create main window!"); SetVError(V_ERR_OGL_WINDOW); glfwTerminate(); return false; } // Attempt to start up Glew f1("Attempting to startup Glew"); if(glewInit() != GLEW_OK) { // Error and return e("Could not instantiate Glew!"); SetVError(V_ERR_OGL_GLEWINIT); return false; } // Set the window's title f1("Setting window title"); glfwSetWindowTitle(V_WINDOW_TITLE); // Set key callback glfwSetKeyCallback( handle_key_down ); glfwEnable(GLFW_KEY_REPEAT); // Set swap interval glfwSwapInterval(1); // Clear the screen / set BG color f1("Clearing background"); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Lastly, setup basic sticky keys f1("Enabling sticky keys"); glfwEnable(GLFW_STICKY_KEYS); // All is good return true; }
// ---------------------------------------------- int main() { int width = 1024; int height = 768; glfwInit(); // set window properties glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // anti aliasing glfwOpenWindowHint(GLFW_REFRESH_RATE, 0); // 0 = system default // open the window. if(!glfwOpenWindow(width, height, 8, 8, 8, 8,32,8, GLFW_WINDOW)) { glfwTerminate(); exit(EXIT_FAILURE); } Simulation sim; sim.setup(); bool running = true; while(running) { sim.update(); sim.draw(); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(); running = !(glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED)); } glfwTerminate(); return 0; };
int Init() { if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); return -1; } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // I want OpenGL 3.1 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); // Open a window and create its OpenGL context if(glfwOpenWindow( 1024, 768, 0,0,0,0, 8,0, GLFW_WINDOW) != GL_TRUE ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); return -1; } // Initialize GLEW if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } glfwSetWindowTitle( "Triangle-Demo-1" ); return 0; }
int main(){ //Change this line to use your name! yourName = "Karl Li"; // Needed in OSX to force use of OpenGL3.2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); init(); initCuda(); CUT_CHECK_ERROR_GL(); initVAO(); initTextures(); GLuint passthroughProgram; passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl"); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); // send into GLFW main loop while(1){ display(); if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){ exit(0); } } glfwTerminate(); return 0; }
int initWindow(int width, int height, const std::string &title) { // init GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize FLGW\n"); return -1; } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialising glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // use OpenGL 3.3 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (!glfwOpenWindow(width, height, 0,0,0,0, 32,0, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window\n"); return -1; } // init GLEW glewExperimental = true; // needed in core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } glfwSetWindowTitle(title.c_str()); return 0; }
void InitGraphics() { // Initialise GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit(-1); } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) ) { fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" ); glfwTerminate(); exit(-1); } // Initialize GLEW if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); exit(-1); } std::cout << "Initialized GL Components.\n"; }
bool initWindow(int width, int height) { if (!glfwInit()) { std::cerr << "Couldn't init GLFW.\n"; return false; } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 5); //glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); if (!glfwOpenWindow(width, height, 8, 8, 8, 0, 0, 8, GLFW_WINDOW)) { std::cerr << "Couldn't open window.\n"; return false; } if (ogl_LoadFunctions() != ogl_LOAD_SUCCEEDED) { std::cerr << "Couldn't init OpenGL functions.\n"; return false; } if (ogl_IsVersionGEQ(1, 5)) { std::cerr << "OpenGL 1.5 not supported.\n"; return false; } glfwSwapInterval(1); glViewport(0, 0, width, height); return true; }
int main(int argc, char** argv) { glfwInit(); glfwOpenWindowHint(GLFW_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_VERSION_MINOR, 3); glfwOpenWindow(800, 600, 8,8,8,8, 24, 16, GLFW_WINDOW); glewInit(); sigurd::Engine engine; sigurd::data::Mesh m; sigurd::data::mesh::loadFromFile(m, "data/sphere.obj"); bool running = true; while(running) { glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); engine.frameStep(); glfwSwapBuffers(); running = glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC); } return 0; }
int main(){ int width, height; int frame = 0; bool running = true; glfwInit(); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); if(!glfwOpenWindow(512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)){ glfwTerminate(); return 0; } glfwSetWindowTitle("GLFW APPLICATION"); printf("RENDERER: %s\n", glGetString(GL_RENDER)); printf("GL_VERSION: %s\n", glGetString(GL_VERSION)); printf("GL_VERDOR: %s\n", glGetString(GL_VENDOR)); printf("GL_SHADING_VERSION: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); int m, n; glGetIntegerv(GL_MAJOR_VERSION, &m); glGetIntegerv(GL_MINOR_VERSION, &n); printf("GL_Major: %d\n", m); printf("GL_Minor: %d\n", n); printf("GL_Extensions: %s", glGetString(GL_EXTENSIONS)); glfwTerminate(); return 0; }
/////////////////////////////////////////////////////////////////////////////// // Main entry point for GLFW based programs int main( int argc , char * argv []) { // initialise GLFW if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); if(!glfwOpenWindow(800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if (GLEW_OK != glewInit()) throw std::runtime_error("glewInit failed"); // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); glfwSetWindowSizeCallback(ChangeSize); SetupRC(); while(glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey( GLFW_KEY_ESC )) { RenderScene(); glfwSwapBuffers(); } glfwTerminate(); }
void Window::ForceOpenGlVersion(int major, int minor) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); LeLog.WriteP("Window: Forced OpenGl version: (%i, %i)", major, minor); }
void AppMain() { if(!glfwInit()) throw std::runtime_error("glfwInit failed"); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE); if(!glfwOpenWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW)) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); glfwDisable(GLFW_MOUSE_CURSOR); glfwSetMousePos(0,0); glfwSetMouseWheel(0); LoadShaders(); LoadTriangle(); //intialise the Camera position gCamera.setPosition(glm::vec3(0,0,4)); gCamera.setViewportAspectRatio(SCREEN_SIZE.x / SCREEN_SIZE.y); gCamera.setNearAndFarPlanes(0.5, 100.0f); Axis = glm::vec3(0,1,0); //intialise the Light attribute gLight.position = glm::vec3(0.0f,0.1f,-0.1f); gLight.intensities = glm::vec3(0.8,0.78,1); // white light gLight.attenuation = 0.2f; gLight.ambientCoefficient = 0.005f; double lastTime = glfwGetTime(); while(glfwGetWindowParam(GLFW_OPENED)){ double thisTime = glfwGetTime(); Update(thisTime - lastTime); lastTime = thisTime; Render(); } glfwTerminate(); }
bool Game::init() { if (glfwInit() != GL_TRUE) return false; glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); this->window = glfwOpenWindow(this->width, this->height, 8, 8, 8, 0, 24, 0, GLFW_WINDOW); if (!this->window) return false; glfwSetWindowTitle("Battlecraft Editor"); glfwSwapInterval(1); // OpenGL Settings glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); srand(11247); this->camera = new Camera(width, height, 90); shader = new VoxelShader(); shader->compile(); tileset = new Tileset(256); tileset->set(1, 250,20,20); tileset->set(2, 20,250,20); tileset->set(3, 20,20,250); tileset->set(4, 255,0,255); chunk = new Chunk(tileset, 16,16,16); chunk->compute(); glErrorCheck("pre linesh compilation") linesh = new LineShader(); if (!linesh->compile()) return false; bounds = new Boundbox(16,16,16); printf("A: %d, a: %d\n", 'A','a'); return true; }
///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemglfw2window :: create(void) { int mode = GLFW_WINDOW; if(0!=s_window) { error("window already made!"); return false; } if(m_fullscreen) mode=GLFW_FULLSCREEN; glfwOpenWindowHint(GLFW_FSAA_SAMPLES, m_fsaa); if(m_profile_major) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, m_profile_major); // We want OpenGL 3.3 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, m_profile_minor); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL } if (!glfwOpenWindow(m_width, m_height, 8, 8, 8, 8, /* RGBA bits */ 24, 8, /* depth/stencil bits */ mode)) { error("glfw couldn't create window"); return false; } // FIXXME: single/double buffering if(!createGemWindow()) { destroyMess(); return false; } s_window=this; titleMess(m_title); offsetMess(m_xoffset, m_yoffset); cursorMess(m_cursor); glfwSetWindowSizeCallback (windowsizeCb); glfwSetWindowCloseCallback (windowcloseCb); glfwSetWindowRefreshCallback(windowrefreshCb); glfwSetKeyCallback (keyCb); glfwSetCharCallback (charCb); glfwSetMouseButtonCallback (mousebuttonCb); glfwSetMousePosCallback (mouseposCb); glfwSetMouseWheelCallback (mousewheelCb); dispatch(); return (0!=s_window); }
WindowImplGLFW::WindowImplGLFW(int width, int height) { glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, 1); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindow(width, height, 8, 8, 8, 8, 24, 0, GLFW_WINDOW); }
int main( void ) { if(!glfwInit()) { exit( EXIT_FAILURE ); } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 16); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if(!glfwOpenWindow(SCREEN_WIDTH, SCREEN_HEIGHT, 8,8,8,8,24,8, GLFW_WINDOW)) { glfwTerminate(); exit(EXIT_FAILURE); } printf("*** OpenGL %s | GLSL %s ***\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); glewExperimental = GL_TRUE; glewInit(); glGetError(); glfwSwapInterval(1); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glfwSetTime(0.0); glDisable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Setup(); int frames = 0; float elapsedTime = 0; do{ float time = (float) glfwGetTime(); Render(time); glfwSwapBuffers(); /* FPS Counter */ if((glfwGetTime()-elapsedTime) > 4.0){ int fps = (float) ceil(frames / (glfwGetTime()-elapsedTime)); printf("*** FPS: %d ***\n", fps); frames = 0; elapsedTime = time; } frames++; } while(!(glfwGetKey(GLFW_KEY_ESC) || glfwGetKey(81)) && glfwGetWindowParam(GLFW_OPENED)); glfwTerminate(); exit( EXIT_SUCCESS ); }
/* GLFW test. Simple 2. */ TEST(GLFWTest, Simple2) { try { if (!glfwInit()) { THROW_GL_EXCEPTION(GLException::RunTimeError, "glfwInit"); } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (!glfwOpenWindow(1280, 720, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfwTerminate(); THROW_GL_EXCEPTION(GLException::RunTimeError, "glfwOpenWindow"); } glfwSetWindowTitle("GLFWTest_Simple2"); GLUtil::InitializeGlew(); GLUtil::EnableDebugOutput(); int running = 1; double start = GLTestUtil::CurrentTimeMilli(); while (running) { double elapsed = GLTestUtil::CurrentTimeMilli() - start; if (elapsed >= 500.0) { break; } glClearColor((float)elapsed / 1000.0f, 1.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(); running = glfwGetWindowParam(GLFW_OPENED); } glfwTerminate(); } catch (const GLException& e) { FAIL() << GLTestUtil::PrintGLException(e); } }
void init( float normsize, bool fullscreen ) { static struct on { on() { glfwInit(); } ~on() { glfwTerminate(); } } _; auto rect = get_screen_rect(); screen_w = rect.first; screen_h = rect.second; { // reinit :P normsize = ( normsize <= 0 ? 1 : normsize ); w = screen_w * normsize; h = screen_h * normsize; } #if 0 //wglSwapIntervalEXT(1); glfwOpenWindowHint( GLFW_ACCUM_RED_BITS, 16 ); glfwOpenWindowHint( GLFW_ACCUM_GREEN_BITS, 16 ); glfwOpenWindowHint( GLFW_ACCUM_BLUE_BITS, 16 ); glfwOpenWindowHint( GLFW_ACCUM_ALPHA_BITS, 16 ); if( glfwOpenWindow( w, h, 0,0,0,0,0,0, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW ) != GL_TRUE ) { std::cerr << "<gate/gate.hpp> says: Cant create " << w << 'x' << h << " window!" << std::endl; exit(1); } #endif window = glfwCreateWindow(w, h, title.c_str(), NULL, NULL); if (!window) { glfwTerminate(); std::cerr << "<gate/gate.hpp> says: Cant create " << w << 'x' << h << " window!" << std::endl; exit(1); } glfwMakeContextCurrent(window); glfwSetWindowTitle( window, title.c_str() ); resize( w, h ); init_glew(); glInit(); }
// the program starts here void AppMain() { // initialise GLFW if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); if(!glfwOpenWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW)) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); // OpenGL settings glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // load vertex and fragment shaders into opengl LoadShaders(); // load the texture LoadTexture(); // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open while(glfwGetWindowParam(GLFW_OPENED)){ // draw one frame Render(); } // clean up and exit glfwTerminate(); }
GLFWApp::GLFWApp() { if (!glfwInit()) exit(EXIT_FAILURE); wndWidth = 800; midWidth = wndWidth/2; wndHeight = 600; midHeight = wndHeight/2; int redBits = 8, greenBits = 8, blueBits = 8; int alphaBits = 8, depthBits = 24, stencilBits = 8; glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (!glfwOpenWindow(wndWidth,wndHeight,redBits,greenBits,blueBits,alphaBits,depthBits,stencilBits,GLFW_WINDOW)) { glfwTerminate(); exit(EXIT_FAILURE); } GLenum err = glewInit(); if (GLEW_OK != err) { exit(EXIT_FAILURE); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); if (GLEW_VERSION_2_1) { fprintf(stdout, "OpenGL 2.1 is supported\n"); } if (GLEW_VERSION_3_3) { fprintf(stdout, "OpenGL 3.3 is supported\n"); } if (GLEW_VERSION_4_0||GLEW_VERSION_4_1) { fprintf(stdout, "OpenGL 4.0 is supported\n"); } glViewport(0, 0, wndWidth, wndHeight); glfwSetWindowTitle("RRC framework"); framesPerSec = 0; frameCnt = 0; startTime = glfwGetTime(); deltaTime = 0.001f; buffTime = 0.0f; isPinMouse = true; isRunning = true; }
bool setupGL() { glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ); if(!glfwOpenWindow( WIDTH, HEIGHT, 8, 8, 8, 8, 32, 0, GLFW_WINDOW)) { logError("could not create GLFW-window"); return false; } logErrorsGL(); glewExperimental = GL_TRUE; if (GLEW_OK != glewInit()) { logError("GLEW init error"); return false; } logErrorsGL(); logNote("Successfully created OpenGL-window, version %i.%i", glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR), glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR)); logNote("GLSL-version: %s",glGetString(GL_SHADING_LANGUAGE_VERSION)); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glfwSwapInterval(0); glActiveTexture(GL_TEXTURE0); glClearColor(1.0, 1.0, 1.0, 0.0); glfwDisable(GLFW_MOUSE_CURSOR); glfwSetKeyCallback(keyCallback); return true; }
GLFWWindow::GLFWWindow(OpenGLVersion desiredMinimumVersion, GLFWOpenGLProfile oglProfile): _isInitialized(false), _windowWidth(0), _windowHeight(0) { if(glfwInit()) { _isInitialized = true; //Specify that we want to support the desired minimum glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, desiredMinimumVersion.GetMajorVersion()); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, desiredMinimumVersion.GetMinorVersion()); //Opengl profile glfwOpenWindowHint( GLFW_OPENGL_PROFILE, oglProfile.GetProfile()); } }
int main(int argc, char** argv) { int running = GL_TRUE; if (!glfwInit()) { fprintf(stderr, "failed to initialize GLFW\n"); exit(EXIT_FAILURE); } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); if (!glfwOpenWindow(WIN_WIDTH, WIN_HEIGHT, 0,0,0,0,0,0, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); exit(EXIT_FAILURE); } glewExperimental = true; if (glewInit() != GLEW_OK) { return -1; } glfwSetWindowTitle("Hello, OpenGL"); if (argc != 2) { printf("Usage: shaderquad <fragment shader>\n"); exit(0); } setup(argv[1]); if (p == 0) running = GL_FALSE; while (running) { t += 0.01f; render(); glfwSwapBuffers(); running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); if (glfwGetKey(76)) { setup(argv[1]); } glfwSleep(.1); } glfwTerminate(); exit(EXIT_SUCCESS); }
void initGL(int w, int h) { if(glfwInit() == GL_FALSE) { std::cerr << "ERROR: Failed to initialize GLFW." << std::endl; exit(1); } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, CTX_VERSION_MAJOR); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, CTX_VERSION_MINOR); if(CTX_VERSION_MAJOR >= 3) { glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } if(glfwOpenWindow(WIDTH, HEIGHT, 0, 0, 0, 0, 8, 0, GLFW_WINDOW) == GL_FALSE) { std::cerr << "ERROR: Failed to open a GLFW window." << std::endl; exit(1); } glfwSetWindowTitle("Splines demo"); /*if(CTX_VERSION_MAJOR >= 3) { if(gl3wInit()) { std::cerr << "ERROR: " << gl3wGetError() << std::endl; exit(1); } if(!gl3wIsSupported(CTX_VERSION_MAJOR, CTX_VERSION_MINOR)) { std::cerr << "ERROR: OpenGL " << CTX_VERSION_MAJOR << "." << CTX_VERSION_MINOR << " is not supported." << std::endl; exit(1); } }*/ std::cout << "INFO: OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "INFO: OpenGL context renderer:" << glGetString(GL_RENDERER) << std::endl; std::cout << "INFO: OpenGL context vendor: " << glGetString(GL_VENDOR) << std::endl; if(CTX_VERSION_MAJOR >= 2) std::cout << "INFO: OpenGL shading language version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; glClearColor(1.0, 1.0, 1.0, 1.0); glViewport(0, 0, WIDTH, HEIGHT); glPointSize(4.0); glfwSetKeyCallback(cbKeyDown); glfwSetWindowSizeCallback(cbReshape); runlevel = 1; }
/////////////////////////////////////////////////////////////////////////////// // Main entry point for GLUT based programs int main(int argc, char* argv[]) { int running = GL_TRUE; // Initialize GLFW if( !glfwInit() ) { exit( EXIT_FAILURE ); } glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); // Open an OpenGL window if( !glfwOpenWindow( 800,600, 0,0,0,0,0,0, GLFW_WINDOW ) ) { glfwTerminate(); exit( EXIT_FAILURE ); } glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ GLenum err = glewInit(); if ( GLEW_OK != err) { fprintf(stderr , "GLEW Error: %s\n" , glewGetErrorString (err)); exit( EXIT_FAILURE ); } SetupRC(); glfwSetWindowSizeCallback(ChangeSize); // Main loop while( running ) { //// OpenGL rendering goes here... RenderScene(); glfwSwapBuffers(); // Check if ESC key was pressed or window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); } // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); }
int main(int argc, char** argv) { if(!glfwInit()) return -1; glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef DEBUG glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif if(!glfwOpenWindow(500, 500, 8, 8, 8, 8, 24, 8, GLFW_WINDOW)) { glfwTerminate(); return -1; } if(glload::LoadFunctions() == glload::LS_LOAD_FAILED) { glfwTerminate(); return -1; } glfwSetWindowTitle("GLFW Demo"); if(glext_ARB_debug_output) { glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(DebugFunc, (void*)15); } init(); glfwSetWindowSizeCallback(reshape); //Main loop while(true) { display(); if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED)) break; } glfwTerminate(); return 0; }
void GLManager::initGlWindow(){ cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() ); if( !glfwInit() ) { std::cerr << "Failed to initalize GLFW" << std::endl; exit( 1 ); } glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ); if ( !glfwOpenWindow( width, height, 8, 8, 8, 8, 8, 8, GLFW_WINDOW ) ) { std::cerr << "Failed to open window" << std::endl; exit( 1 ); } glewInit(); if (! glewIsSupported("GL_VERSION_2_0 ")) { std::cerr << "ERROR: Support for necessary OpenGL extensions missing." << std::endl; exit( 1 ); } glViewport(0, 0, height, width); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0); };
Init() { if(!glfwInit()) { std::cerr << "\nCould not initialize glfw!"; return; } glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, true); if(!glfwOpenWindow(screenSizeX, screenSizeY, 8, 8, 8, 8, 8, 8, GLFW_WINDOW)) { std::cerr << "\nCould not open the window!"; glfwTerminate(); return; } glfwSetWindowTitle("Colorful Game of Life"); glfwSetWindowPos(350, 150); glfwSwapInterval(0); glfwSetTime(0); if(gl3wInit() != 0) { std::cerr << "\nCould not initialize gl3w!"; glfwTerminate(); return; } }