예제 #1
0
void RenderWindow::setCallbacks() {

	glfwEnable(GLFW_STICKY_KEYS);
	//glfwDisable( GLFW_SYSTEM_KEYS );

	// glfw callbacks ///////////////////////////////////////////////////	
	glfwSetKeyCallback(keyCB);
	glfwSetCharCallback(charCB);
	glfwSetMousePosCallback(mousePosCB);
	glfwSetMouseButtonCallback(mouseButtonCB);
	glfwSetMouseWheelCallback(mouseWheelCB);

	glfwSetWindowSizeCallback(windowSizeCB);
}
예제 #2
0
void Application::Init()
{
	//Set the error callback
	glfwSetErrorCallback(error_callback);

	//Initialize GLFW
	if (!glfwInit())
	{
		exit(EXIT_FAILURE);
	}

	//Set the GLFW window creation hints - these are optional
	glfwWindowHint(GLFW_SAMPLES, 4); //Request 4x antialiasing
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //Request a specific OpenGL version
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //Request a specific OpenGL version
	//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL 


	//Create a window and create its OpenGL context
    //m_window = glfwCreateWindow(800, 600, "Computer Graphics", NULL, NULL);  //800 x 600
    m_window = glfwCreateWindow(1920, 1080, "Computer Graphics", glfwGetPrimaryMonitor(), NULL);

    glfwSetWindowSizeCallback(m_window, resize_callback);

	//If the window couldn't be created
	if (!m_window)
	{
		fprintf( stderr, "Failed to open GLFW window.\n" );
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	//This function makes the context of the specified window current on the calling thread. 
	glfwMakeContextCurrent(m_window);

	//Sets the key callback
	//glfwSetKeyCallback(m_window, key_callback);

	glewExperimental = true; // Needed for core profile
	//Initialize GLEW
	GLenum err = glewInit();

	//If GLEW hasn't initialized
	if (err != GLEW_OK) 
	{
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
		//return -1;
	}
}
예제 #3
0
int main(int argc, const char * argv[]) {
    
    ModelFactory modelFactory;
    teapot = modelFactory.BuildModel("teapot.obj");

    std::cout << teapot.m_Info.vertCount << std::endl;
    
    if (!glfwInit())
        exit(EXIT_FAILURE);
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_MAJOR);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_MINOR);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_SAMPLES, 8);
    
    GLFWwindow* window = glfwCreateWindow(WIN_WIDTH, WIN_HEIGHT, WIN_TITLE, NULL, NULL);
    
    gScreenWidth = WIN_WIDTH;
    gScreenHeight = WIN_HEIGHT;
    
    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    
    glInit();
    
    std::cout << glGetString(GL_RENDERER) << std::endl;
    std::cout << glGetString(GL_VERSION) << std::endl;
    
    glfwSetKeyCallback(window, KeyCallback);
    glfwSetWindowSizeCallback(window, ResizeCallback);
    
    while (!glfwWindowShouldClose(window)) {
        glLoop();
        glfwPollEvents();
        glfwSwapBuffers(window);
    }
    
    glShutdown();
    
    glfwDestroyWindow(window);
    
    glfwTerminate();
    return 0;
}
/*--------------------------------GLFW3 and GLEW------------------------------*/
bool start_gl () {
	gl_log ("starting GLFW %s\n", glfwGetVersionString ());
	
	glfwSetErrorCallback (glfw_error_callback);
	if (!glfwInit ()) {
		fprintf (stderr, "ERROR: could not start GLFW3\n");
		return false;
	}

	/* We must specify 3.2 core if on Apple OS X -- other O/S can specify
	 anything here. I defined 'APPLE' in the makefile for OS X */
#ifdef APPLE
	glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif

	glfwWindowHint (GLFW_SAMPLES, 4);
	
	/*GLFWmonitor* mon = glfwGetPrimaryMonitor ();
	const GLFWvidmode* vmode = glfwGetVideoMode (mon);
	g_window = glfwCreateWindow (
		vmode->width, vmode->height, "Extended GL Init", mon, NULL
	);*/

	g_window = glfwCreateWindow (
		g_gl_width, g_gl_height, "Extended Init.", NULL, NULL
	);
	if (!g_window) {
		fprintf (stderr, "ERROR: could not open window with GLFW3\n");
		glfwTerminate();
		return false;
	}
	glfwSetWindowSizeCallback (g_window, glfw_window_size_callback);
	glfwMakeContextCurrent (g_window);
	
	// start GLEW extension handler
	glewExperimental = GL_TRUE;
	glewInit ();

	// get version info
	const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
	const GLubyte* version = glGetString (GL_VERSION); // version as a string
	printf ("Renderer: %s\n", renderer);
	printf ("OpenGL version supported %s\n", version);
	gl_log ("renderer: %s\nversion: %s\n", renderer, version);
	
	return true;
}
예제 #5
0
파일: main.cpp 프로젝트: bhlzlx/graphics
int InitOpenGL()
{
    if (!glfwInit ())
    {
        fprintf (stderr, "ERROR: could not start GLFW3\n");
        return 1;
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

	mainWnd.window = glfwCreateWindow (DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "Graphics", NULL, NULL);

    if (!mainWnd.window)
    {
        fprintf (stderr, "ERROR: could not open window with GLFW3\n");
        glfwTerminate();
        return 1;
    }

    glfwSetWindowUserPointer(mainWnd.window,&mainWnd);
    glfwSetMouseButtonCallback(mainWnd.window, mouse_button_callback);
    glfwSetCursorPosCallback(mainWnd.window, cursor_position_callback);
    glfwSetWindowSizeCallback(mainWnd.window, window_size_callback);
    glfwSetKeyCallback(mainWnd.window,key_callback);

    glfwMakeContextCurrent (mainWnd.window);

    glewExperimental = GL_TRUE;
    glewInit ();

    if (glewIsSupported("GL_VERSION_4_1"))
    {
        printf("Ready for OpenGL 4.1\n");
    }
    else
    {
        printf("OpenGL 4.1 not supported\n");
        exit(1);
    }

    // get version info
    const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
    const GLubyte* version = glGetString (GL_VERSION); // version as a string
    printf ("Renderer: %s\n", renderer);
    printf ("OpenGL version supported %s\n", version);
    return 0;
}
예제 #6
0
	void Renderer::Init()
	{
		if (!glfwInit())
			return;

		//glfwSetErrorCallback(? ? ? );

		GLFWmonitor* monitor = 0;
		if (fullscreen)
			monitor = glfwGetPrimaryMonitor();

		window = glfwCreateWindow(wWidth, wHeight, "Lava Bulge", monitor, 0);
		glfwSetWindowSizeCallback(window, window_resize_callback);

		glfwMakeContextCurrent(window);

		glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
		glfwSwapInterval(0);

		//Контекст асинхронной загрузки
		glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
		loading_context = glfwCreateWindow(640, 480, "000", 0, window);
		//

		glewInit();

		glClearColor(0.3f, 0.3f, 0.3f, 1.0f);



		glEnable(GL_SCISSOR_TEST);

		glEnable(GL_CULL_FACE);
		//glDisable(GL_CULL_FACE);	//TODO: Убрать, куллинг контролируется материалом
		glFrontFace(GL_CCW);
		glCullFace(GL_BACK);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glPolygonMode(GL_FRONT, GL_FILL);

		glPointSize(3);

		//////////////////////////////////////////
		renderTarget = new RenderTarget();
		renderTarget->Resize(1280, 720);
	}
예제 #7
0
int main(void)
{
    setlocale(LC_ALL, "");

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW\n");
        exit(1);
    }

    printf("Library initialized\n");

    if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
    {
        glfwTerminate();

        fprintf(stderr, "Failed to create GLFW window");
        exit(1);
    }

    printf("Window opened\n");

    glfwSetWindowTitle("Event Linter");
    glfwSwapInterval(1);

    glfwSetWindowSizeCallback(window_size_callback);
    glfwSetWindowCloseCallback(window_close_callback);
    glfwSetWindowRefreshCallback(window_refresh_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetMousePosCallback(mouse_position_callback);
    glfwSetMouseWheelCallback(mouse_wheel_callback);
    glfwSetKeyCallback(key_callback);
    glfwSetCharCallback(char_callback);

    printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
    printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");

    printf("Main loop starting\n");

    while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
    {
        glfwWaitEvents();
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers();
    }

    glfwTerminate();
    exit(0);
}
예제 #8
0
/// EmuWindow_GLFW constructor
EmuWindow_GLFW::EmuWindow_GLFW() {
    keyboard_id = KeyMap::NewDeviceId();

    ReloadSetKeymaps();

    glfwSetErrorCallback([](int error, const char *desc){
        LOG_ERROR(Frontend, "GLFW 0x%08x: %s", error, desc);
    });

    // Initialize the window
    if(glfwInit() != GL_TRUE) {
        LOG_CRITICAL(Frontend, "Failed to initialize GLFW! Exiting...");
        exit(1);
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    // GLFW on OSX requires these window hints to be set to create a 3.2+ GL context.
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
    m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth,
        (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight),
        window_title.c_str(), nullptr, nullptr);

    if (m_render_window == nullptr) {
        LOG_CRITICAL(Frontend, "Failed to create GLFW window! Exiting...");
        exit(1);
    }

    glfwSetWindowUserPointer(m_render_window, this);

    // Notify base interface about window state
    int width, height;
    glfwGetFramebufferSize(m_render_window, &width, &height);
    OnFramebufferResizeEvent(m_render_window, width, height);

    glfwGetWindowSize(m_render_window, &width, &height);
    OnClientAreaResizeEvent(m_render_window, width, height);

    // Setup callbacks
    glfwSetKeyCallback(m_render_window, OnKeyEvent);
    glfwSetMouseButtonCallback(m_render_window, OnMouseButtonEvent);
    glfwSetCursorPosCallback(m_render_window, OnCursorPosEvent);
    glfwSetFramebufferSizeCallback(m_render_window, OnFramebufferResizeEvent);
    glfwSetWindowSizeCallback(m_render_window, OnClientAreaResizeEvent);

    DoneCurrent();
}
예제 #9
0
파일: accuracy.c 프로젝트: eledot/Plum
int main(void)
{
    GLFWwindow window;
    int width, height;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSetCursorPosCallback(window, cursor_position_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetKeyCallback(window, key_callback);

    glfwMakeContextCurrent(window);

    glfwGetWindowSize(window, &width, &height);
    window_size_callback(window, width, height);

    set_swap_interval(window, swap_interval);

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_LINES);
        glVertex2f(0.f, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) cursor_x, 0.f);
        glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
        glEnd();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
예제 #10
0
void veViewerDesktop::destroy()
{
    if (!_hwnd) return;
    glfwSetKeyCallback(_hwnd, nullptr);
    glfwSetCharCallback(_hwnd, nullptr);
    glfwSetMouseButtonCallback(_hwnd, nullptr);
    glfwSetCursorPosCallback(_hwnd, nullptr);
    glfwSetScrollCallback(_hwnd, nullptr);
    glfwSetWindowSizeCallback(_hwnd, nullptr);
    glfwSetWindowFocusCallback(_hwnd, nullptr);
    glfwSetWindowCloseCallback(_hwnd, nullptr);
    
    glfwDestroyWindow(_hwnd);
    _hwnd = nullptr;
}
예제 #11
0
파일: glfw.cpp 프로젝트: hglm/sre
void sreBackendGLFW::Initialize(int *argc, char ***argv, int requested_width, int requested_height,
int& actual_width, int& actual_height, unsigned int backend_flags) {
    glfwInit();
    // Require OpenGL >= 3.0.
//    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
//    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);
    // Because we use glBindAttribute for compability with OpenGL ES 2.0, we do not have forward compability.
//    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    if (backend_flags & SRE_BACKEND_INIT_FLAG_MULTI_SAMPLE)
        // Enable multi-sample anti-aliasing
        glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    int r;
    if (backend_flags & SRE_BACKEND_INIT_FLAG_STENCIL_BUFFER)
        r = glfwOpenWindow(requested_width, requested_height, 8, 8, 8, 8, 24, 8, GLFW_WINDOW);
    else
        r = glfwOpenWindow(requested_width, requested_height, 8, 8, 8, 8, 24, 0, GLFW_WINDOW);
    if (!r) {
        printf("Failed to open GLFW window.\n");
        glfwTerminate();
        exit(1);
    }
    glfwGetWindowSize(&actual_width, &actual_height);
    glfwSetWindowTitle("SRE demo -- OpenGL rendering demo using GLFW");
    int stencil_bits = glfwGetWindowParam(GLFW_STENCIL_BITS);
    int depth_bits = glfwGetWindowParam(GLFW_DEPTH_BITS);
    printf("Opened GLFW context of size %d x %d with 32-bit pixels, %d-bit depthbuffer and %d-bit stencil.\n",
        actual_width, actual_height, depth_bits, stencil_bits);
    glfwSetWindowSizeCallback(WindowResizeCallback);
    glfwSetKeyCallback(KeyCallback);
    glfwSetMousePosCallback(MousePosCallback);
    glfwSetMouseButtonCallback(MouseButtonCallback);
    // Don't poll events during glfwSwapBuffers but require explicit calls to glfwPollEvents().
    glfwDisable(GLFW_AUTO_POLL_EVENTS);
    // Generate multiple keypress events when a key is held down.
//    glfwEnable(GLFW_KEY_REPEAT);
//    if (fullscreen_mode)
//        glfwSetMousePos(window_width / 2, window_height / 2);

    GLenum err = glewInit();
    if (GLEW_OK != err) {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
        exit(1);
    }
    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

    initialized = true;
}
예제 #12
0
///////////////////////////////////////////////////////////////////////////////
// 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 );
}
예제 #13
0
파일: main.cpp 프로젝트: schardong/Splines
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;
}
예제 #14
0
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;
}
예제 #15
0
bool GLFWManager::initialize(int width, int height, std::string strTitle,
		bool bFullScreen) {
	if (!glfwInit()) {
		std::cerr << "Failed to initialize GLFW" << std::endl;
		return false;
	}

	this->screenWidth = width;
	this->screenHeight = height;

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	if (bFullScreen)
		window = glfwCreateWindow(width, height, strTitle.c_str(),
				glfwGetPrimaryMonitor(), nullptr);
	else
		window = glfwCreateWindow(width, height, strTitle.c_str(), nullptr,
				nullptr);

	if (window == nullptr) {
		std::cerr
				<< "Error to create GLFW window, you can try download the last version of your video card that support OpenGL 3.3+"
				<< std::endl;
		destroy();
		return false;
	}

	glfwMakeContextCurrent(window);
	glfwSwapInterval(0);

	glfwSetWindowSizeCallback(window, reshapeCallback);
	glfwSetKeyCallback(window, keyCallback);
	glfwSetCursorPosCallback(window, mouseCallback);
	glfwSetMouseButtonCallback(window, mouseButtonCallback);
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

	// Init glew
	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if (GLEW_OK != err) {
		std::cerr << "Failed to initialize glew" << std::endl;
		return false;
	}

	return true;
}
예제 #16
0
void InputManager::RemoveGlfwCallbacks()
{
	glfwSetWindowSizeCallback(nullptr);

	glfwSetKeyCallback(nullptr);
	glfwSetCharCallback(nullptr);
	glfwSetMouseButtonCallback(nullptr);
	glfwSetMousePosCallback(nullptr);
	glfwSetMouseWheelCallback(nullptr);
#ifdef _GLFW_DMITRI_WINDOWS_TOUCH_ENABLED
	glfwSetTouchCallback(nullptr);
#endif // _GLFW_DMITRI_WINDOWS_TOUCH_ENABLED

	m_TypingPointer.reset();
	m_MousePointer.reset();
}
예제 #17
0
void InputManager::SetGlfwCallbacks()
{
	m_TypingPointer = std::unique_ptr<TypingPointer>(new TypingPointer(*m_InputHandler));
	m_MousePointer = std::unique_ptr<MousePointer>(new MousePointer(*m_InputHandler));

	glfwSetWindowSizeCallback(&InputManager::ProcessWindowSize);

	glfwSetKeyCallback(&InputManager::ProcessKey);
	glfwSetCharCallback(&InputManager::ProcessChar);
	glfwSetMouseButtonCallback(&InputManager::ProcessMouseButton);
	glfwSetMousePosCallback(&InputManager::ProcessMousePos);
	glfwSetMouseWheelCallback(&InputManager::ProcessMouseWheel);
#ifdef _GLFW_DMITRI_WINDOWS_TOUCH_ENABLED
	glfwSetTouchCallback(&InputManager::ProcessTouch);
#endif // _GLFW_DMITRI_WINDOWS_TOUCH_ENABLED
}
예제 #18
0
파일: Setup.cpp 프로젝트: 435886030/NEWorld
void createWindow() {
	glfwSetErrorCallback([](int, const char* desc) { cout << desc << endl; });
	std::stringstream title;
	title << "NEWorld " << MAJOR_VERSION << MINOR_VERSION << EXT_VERSION;
	if (Multisample != 0) glfwWindowHint(GLFW_SAMPLES, Multisample);
	MainWindow = glfwCreateWindow(windowwidth, windowheight, title.str().c_str(), NULL, NULL);
	MouseCursor = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
	glfwMakeContextCurrent(MainWindow);
	glfwSetCursor(MainWindow, MouseCursor);
	glfwSetInputMode(MainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
	glfwSetWindowSizeCallback(MainWindow, &WindowSizeFunc);
	glfwSetMouseButtonCallback(MainWindow, &MouseButtonFunc);
	glfwSetScrollCallback(MainWindow, &MouseScrollFunc);
	glfwSetCharCallback(MainWindow, &CharInputFunc);
	if (ppistretch) GUI::InitStretch();
}
예제 #19
0
파일: main.c 프로젝트: st3w4r/42-arkanoid
static GLFWwindow	*ark_create_window(void)
{
	GLFWwindow	*window;

	window = glfwCreateWindow(WIN_W, WIN_H, "Arkanoid", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	glfwMakeContextCurrent(window);
	glfwSwapInterval(1);
	glfwSetKeyCallback(window, key_callback);
	glfwSetWindowSizeCallback(window, window_size_callback);
	return (window);
}
예제 #20
0
bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
{
    setViewName(viewName);

    _frameZoomFactor = frameZoomFactor;

    glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);

    _mainWindow = glfwCreateWindow(rect.size.width * _frameZoomFactor,
                                   rect.size.height * _frameZoomFactor,
                                   _viewName.c_str(),
                                   _monitor,
                                   nullptr);
    glfwMakeContextCurrent(_mainWindow);

    glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack);
    glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack);
    glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback);
    glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
    glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
    glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
    glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWframebuffersize);
    glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback);
    glfwSetDropCallback(_mainWindow, GLFWEventHandler::onGLFWDropCallback);
    
    setFrameSize(rect.size.width, rect.size.height);

    // check OpenGL version at first
    const GLubyte* glVersion = glGetString(GL_VERSION);

    if ( atof((const char*)glVersion) < 1.5 )
    {
        char strComplain[256] = {0};
        sprintf(strComplain,
                "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
                glVersion);
        MessageBox(strComplain, "OpenGL version too old");
        return false;
    }

    initGlew();

    // Enable point size by default.
    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

    return true;
}
예제 #21
0
GameEngine::GameEngine(int width, int height)
{

	_physicsEngine = NULL;
	_renderer = NULL;
	_paused = false;
	_scene = NULL;
	_timeBetweenUpdates = 1.0/300.0;

	if(!glfwInit())
	{
		std::cerr << "Failed to initialize glfw" << std::endl;
	}
	std::cout << "GLFW initialized" << std::endl;
	_window = glfwCreateWindow(width, height, "Game", NULL, NULL);
	if(!_window)
	{
		std::cerr << "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." << std::endl;
	}

	_renderer = new Renderer(_window);
	Control::setGameEngine(this);
	glfwSetInputMode(_window, GLFW_STICKY_KEYS, GLFW_KEY_ESCAPE);
	glfwSetWindowSizeCallback(_window, Control::windowResized);
	glfwSetKeyCallback(_window, Control::keyCallBack);
	glfwSetCursorPosCallback(_window, Control::mousePosCallback);
	glfwSetScrollCallback(_window, Control::mouseScrollCallback);
	glfwSetMouseButtonCallback(_window, Control::mouseClickCallback);
	glfwSwapInterval(0);

	this->_physicsEngine = new PhysicsEngine();
	
	std::cout << "Loading scene->.." << std::endl;
	_scene = XmlLoader::loadScene("scenes/cornellBoxTarea2c.xml");
	_scene->setShaderId(_renderer->getProgramId());
	_scene->initModelData();
	_scene->setMaterials();
	_scene->generateIds();
	//_scene->generateLineIds();
	_renderer->setRenderingParams();	

	setObjects(_scene->_models);

	_numUpdates = 0;
	_lastUpdate = glfwGetTime();
	_lastCheck = _lastUpdate;
}
예제 #22
0
bool Application::create(const char* a_name, int a_width, int a_height, int a_argc, char* a_argv[])
{
	// initialise glfw systems
	if (glfwInit() != GL_TRUE)
		return false;
    
#ifdef __APPLE__
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
    
	// create a windowed mode window and its OpenGL context
	m_window = glfwCreateWindow(a_width, a_height, a_name, nullptr, nullptr);
	if (m_window == nullptr)
	{
		glfwTerminate();
		return false;
	}
    
    auto major = glfwGetWindowAttrib(m_window, GLFW_CONTEXT_VERSION_MAJOR);
    auto minor = glfwGetWindowAttrib(m_window, GLFW_CONTEXT_VERSION_MINOR);
    auto revision = glfwGetWindowAttrib(m_window, GLFW_CONTEXT_REVISION);
    printf("GL %i.%i.%i\n",major,minor,revision);

	// make the window's context current
	glfwMakeContextCurrent(m_window);

	// initialise glew systems to wrangle GL extensions
    glewExperimental = GL_TRUE;
	if (glewInit() != GLEW_OK)
	{
		glfwTerminate();
		return false;
	}
	
	// simply resize the GL viewport when the window size changes
	glfwSetWindowSizeCallback(m_window, [](GLFWwindow*, int w, int h){ glViewport(0,0,w,h); });

	bool result = onCreate(a_argc,a_argv);
	if (result == false)
	{
		glfwTerminate();
	}
	return result;
}
예제 #23
0
/**
 * Initializes GLFW (window & callbacks), GLEW (extensions), and some OpenGL
 * features.
 */
void initLibraries() {
    // GLFW
    glfwSetErrorCallback(errorCallback);
    
    if (!glfwInit()) {
        std::cerr << "Failed to initialize GLFW" << std::endl;
        exit(EXIT_FAILURE);
    }
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    //glfwWindowHint(GLFW_SAMPLES, 2);
    
    window = glfwCreateWindow(
        WIDTH, HEIGHT, "IT5102E project - Forest", nullptr, nullptr
    );
    if (!window) {
        std::cerr << "Failed to open GLFW window" << std::endl;
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    
    glfwSetKeyCallback(window, Inputs::instance().keyCallback);
    glfwSetMouseButtonCallback(window, Inputs::instance().mouseButtonCallback);
    glfwSetCursorPosCallback(window, Inputs::instance().cursorPositionCallback);
    glfwSetScrollCallback(window, Inputs::instance().scrollCallback);
    glfwSetWindowSizeCallback(window, Inputs::instance().windowSizeCallback);
    
    // GLEW
    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK) {
        std::cerr << "Failed to initialize GLEW" << std::endl;
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    
    // OpenGL
    glViewport(0, 0, WIDTH, HEIGHT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    //glEnable(GL_MULTISAMPLE);
}
예제 #24
0
파일: main.cpp 프로젝트: sliz1/ubw
int main(int argc, char *argv[]) {
  glfwSetErrorCallback(GLFWErrorCallback);
  if (!glfwInit()) {
    kLogger.Log("ERROR: Cannot init GLFW3");
    exit(EXIT_FAILURE);
  }

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

  auto window = glfwCreateWindow(kWindowSize.x, kWindowSize.y,
                                 kWindowTitle.c_str(), nullptr, nullptr);
  if (!window) {
    kLogger.Log("ERROR: Cannot create OpenGL window");
    exit(EXIT_FAILURE);
  }

  glfwMakeContextCurrent(window);
  glfwSetKeyCallback(window, GLFWKeyboardCallback);
  glfwSetMouseButtonCallback(window, GLFWMouseButtonCallback);
  glfwSetWindowSizeCallback(window, GLFWWindowReshapeCallback);

  if (!gladLoadGL()) {
    kLogger.Log("ERROR: Cannot init GLAD");
    glfwTerminate();
    exit(EXIT_FAILURE);
  }

  kLogger.Log(Kensei::GLInfoHelper::getGLParams().str());

  while (!glfwWindowShouldClose(window)) {
    glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    UpdateFPSCounter(window);

    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  glfwTerminate();
  return EXIT_SUCCESS;
}
예제 #25
0
int main(){

//Multi-threading activated
    omp_set_num_threads(8);
    Eigen::setNbThreads(8);
    Eigen::initParallel();

//Initialize window, callback functions and drawing functions
    glfw_container->initializeWindow();
    glfwSetWindowSizeCallback(glfw_container->getWindow(), glfw_window_size_callback);
    glfwSetMouseButtonCallback(glfw_container->getWindow(), mouseClickEvent);
    glfwSetErrorCallback(glfw_error_callback);
    glfw_container->initializeDrawing();
    glfw_container->loopDrawing();

	return 0;
}
예제 #26
0
bool SetupWindow(const char * title, const int width, const int height)
{
    if(glfwInit() != GL_TRUE)
        std::cerr << "Couldn't initialize glfw\n";
    else
    {
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        GLFWwindow* window(glfwCreateWindow(width, height, title, NULL, NULL));

        if(!window)
            std::cerr << "Couldn't create OpenGL context\n";
        else
        {
            glfwMakeContextCurrent(window);

            glewExperimental = GL_TRUE;
            if(glewInit() != GLEW_OK)
                std::cerr << "Couldn't initialize glew\n";
            else
            {
// had to add this is as GLEW was giving me an unknown enum error(1280) :(
                for(bool empty(false);!empty;)
                {
                    GLenum err(glGetError());
                    if(err == GL_NO_ERROR)
                        empty = true;
                    else if(err != 1280)
                        std::cerr << "ERROR I REPEAT ERROR: " << err << "\n";
                }

                glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
                glfwSetWindowSizeCallback(window, Resize);

                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // maybe 0.0f 0.7f 0.0f
                glViewport(0, 0, width, height);

                return true;
            }
        }
    }
    return false;
}
예제 #27
0
void CPlyRender::Init(GLFWwindow* _glfw_window){
	InitGeometry();
	InitWall();
	InitCubeMapping();
	
	InitShader();

	glfwSetWindowUserPointer(_glfw_window, this);
	glEnable(GL_MULTISAMPLE);
	glfwSetScrollCallback(_glfw_window, wheel);
	glfwSetWindowSizeCallback(_glfw_window, miffy::reshape);
	glfwSetMouseButtonCallback(_glfw_window, miffy::mousebutton);
	glfwSetCursorPosCallback(_glfw_window, miffy::mousemove);
	glfwSetKeyCallback(_glfw_window, keyCallback);

	glShadeModel(GL_FLAT);
}
예제 #28
0
파일: main.c 프로젝트: solmir/projet42
int			main(int ac, char **av)
{
	GLFWwindow		*win;
	t_env			e;
	t_cam			c;

	init_key_binding();
	init_scene(&e);
	init_cam(&c, &e);
	if (!glfwInit())
		exit(EXIT_FAILURE);
	glfwSetErrorCallback(error_callback);
	if (!(win = glfwCreateWindow(WIN_W, WIN_H, "visualisatron 2000",
					NULL, NULL)))
		ft_exit("failed to open window !");
	e.map = malloc(4096);
	e.player_number = 4;
	e.memory_size = 4096;
	e.grid_width = 64;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_SAMPLES, 1);
	glfwSetFramebufferSizeCallback(win, framebuffer_size_callback);
	glfwSetKeyCallback(win, key_callback);
	glfwSetWindowSizeCallback(win, window_size_callback);
	glfwMakeContextCurrent(win);
	glfwSetCursorPosCallback(win, cursor_pos_callback);
	glfwSetMouseButtonCallback(win, mouse_click_callback);
	glfwSetScrollCallback(win, mouse_scroll_callback);
	glfwSwapInterval(1);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glfwShowWindow(win);
	init_msaa();
//	printf("%s\n", glGetString( GL_EXTENSIONS ) );
	while (!glfwWindowShouldClose(win))
		main_loop(win, &e);
	glfwDestroyWindow(win);
	glfwTerminate();
	return (0);
	(void)ac;
	(void)av;
}
예제 #29
0
파일: view_mesh.cpp 프로젝트: Qix-/fugu
void setupWindowAndGL(){
	// Setup GL etc
	if (!glfwInit()){
		exit(EXIT_FAILURE);
	}

	if (!glfwOpenWindow(width,height, 0,0,0,0,8,0, GLFW_WINDOW)){
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	GLenum err = glewInit();
	if (GLEW_OK != err){
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glfwSetWindowSizeCallback(resizeWindow);

	glClearColor(0, 0, 0, 1);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	GLfloat amb[] = {0,0,0,1};
	GLfloat diff[] = {1,1,1,1};
	glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,diff);
/*
	GLfloat global_ambient[] = { 0.3f, 0.3f, 0.3f, 1.0f };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

	glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,10);

	GLfloat col[] = {1.f,1.f,1.f,0.f};
	glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,col);
	GLfloat white[] = {1.f,1.f,1.f,0.f};
	GLfloat spec[] = {.5f,.5f,.5f,0.f};
	glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,spec);
	*/
}
예제 #30
0
/* Nothing to Edit here */
GLFWwindow* initGLFW (int width, int height)
{
    GLFWwindow* window; // window desciptor/handle

    glfwSetErrorCallback(error_callback);
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    window = glfwCreateWindow(width, height, "Sample OpenGL 3.3 Application", NULL, NULL);

    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
    glfwSwapInterval( 1 );

    /* --- register callbacks with GLFW --- */

    /* Register function to handle window resizes */
    /* With Retina display on Mac OS X GLFW's FramebufferSize
     is different from WindowSize */
    glfwSetFramebufferSizeCallback(window, reshapeWindow);
    glfwSetWindowSizeCallback(window, reshapeWindow);

    /* Register function to handle window close */
    glfwSetWindowCloseCallback(window, quit);

    /* Register function to handle keyboard input */
    glfwSetKeyCallback(window, keyboard);      // general keyboard input
    glfwSetCharCallback(window, keyboardChar);  // simpler specific character handling

    /* Register function to handle mouse click */
    glfwSetMouseButtonCallback(window, mouseButton);  // mouse button clicks
    glfwSetScrollCallback(window, scroll_callback);
    return window;
}