Beispiel #1
0
GLFWmonitor* Screen::getMonitor(unsigned short monitorID)
{
	int monitorCount;
	glfwGetMonitors(&monitorCount);
	vector<GLFWmonitor*> monitors = vector<GLFWmonitor*>();
	GLFWmonitor** temp = glfwGetMonitors(&monitorCount);
	monitors.insert(monitors.begin(), temp, temp + monitorCount);

	if (monitorID < monitors.size() && monitorID > 0)
		return monitors.at(monitorID);
	else if (monitorID == 0)
		return glfwGetPrimaryMonitor(); //0
	else
		return nullptr; //actually uses the default screen in Fullscreen mode
}
///@brief Attempt to determine which of the connected monitors is the Oculus Rift and which
/// are not. The only heuristic available for this purpose is resolution.
void IdentifyMonitors()
{
    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count);
    for (int i=0; i<count; ++i)
    {
        GLFWmonitor* pMonitor = monitors[i];
        if (pMonitor == NULL)
            continue;
        const GLFWvidmode* mode = glfwGetVideoMode(pMonitor);

        /// Take a guess at which is the Oculus - 1280x800 is pretty distinctive
        if (
            (mode->width  == 1280) &&
            (mode->height == 800)
            )
        {
            g_pOculusMonitor = pMonitor;
        }
        else if (g_pPrimaryMonitor == NULL)
        {
            /// Guess that the first (probably)non-Oculus monitor is primary.
            ///@note The multi-monitor setup requires the two screens to be aligned along their top edge
            /// with the Oculus monitor to the right of the primary.
            g_pPrimaryMonitor = pMonitor;
        }
    }
}
	GLFWmonitor* RenderSystem::_getMonitor()
	{
		int count;
		GLFWmonitor** monitors = glfwGetMonitors(&count);
		
		return monitors[this->_monitor];
	}
Beispiel #4
0
bool Window_GL::open(WindowParams p, std::string title)
{
//	glfwWindowHint(GLFW_SAMPLES, p.samples);
	glfwWindowHint(GLFW_RESIZABLE, 1);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

	int count;
	GLFWmonitor **ml = glfwGetMonitors(&count);
	GLFWmonitor *m = NULL;

	if (p.fullscreen)
	{
		m = glfwGetPrimaryMonitor();
		if (p.fullscreen_monitor && p.fullscreen_monitor <= count)
			m = ml[p.fullscreen_monitor-1];
	}

	handle = (void*)glfwCreateWindow(p.width, p.height, title.c_str(), m, NULL);
	glfwMakeContextCurrent((GLFWwindow*)handle);

	params = p;

	// Make sure we were able to create a rendering context.
	if (!handle)
	{
		LOG->Error("Unable to obtain an OpenGL 3.1 rendering context.");
		return false;
	}
	if (glxwInit() != 0)
		LOG->Error("Unable to load required OpenGL extensions.");

	return true;
}
Beispiel #5
0
GLFWwindow * createWindow(void) {
	int count;
	GLFWmonitor ** monitors = glfwGetMonitors(&count);
	
	if (count == 1) return glfwCreateWindow(INIT_WIN_WIDTH, INIT_WIN_HEIGHT, WIN_TITLE, NULL, NULL);

	std::cout << "Available monitors:" << std::endl;
	for (int i = 0; i < count; i++) {
		const GLFWvidmode * mode = glfwGetVideoMode(monitors[i]);
		std::cout << "\t" << i + 1 << ":\t" << glfwGetMonitorName(monitors[i]) << "\t" << mode->width << "x" << mode->height << std::endl;
	}

	int selectedMonitor = -1;
	if (SELECT_MONITOR_MAN) {
		std::string data;
		do {
			std::cout << "\nPlease select a monitor:" << std::endl;
			std::getline(std::cin, data);
			if (data.length() > 3) continue;
			selectedMonitor = (unsigned int)atoi(data.c_str());
		} while (selectedMonitor < 1 || selectedMonitor > count);
	}
	else selectedMonitor = SELECT_MONITOR_DEFAULT;
	std::cout << "Selected monitor " << selectedMonitor << "." << std::endl;
	selectedMonitor--; // the monitors display as starting from 1 instead of 0

	const GLFWvidmode * mode = glfwGetVideoMode(monitors[selectedMonitor]);
	controller.m_state.winWidth = mode->width;
	controller.m_state.winHeight = mode->height;

	glfwWindowHint(GLFW_AUTO_ICONIFY, false);

	return glfwCreateWindow(controller.m_state.winWidth, controller.m_state.winHeight = mode->height, WIN_TITLE, monitors[selectedMonitor], NULL);
}
Beispiel #6
0
 int GLFW_App::get_num_monitors() const
 {
     int ret;
     /*GLFWmonitor** monitors = */
     glfwGetMonitors(&ret);
     return ret;
 }
void GlfwApp::createSecondaryScreenWindow(const glm::uvec2 & size) {
  GLFWmonitor * primary = glfwGetPrimaryMonitor();
  int monitorCount;
  GLFWmonitor ** monitors = glfwGetMonitors(&monitorCount);
  GLFWmonitor * best = nullptr;
  glm::uvec2 bestSize;
  for (int i = 0; i < monitorCount; ++i) {
    GLFWmonitor * cur = monitors[i];
    if (cur == primary) {
      continue;
    }
    glm::uvec2 curSize = getSize(cur);
    if (best == nullptr || (bestSize.x < curSize.x && bestSize.y < curSize.y)) {
      best = cur;
      bestSize = curSize;
    }
  }
  if (nullptr == best) {
    best = primary;
    bestSize = getSize(best);
  }
  glm::ivec2 pos = getPosition(best);
  if (bestSize.x > size.x) {
    pos.x += (bestSize.x - size.x) / 2;
  }

  if (bestSize.y > size.y) {
    pos.y += (bestSize.y - size.y) / 2;
  }
  createWindow(size, pos);
}
/// Dump a list of monitor info to Log and stdout.
/// http://www.glfw.org/docs/3.0/monitor.html
void PrintMonitorInfo()
{
    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count);
    printf("Found %d monitors:\n", count);
    LOG_INFO("Found %d monitors:", count);
    for (int i=0; i<count; ++i)
    {
        GLFWmonitor* pMonitor = monitors[i];
        if (pMonitor == NULL)
            continue;
        printf("  Monitor %d:\n", i);
        LOG_INFO("  Monitor %d:", i);

        /// Monitor name
        const char* pName = glfwGetMonitorName(pMonitor);
        printf("    Name: %s\n", pName);
        LOG_INFO("    Name: %s", pName);

        /// Monitor Physical Size
        int widthMM, heightMM;
        glfwGetMonitorPhysicalSize(pMonitor, &widthMM, &heightMM);
        //const double dpi = mode->width / (widthMM / 25.4);
        printf("    physical size: %d x %d mm\n");
        LOG_INFO("    physical size: %d x %d mm");

        /// Modes
        const GLFWvidmode* mode = glfwGetVideoMode(pMonitor);
        printf("    Current mode:  %dx%d @ %dHz (RGB %d %d %d bits)\n",
                mode->width,
                mode->height,
                mode->refreshRate,
                mode->redBits,
                mode->greenBits, 
                mode->blueBits);
        LOG_INFO("    Current mode:  %dx%d @ %dHz (RGB %d %d %d bits)",
                mode->width,
                mode->height,
                mode->refreshRate,
                mode->redBits,
                mode->greenBits, 
                mode->blueBits);

#if 0
        int modeCount;
        const GLFWvidmode* modes = glfwGetVideoModes(pMonitor, &modeCount);
        printf("    %d Modes:\n", modeCount);
        LOG_INFO("    %d Modes:", modeCount);
        for (int j=0; j<modeCount; ++j)
        {
            const GLFWvidmode& m = modes[j];
            printf("      %dx%d @ %dHz (RGB %d %d %d bits)\n",
                m.width, m.height, m.refreshRate, m.redBits, m.greenBits, m.blueBits);
            LOG_INFO("      %dx%d @ %dHz (RGB %d %d %d bits)",
                m.width, m.height, m.refreshRate, m.redBits, m.greenBits, m.blueBits);
        }
#endif
    }
}
Beispiel #9
0
IntVector2 Graphics::GetDesktopResolution(int monitor) const
{
    int monitor_count=0;
    GLFWmonitor** known_monitors = glfwGetMonitors(&monitor_count);
    if (monitor >= monitor_count || monitor < 0)
        monitor = 0; // this monitor is not present, use first monitor
    const GLFWvidmode * mode = glfwGetVideoMode(known_monitors[monitor]);
    return IntVector2(mode->width, mode->height);
}
Beispiel #10
0
char* app_display_querymodes()
{
    glfwSetErrorCallback(glfw_error_callback);

    if (!glfwInit())
        return NULL;

    uint adapter_id = 0;
    size_t outsz;

    /* start json data (adapter array) */
    json_t jroot = json_create_arr();

    /* read adapters */
    while (adapter_id == 0)  {
        json_t jadapter = json_create_obj();
        json_additem_toarr(jroot, jadapter);

        json_additem_toobj(jadapter, "name", json_create_str("Graphics Card #1"));
        json_additem_toobj(jadapter, "id", json_create_num(0));

        /* enumerate monitors */
        json_t joutputs = json_create_arr();
        json_additem_toobj(jadapter, "monitors", joutputs);
        int output_cnt = 0;
        GLFWmonitor** monitors = glfwGetMonitors(&output_cnt);
        for (int i = 0; i < output_cnt; i++)    {
            json_t joutput = json_create_obj();
            json_additem_toarr(joutputs, joutput);

            json_additem_toobj(joutput, "id", json_create_num((fl64)i));
            json_additem_toobj(joutput, "name", json_create_str(glfwGetMonitorName(monitors[i])));

            /* enumerate modes */
            json_t jmodes = json_create_arr();
            json_additem_toobj(joutput, "modes", jmodes);

            int mode_cnt;
            const GLFWvidmode* modes = glfwGetVideoModes(monitors[i], &mode_cnt);
            for (int i = 0; i < mode_cnt; i++)   {
                json_t jmode = json_create_obj();
                json_additem_toobj(jmode, "width", json_create_num((fl64)modes[i].width));
                json_additem_toobj(jmode, "height", json_create_num((fl64)modes[i].height));
                json_additem_toobj(jmode, "refresh-rate",
                    json_create_num((fl64)modes[i].refreshRate));
                json_additem_toarr(jmodes, jmode);
            }
        }

        adapter_id ++;
    }

    char* r = json_savetobuffer(jroot, &outsz, FALSE);
    json_destroy(jroot);

    return r;
}
Beispiel #11
0
int Graphics::GetCurrentMonitor()
{
    GLFWmonitor *mon = glfwGetWindowMonitor(window2_);
    int moncount=0;
    GLFWmonitor **monitors = glfwGetMonitors(&moncount);
    while(--moncount>=0)
        if(monitors[moncount]==mon)
            return moncount;
    return 0;
}
 void Adviser::fetchMonitors(std::vector<Video::Monitor> *buffer) const {
     if(0 != buffer) {
         buffer->clear();
         int monitorCount;
         GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
         for(int i = 0; i < monitorCount; ++i) {
             buffer->push_back(Video::Monitor(monitors[i]));
         }
     }
 }
Beispiel #13
0
	int Init(bool a_bSetFullScreen, unsigned int a_uiWidth, unsigned int a_uiHeight, int a_uiPosX, int a_uiPosY)
	{
		Monitor = glfwGetMonitors(aiNumOfMonitors);
		Mode = glfwGetVideoMode(Monitor[0]);

		glfwWindowHint(GLFW_RED_BITS, Mode->redBits);
		glfwWindowHint(GLFW_GREEN_BITS, Mode->greenBits);
		glfwWindowHint(GLFW_BLUE_BITS, Mode->blueBits);
		glfwWindowHint(GLFW_REFRESH_RATE, Mode->refreshRate);

		if (a_bSetFullScreen)
			Window = glfwCreateWindow(Mode->width, Mode->height, "The Solar System", Monitor[0], nullptr);
		else
		{
			Window = glfwCreateWindow(a_uiWidth, a_uiHeight, "The Solar System", nullptr, nullptr);

			if (a_uiPosX == -1)
				a_uiPosX = (Mode->width - a_uiWidth) / 2;
			if (a_uiPosY == -1)
				a_uiPosY = (Mode->height - a_uiHeight) / 2;

			glfwSetWindowPos(Window, a_uiPosX, a_uiPosY);
		}

		if (Window == nullptr)
		{
			glfwTerminate();
			return -2;
		}

		//make the glfw window 
		glfwMakeContextCurrent(Window);

		if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
		{
			glfwDestroyWindow(Window);
			glfwTerminate();
			return -3;
		}
		// Parses the version of OpenGL and prints it
		auto major = ogl_GetMajorVersion();
		auto minor = ogl_GetMinorVersion();
		printf_s("GL: %i.%i\n", major, minor);

		//initialize all of our gizmos and set up the virtual camera
		Gizmos::create();

		SetView({ 10, 0, 0 }, { 0, 0, 0 }, { 0, 1, 0 });
		Projection = glm::perspective(glm::pi<float>() * 0.25f, 16 / 9.f, 0.001f, 1000.f);

		glClearColor(0.5f, 0.5f, 0.5f, 1);//set the clear color
		glEnable(GL_DEPTH_TEST); // enables the depth buffer	

		return 0;
	}
Beispiel #14
0
	void Monitor::getMonitorsList()
	{
		if(monitors.empty())
		{
			int total = 0;
			GLFWmonitor** mons = glfwGetMonitors(&total);
			
			for(int i = 0; i < total; ++i)
				monitors.emplace_back(mons[i]);
		}
	}
// Get the 'monitor' at position specified by HMD Info
// This should be the OVR
GLFWmonitor* getMonitorAtPosition(glm::ivec2 & position) {
	int count;
	GLFWmonitor ** monitors = glfwGetMonitors(&count);
	for (int i = 0; i < count; ++i) {
		glm::ivec2 candidatePosition;
		glfwGetMonitorPos(monitors[i], &candidatePosition.x, &candidatePosition.y);
		if (candidatePosition == position) {
			return monitors[i];
		}
	}
	return nullptr;
}
Beispiel #16
0
static inline jint wrapped_Java_com_badlogic_jglfw_Glfw_glfwGetMonitorsJni
(JNIEnv* env, jclass clazz, jlongArray obj_monitors, long long* monitors) {

//@line:583

		int count = 0;
		GLFWmonitor** mons = glfwGetMonitors(&count);
		if(!mons) return 0;
		
		for(int i = 0; i < count; i++) {
			monitors[i] = (jlong)mons[i];
		}
		return count;
	
}
Beispiel #17
0
    GLFW_Window::GLFW_Window(int width, int height, const std::string &theName, bool fullscreen,
                             int monitor_index, GLFWwindow* share)
     {
         int monitor_count = 0;
         GLFWmonitor **monitors = glfwGetMonitors(&monitor_count);
         monitor_index = clamp(monitor_index, 0, monitor_count - 1);
//         GLFWmonitor *monitor_handle = monitor_count > 1 ? monitors[monitor_index] : glfwGetPrimaryMonitor();
         
         m_handle = glfwCreateWindow(width, height,
                                     theName.c_str(),
                                     fullscreen ? monitors[monitor_index] : NULL,
                                     share);
        if(!m_handle) throw CreateWindowException();
        glfwMakeContextCurrent(m_handle);
    }
Beispiel #18
0
IntVector2 Graphics::GetMonitorResolution(int monitorId) const
{
    IntVector2 res;
    int moncount=0;
    GLFWmonitor **monitors = glfwGetMonitors(&moncount);
    if(monitorId<moncount)
    {
        const GLFWvidmode * mode = glfwGetVideoMode(monitors[monitorId]);
        res = {mode->width,mode->height};
    }
    else
    {
        const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        res = {mode->width,mode->height};
    }
    return res;
}
Beispiel #19
0
bool Window::switchFullscreen(int screenId)
{
    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count);
    if (screenId >= count)
        return false;

    if (_window.get() == nullptr)
        return false;

    if (screenId != -1)
        _screenId = screenId;
    else if (screenId == _screenId)
        return true;

    const GLFWvidmode* vidmode = glfwGetVideoMode(monitors[_screenId]);

    glfwWindowHint(GLFW_VISIBLE, true);
    GLFWwindow* window;
    if (glfwGetWindowMonitor(_window->get()) == NULL)
    {
        glfwWindowHint(GLFW_RED_BITS, vidmode->redBits);
        glfwWindowHint(GLFW_GREEN_BITS, vidmode->greenBits);
        glfwWindowHint(GLFW_BLUE_BITS, vidmode->blueBits);
        glfwWindowHint(GLFW_REFRESH_RATE, vidmode->refreshRate);

        window = glfwCreateWindow(vidmode->width, vidmode->height, ("Splash::" + _name).c_str(), monitors[_screenId], _window->getMainWindow());
    }
    else
        window = glfwCreateWindow(vidmode->width, vidmode->height, ("Splash::" + _name).c_str(), 0, _window->getMainWindow());

    if (!window)
    {
        Log::get() << Log::WARNING << "Window::" << __FUNCTION__ << " - Unable to create new fullscreen shared window" << Log::endl;
        return false;
    }

    _window = move(make_shared<GlWindow>(window, _window->getMainWindow()));
    updateSwapInterval();
    setupReadFBO();

    setEventsCallbacks();
    showCursor(false);

    return true;
}
Beispiel #20
0
Vector3 Graphics::GetDisplayDPI(int monitor) const
{
    int moncount=0;
    GLFWmonitor **monitors = glfwGetMonitors(&moncount);
    Vector3 result;
    if(monitor<moncount)
    {
        int widthMM, heightMM;
        glfwGetMonitorPhysicalSize(monitors[monitor], &widthMM, &heightMM);
        int diagonalMM = std::sqrt(widthMM * widthMM + heightMM*heightMM);
        const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]);
        const float hdpi = mode->width / (widthMM / 25.4f);
        const float vdpi = mode->height / (heightMM / 25.4f);
        const float ddpi = std::sqrt(mode->width*mode->width + mode->height*mode->height) / (diagonalMM / 25.4f);
        result = {ddpi,hdpi,vdpi};
    }
    return result;
}
Beispiel #21
0
int main(int argc, char** argv)
{
    int ch, i, count, mode = LIST_MODE;
    GLFWmonitor** monitors;

    while ((ch = getopt(argc, argv, "th")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);
            case 't':
                mode = TEST_MODE;
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    argc -= optind;
    argv += optind;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    monitors = glfwGetMonitors(&count);

    for (i = 0;  i < count;  i++)
    {
        if (mode == LIST_MODE)
            list_modes(monitors[i]);
        else if (mode == TEST_MODE)
            test_modes(monitors[i]);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Beispiel #22
0
std::vector<IntVector3> Graphics::GetResolutions(int monitor) const
{
    std::vector<IntVector3> ret;
    int monitor_count=0;
    GLFWmonitor** known_monitors = glfwGetMonitors(&monitor_count);
    if (monitor >= monitor_count || monitor < 0)
        monitor = 0; // this monitor is not present, use first monitor
    GLFWmonitor* selected_monitor = known_monitors[monitor];
    int numModes=0;
    const GLFWvidmode * modes = glfwGetVideoModes(selected_monitor,&numModes);
    if(!modes)
        return ret;

    for (int i = 0; i < numModes; ++i)
    {
        const GLFWvidmode &mode(modes[i]);
        int width = mode.width;
        int height  = mode.height;
        int rate = mode.refreshRate;

        // Store mode if unique
        bool unique = true;
        for (unsigned j = 0; j < ret.size(); ++j)
        {
            if (ret[j].x_ == width && ret[j].y_ == height && ret[j].z_ == rate)
            {
                unique = false;
                break;
            }
        }

        if (unique)
            ret.emplace_back(width, height, rate);
    }

    return ret;
}
Beispiel #23
0
//Method initializes OpenGL for rendering to a window/viewport
bool glEngine::Init()
{
	/// We need our GLFW function pointers to be assigned, if this process fails we cannot continue
	if ( !glfwInit() )
	{
		return false;
	}

	/// Here we query how much sampling is possible and set that to be used if possible
	GLint samples = 8;
	glGetIntegerv( GL_SAMPLES, &samples );
	if ( samples )
	{
		glEnable( GL_MULTISAMPLE );
	}
	glfwWindowHint( GLFW_SAMPLES, samples );

	GLFWmonitor** monitors;
	int count;

	monitors = glfwGetMonitors( &count );
	//TODO: Create Window Resizing method
	const GLFWvidmode* mode = glfwGetVideoMode( glfwGetPrimaryMonitor() );

	///Create a window of a particular type
	switch ( m_wMode )
	{
		case GL_Engine::window::FULLSCREEN:
		{
			m_window = glfwCreateWindow( mode->width, mode->height, "Fullscreen", glfwGetPrimaryMonitor(), NULL );
			m_Screen.m_Height = mode->height;
			m_Screen.m_Width = mode->width;
			break;
		}

		case GL_Engine::window::DECORATEDWINDOW:
		{
			m_window = glfwCreateWindow( m_Screen.Width(), m_Screen.Height(), "Decorated Window", NULL, NULL );
			break;
		}

		case GL_Engine::window::BORDERLESSFULLSCREEN:
		{
			glfwWindowHint( GLFW_DECORATED, false );

			glfwWindowHint( GLFW_RED_BITS, mode->redBits );
			glfwWindowHint( GLFW_GREEN_BITS, mode->greenBits );
			glfwWindowHint( GLFW_BLUE_BITS, mode->blueBits );
			glfwWindowHint( GLFW_REFRESH_RATE, mode->refreshRate );

			m_window = glfwCreateWindow( mode->width, mode->height, "Borderless Fullscreen", NULL, NULL );
			m_Screen.m_Height = mode->height;
			m_Screen.m_Width = mode->width;
			break;
		}
	}

	/// If creating the window failed we need to terminate
	if ( !m_window )
	{
		glfwTerminate();
		return false;
	}
	/// Associates this window with OpenGL's rendering (I believe)
	glfwMakeContextCurrent( m_window );

	/// Sets our input processing function, all input will be passed to this function
	//glfwSetScrollCallback( window, scroll_callback );
	glfwSetKeyCallback( m_window, key_callback );
	glfwSetCursorPosCallback( m_window, cursor_position_callback );
	glfwSetMouseButtonCallback( m_window, mouse_button_callback );
	glfwSetWindowSizeCallback( m_window, window_resize_callback );

	/// start GLEW extension handler
	glewExperimental = GL_TRUE;

	///Initialize OpenGL functions
	glewInit();
	const GLubyte* renderer = glGetString( GL_RENDERER ); /// get renderer string
	const GLubyte* version = glGetString( GL_VERSION ); /// version as a string
	///oLog( Level::Info ) << "Renderer: " << renderer;
	///oLog( Level::Info ) << "OpenGL version supported: " << version;

	m_projectionMatrix = glm::mat4( 1.f );
	m_viewMatrix = glm::mat4( 1.f );

	glEnable( GL_CULL_FACE );
	glCullFace( GL_BACK );
	glFrontFace( GL_CCW );

	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );	///clear colour: r,g,b,a 	
	glfwSwapInterval( 1 ); ///cap FPS

	m_currentDC = wglGetCurrentDC();
	m_currentContext = wglGetCurrentContext();

	return true;
}
Beispiel #24
0
void OGLApp::v_run()
{	
	app = std::make_shared<OGLApp>(*this);

	std::cout << "Starting GLFW context" << std::endl;
	if (!glfwInit())
	{
		std::cerr << "Failed to initialize GLFW" << std::endl;
		return;
	}
	sw = WindowInfo::getInstance()->getWidth();
	sh = WindowInfo::getInstance()->getHeight();

	int MonitorCount;
	GLFWmonitor ** monitors = glfwGetMonitors(&MonitorCount);

#ifdef _DEBUG
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
#endif
	//glfwGetPrimaryMonitor(), 
	pWindow = glfwCreateWindow(sw, sh, WindowInfo::getInstance()->getTitle().c_str(), nullptr, nullptr);
	glfwSetWindowPos(pWindow, WindowInfo::getInstance()->getPosX() - 100, WindowInfo::getInstance()->getPosY() - 100);
	glfwMakeContextCurrent(pWindow);

	glfwSetCursorPosCallback(pWindow, glfw_mouse);          // - Directly redirect GLFW mouse position events to AntTweakBar
	glfwSetScrollCallback(pWindow, glfw_scroll);    // - Directly redirect GLFW mouse wheel events to AntTweakBar
	glfwSetKeyCallback(pWindow, glfw_key);                         // - Directly redirect GLFW key events to AntTweakBar
#ifdef USE_ANT
	glfwSetMouseButtonCallback(pWindow, glfw_mouseButton); // - Directly redirect GLFW mouse button events to AntTweakBar
	glfwSetCharCallback(pWindow, glfw_char);                      // - Directly redirect GLFW char events to AntTweakBar
#endif
	glfwSetWindowSizeCallback(pWindow, glfw_resize);


	//glfwSetInputMode(pWindow, GLFW_STICKY_KEYS, GL_TRUE);
	// GLFW Options
    //glfwSetInputMode(pWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);


	if (pWindow == NULL) {
		std::cerr << "Failed to create GLFW pWindow" << std::endl;
		glfwTerminate();
		return;
	}
	glewExperimental = GL_TRUE;

	//Check the GLSL and OpenGL status 
	if (glewInit() != GLEW_OK)
	{
		std::cerr << "Failed to initialize GLEW" << std::endl;
		return;
	}
	const GLubyte *renderer = glGetString(GL_RENDERER);
	const GLubyte *vendor = glGetString(GL_VENDOR);
	const GLubyte *version = glGetString(GL_VERSION);
	const GLubyte *glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);

	m_GLRenderer = (const char *)renderer;
	m_GLVersion  = (const char *)version;
	m_GLSLVersion = (const char *)glslVersion;

	GLint major, minor;
	glGetIntegerv(GL_MAJOR_VERSION, &major);
	glGetIntegerv(GL_MINOR_VERSION, &minor);
	std::cout << "GL Vendor    :" << vendor << std::endl;
	std::cout << "GL Renderer  : " << renderer << std::endl;
	std::cout << "GL Version (std::string)  : " << version << std::endl;
	std::cout << "GL Version (integer) : " << major << "." << minor << std::endl;
	std::cout << "GLSL Version : " << glslVersion << std::endl;
	std::cout << "--------------------------------------------------------------------------------"
		<< std::endl;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

#ifdef USE_FONT
	m_pFont.init();
#endif
#ifdef USE_CEGUI
	OGLCEGUI::getInstance()->init();
	OGLCEGUI::getInstance()->setupCallbacks(pWindow);
#endif
	v_init();


	while (!glfwWindowShouldClose(pWindow))
	{
		glfwPollEvents();
		v_movement(pWindow);

		countFps();

		static GLfloat lastFrame = static_cast<float>(glfwGetTime());
		GLfloat currentFrame = static_cast<float>(glfwGetTime());
		GLfloat deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;

		v_update();
		v_render();

#ifdef USE_FONT
		glDisable(GL_DEPTH_TEST);
		m_pFont.render("Graphics card: " + m_GLRenderer, 10, sh - 40);
		m_pFont.render("GL Version: " + m_GLVersion, 10, sh - 70);
		m_pFont.render("GLSL Version: " + m_GLSLVersion, 10, sh - 100);
		m_pFont.render("FPS: " + std::to_string(m_fps), 10, 30);
		//glEnable(GL_DEPTH_TEST);
#endif

#ifdef USE_CEGUI
		 OGLCEGUI::getInstance()->render();
#endif
		glfwSwapBuffers(pWindow);
	}

	v_shutdown();

	glfwTerminate();
}
Beispiel #25
0
//------------------------------------------------------------------------------
int main(int argc, char ** argv)
{
    bool fullscreen = false;
    std::string str;
    for (int i = 1; i < argc; ++i) {
        if (!strcmp(argv[i], "-d"))
            g_level = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-c"))
            g_repeatCount = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-f"))
            fullscreen = true;
        else {
            std::ifstream ifs(argv[1]);
            if (ifs) {
                std::stringstream ss;
                ss << ifs.rdbuf();
                ifs.close();
                str = ss.str();
                g_defaultShapes.push_back(SimpleShape(str.c_str(), argv[1], kCatmark));
            }
        }
    }
    initializeShapes();
    OsdSetErrorCallback(callbackError);

    if (not glfwInit()) {
        printf("Failed to initialize GLFW\n");
        return 1;
    }

    static const char windowTitle[] = "OpenSubdiv glBatchViewer";
    
#define CORE_PROFILE
#ifdef CORE_PROFILE
    setGLCoreProfile();
#endif

#if GLFW_VERSION_MAJOR>=3
    if (fullscreen) {
    
        g_primary = glfwGetPrimaryMonitor();

        // apparently glfwGetPrimaryMonitor fails under linux : if no primary,
        // settle for the first one in the list    
        if (not g_primary) {
            int count=0;
            GLFWmonitor ** monitors = glfwGetMonitors(&count);

            if (count)
                g_primary = monitors[0];
        }
        
        if (g_primary) {
            GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
            g_width = vidmode->width;
            g_height = vidmode->height;
        }
    }

    if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, 
                                       fullscreen and g_primary ? g_primary : NULL, NULL))) {
        printf("Failed to open window.\n");
        glfwTerminate();
        return 1;
    }
    glfwMakeContextCurrent(g_window);
    glfwSetKeyCallback(g_window, keyboard);
    glfwSetCursorPosCallback(g_window, motion);
    glfwSetMouseButtonCallback(g_window, mouse);
    glfwSetWindowSizeCallback(g_window, reshape);
#else
    if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8,
                       fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) {
        printf("Failed to open window.\n");
        glfwTerminate();
        return 1;
    }
    glfwSetWindowTitle(windowTitle);
    glfwSetKeyCallback(keyboard);
    glfwSetMousePosCallback(motion);
    glfwSetMouseButtonCallback(mouse);
    glfwSetWindowSizeCallback(reshape);
#endif

#if defined(OSD_USES_GLEW)
#ifdef CORE_PROFILE
    // this is the only way to initialize glew correctly under core profile context.
    glewExperimental = true;
#endif
    if (GLenum r = glewInit() != GLEW_OK) {
        printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
        exit(1);
    }
#ifdef CORE_PROFILE
    // clear GL errors which was generated during glewInit()
    glGetError();
#endif
#endif

    // activate feature adaptive tessellation if OSD supports it
    g_adaptive = OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation();

    initGL();

    glfwSwapInterval(0);

    initHUD();
    callbackModel(g_currentShape);

    g_fpsTimer.Start();
    while (g_running) {
        idle();
        display();
        
#if GLFW_VERSION_MAJOR>=3
        glfwPollEvents();
        glfwSwapBuffers(g_window);
#else
        glfwSwapBuffers();
#endif
    }

    uninitGL();
    glfwTerminate();
}
Beispiel #26
0
int main(int argc, char** argv)
{
    int count = 0;
    GLFWwindow* window;

    srand((unsigned int) time(NULL));

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    for (;;)
    {
        GLFWmonitor* monitor = NULL;

        if (count & 1)
        {
            int monitorCount;
            GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
            monitor = monitors[rand() % monitorCount];
        }

        window = open_window(640, 480, monitor);
        if (!window)
        {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        glMatrixMode(GL_PROJECTION);
        glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);

        glfwSetTime(0.0);

        while (glfwGetTime() < 5.0)
        {
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f);
            glRectf(-0.5f, -0.5f, 1.f, 1.f);
            glPopMatrix();

            glfwSwapBuffers(window);
            glfwPollEvents();

            if (glfwWindowShouldClose(window))
            {
                close_window(window);
                printf("User closed window\n");

                glfwTerminate();
                exit(EXIT_SUCCESS);
            }
        }

        printf("Closing window\n");
        close_window(window);

        count++;
    }

    glfwTerminate();
}
Beispiel #27
0
int main(int argc, char** argv)
{
    int ch, i, window_count;
    int auto_iconify = GLFW_TRUE, fullscreen = GLFW_FALSE, all_monitors = GLFW_FALSE;
    GLFWwindow** windows;

    while ((ch = getopt(argc, argv, "afhn")) != -1)
    {
        switch (ch)
        {
            case 'a':
                all_monitors = GLFW_TRUE;
                break;

            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                fullscreen = GLFW_TRUE;
                break;

            case 'n':
                auto_iconify = GLFW_FALSE;
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_AUTO_ICONIFY, auto_iconify);

    if (fullscreen && all_monitors)
    {
        int monitor_count;
        GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);

        window_count = monitor_count;
        windows = calloc(window_count, sizeof(GLFWwindow*));

        for (i = 0;  i < monitor_count;  i++)
        {
            windows[i] = create_window(monitors[i]);
            if (!windows[i])
                break;
        }
    }
    else
    {
        GLFWmonitor* monitor = NULL;

        if (fullscreen)
            monitor = glfwGetPrimaryMonitor();

        window_count = 1;
        windows = calloc(window_count, sizeof(GLFWwindow*));
        windows[0] = create_window(monitor);
    }

    for (i = 0;  i < window_count;  i++)
    {
        glfwSetKeyCallback(windows[i], key_callback);
        glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback);
        glfwSetWindowSizeCallback(windows[i], window_size_callback);
        glfwSetWindowFocusCallback(windows[i], window_focus_callback);
        glfwSetWindowIconifyCallback(windows[i], window_iconify_callback);
        glfwSetWindowRefreshCallback(windows[i], window_refresh_callback);

        window_refresh_callback(windows[i]);

        printf("Window is %s and %s\n",
            glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
            glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
    }

    for (;;)
    {
        glfwWaitEvents();

        for (i = 0;  i < window_count;  i++)
        {
            if (glfwWindowShouldClose(windows[i]))
                break;
        }

        if (i < window_count)
            break;

        // Workaround for an issue with msvcrt and mintty
        fflush(stdout);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Beispiel #28
0
// APPLICATION ENTRY
// -----------------
int main() {
  int width = 1024;
  int height = 768;
  sim_ptr = NULL;

  int c = 0;
  GLFWmonitor** m = glfwGetMonitors(&c);

  // init
  glfwSetErrorCallback(error_callback);
  if(!glfwInit()) {
    printf("ERROR: cannot initialize GLFW.\n");
    exit(EXIT_FAILURE);
  }

  // glfwWindowHint(GLFW_DEPTH_BITS, 16);
  // glfwWindowHint(GLFW_FSAA_SAMPLES, 4);

  GLFWwindow* window = glfwCreateWindow(width, height, "Simulation", NULL, NULL);
  if(!window) {
    printf("ERROR: cannot open window.\n");
    exit(EXIT_FAILURE);
  }
  
  glfwSetWindowSizeCallback(window, window_size_callback);
  glfwSetWindowCloseCallback(window, window_close_callback);
  glfwSetMouseButtonCallback(window, mouse_button_callback);
  glfwSetCursorPosCallback(window, cursor_callback);
  glfwSetScrollCallback(window, scroll_callback);
  glfwSetKeyCallback(window, key_callback);
  glfwSetCharCallback(window, char_callback);

  glfwMakeContextCurrent(window);

#if defined(ROXLU_GL_CORE3)
  if(glxwInit() != 0) {
    printf("ERROR: cannot init glxw\n");
    return EXIT_FAILURE;
  }
#else
  glewExperimental = true;
  GLenum err = glewInit();
  if (GLEW_OK != err) {
    fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
    exit(EXIT_FAILURE);
  }
#endif

  Simulation sim;
  sim_ptr = &sim;
  sim.window = window;
  sim.window_w = width;
  sim.window_h = height;
  sim.setup();
  
  bool running = true;
  while(running) {
    glfwPollEvents();

    sim.update();
    sim.draw();

    glfwSwapBuffers(window);
    running = !(glfwGetKey(window, GLFW_KEY_ESC));
  }
  glfwTerminate();
  return EXIT_SUCCESS;
};
//------------------------------------------------------------------------------
int main(int argc, char ** argv)
{
    bool fullscreen = false;
    std::string str;
    for (int i = 1; i < argc; ++i) {
        if (!strcmp(argv[i], "-d"))
            g_level = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-c"))
            g_repeatCount = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-f"))
            fullscreen = true;
        else {
            std::ifstream ifs(argv[1]);
            if (ifs) {
                std::stringstream ss;
                ss << ifs.rdbuf();
                ifs.close();
                str = ss.str();
                g_shapes.push_back(ShapeDesc(argv[1], str.c_str(), kCatmark));
            }
        }
    }
    initShapes();

    if (not glfwInit()) {
        printf("Failed to initialize GLFW\n");
        return 1;
    }

    static const char windowTitle[] = "OpenSubdiv vtrViewer";

#define CORE_PROFILE
#ifdef CORE_PROFILE
    setGLCoreProfile();
#endif

    if (fullscreen) {

        g_primary = glfwGetPrimaryMonitor();

        // apparently glfwGetPrimaryMonitor fails under linux : if no primary,
        // settle for the first one in the list
        if (not g_primary) {
            int count=0;
            GLFWmonitor ** monitors = glfwGetMonitors(&count);

            if (count)
                g_primary = monitors[0];
        }

        if (g_primary) {
            GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
            g_width = vidmode->width;
            g_height = vidmode->height;
        }
    }

    if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
                                       fullscreen and g_primary ? g_primary : NULL, NULL))) {
        printf("Failed to open window.\n");
        glfwTerminate();
        return 1;
    }
    glfwMakeContextCurrent(g_window);

    // accommocate high DPI displays (e.g. mac retina displays)
    glfwGetFramebufferSize(g_window, &g_width, &g_height);
    glfwSetFramebufferSizeCallback(g_window, reshape);

    glfwSetKeyCallback(g_window, keyboard);
    glfwSetCursorPosCallback(g_window, motion);
    glfwSetMouseButtonCallback(g_window, mouse);
    glfwSetWindowCloseCallback(g_window, windowClose);

#if defined(OSD_USES_GLEW)
#ifdef CORE_PROFILE
    // this is the only way to initialize glew correctly under core profile context.
    glewExperimental = true;
#endif
    if (GLenum r = glewInit() != GLEW_OK) {
        printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
        exit(1);
    }
#ifdef CORE_PROFILE
    // clear GL errors which was generated during glewInit()
    glGetError();
#endif
#endif

    initGL();

    glfwSwapInterval(0);

    initHUD();
    rebuildOsdMeshes();

    checkGLErrors("before loop");
    while (g_running) {
        idle();
        display();

        glfwPollEvents();
        glfwSwapBuffers(g_window);

        glFinish();
    }

    uninitGL();
    glfwTerminate();
}
Beispiel #30
0
void Window_Create(char *Title, int Width, int Height, int MoniterNum,
		struct Window **Window)
{
	log_info("Creating Window");
	if (*Window == NULL)
		(*Window) = malloc(sizeof(struct Window));

	check_mem((*Window));

	(*Window)->WINDOW_TITLE = Title;
	(*Window)->WINDOW_WIDTH = Width;
	(*Window)->WINDOW_HEIGHT = Height;
	Game_Width = Width;
	Game_Height = Height;

	/* Initialize GLFW for video output */
	if (!glfwInit())
	{
		log_info("Unable to initialize GLFW");
		Application_Error();
	}

	int count;
	GLFWmonitor** monitors = glfwGetMonitors(&count);

	int xpos, ypos;
	glfwGetMonitorPos(monitors[MoniterNum], &xpos, &ypos);
	const GLFWvidmode* mode = glfwGetVideoMode(monitors[0]);

	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);

	/* Create a 640x480 OpenGL screen */
	(*Window)->Window = glfwCreateWindow((*Window)->WINDOW_WIDTH,
			(*Window)->WINDOW_HEIGHT, (*Window)->WINDOW_TITLE, NULL, NULL);
	glfwSetWindowPos((*Window)->Window,
			xpos + mode->width / 2 - mode->width / 4 + mode->width / 8,
			ypos + mode->height / 2 - mode->height / 4);
	if (!(*Window)->Window)
	{
		log_err("Unable to create OpenGL window");
		Application_Error();
	}

	glfwMakeContextCurrent((*Window)->Window);

	if (gl3wInit())
	{
		log_err("failed to initialize OpenGL");
		Application_Error();
	}
	if (!gl3wIsSupported(3, 3))
	{
		log_err("OpenGL 3.3 not supported");
		Application_Error();
	}

	glGenVertexArrays(1, &(*Window)->DefaultVAO);
	glBindVertexArray((*Window)->DefaultVAO);

	(*Window)->Running = true;

	printOpenGLError();

	log_info("Window has been created");

	return;

	error: Window_Free(Window);
	Application_Error();
	return;
}