コード例 #1
0
void printVers() {
  std::cout << "GLFW " << glfwGetVersionString() << std::endl;
  std::cout << "GLEW " << glewGetString(GLEW_VERSION) << std::endl;
  std::cout << "GL " << glGetString(GL_VERSION) << std::endl;
  std::cout << "Shader version " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
  std::cout << std::endl;
}
コード例 #2
0
int					main(int ac, char **av)
{
    GLFWwindow		*window;
    GLuint			texture;

    if (!glfwInit())
        return (1);
    ft_printf("Init ok\nGlfw version: %s\n", glfwGetVersionString());
    glfwSetErrorCallback(&error_handler);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    if (!(window = glfwCreateWindow(800, 600, "Scope", NULL, NULL)))
    {
        glfwTerminate();
        return (2);
    }
    glfwMakeContextCurrent(window);
    glEnable(GL_DEPTH_TEST);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    texture = texture_load((ac > 2) ? av[2] : "herbe.jpg");
    ft_printf("Renderer: %s\nOpenGL version supported %s\n",
              glGetString(GL_RENDERER), glGetString(GL_VERSION));
    return (main_loop(window, texture, av[1]));
}
コード例 #3
0
ファイル: glfwinfo.c プロジェクト: deltaluca/glfw
static GLboolean valid_version(void)
{
    int major, minor, revision;

    glfwGetVersion(&major, &minor, &revision);

    printf("GLFW header version: %u.%u.%u\n",
           GLFW_VERSION_MAJOR,
           GLFW_VERSION_MINOR,
           GLFW_VERSION_REVISION);

    printf("GLFW library version: %u.%u.%u\n", major, minor, revision);

    if (major != GLFW_VERSION_MAJOR)
    {
        printf("*** ERROR: GLFW major version mismatch! ***\n");
        return GL_FALSE;
    }

    if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
        printf("*** WARNING: GLFW version mismatch! ***\n");

    printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
    return GL_TRUE;
}
コード例 #4
0
ファイル: Screen.cpp プロジェクト: Deathlymad/GraphicsTest
void Screen::setupGraphicFunctions()
{
	if (initializedGLEW)
		return;

	LOG << "start init of GLEW" << "\n";
	glewExperimental = true; // Needed for core profile
	LOG << "using experimental version of GLEW" << "\n";
	if (glewInit() != GLEW_OK) {
		LOG << "Failed to initialize GLEW" << "\n";
	}
	LOG << "done with GLEW" << "\n";

	glGetError(); //catches the Invalid Enum Error that GLEW Throws, not a error but a bug
	LOG << string("Running Versions: \n") +
		"  Graphics Data:\n\n" +
		"    Graphic Renderer: " + (char*)glGetString(GL_RENDERER) + "\n" +
		"    Graphics Vendor:  " + (char*)glGetString(GL_VENDOR) + "\n" +
		"    OpenGL:           " + (char*)glGetString(GL_VERSION) + "\n" +
		"    GLSL:             " + (char*)glGetString(GL_SHADING_LANGUAGE_VERSION) + "\n" +
		"    GLFW:             " + (char*)glfwGetVersionString() + "\n" +
		"    GLEW:             " + (char*)glewGetString(GLEW_VERSION) + "\n";

	initializedGLEW = true;
}
コード例 #5
0
ファイル: GLFWRenderer.cpp プロジェクト: barczynsky/ft-layout
GLFWRenderer::GLFWRenderer(int w, int h) : width { w }, height { h }
{
	glfwInit();
	glfwWindowHint(GLFW_SAMPLES, 16);
	window = glfwCreateWindow(w, h, glfwGetVersionString(), nullptr, nullptr);
	glfwMakeContextCurrent(window);
	glewInit();
}
コード例 #6
0
ファイル: gl_utils.cpp プロジェクト: capnramses/opengl_expmts
/*--------------------------------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;
	}

	// uncomment these lines if on Apple OS X
	glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

//	glfwWindowHint (GLFW_SAMPLES, 32);
	
	/*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 ();
	
	if (GLEW_KHR_debug) {
		int param = -1;
		printf ("KHR_debug extension found\n");
		glDebugMessageCallback ((GLDEBUGPROC)debug_gl_callback, &param);
		glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
		printf ("debug callback engaged\n");
	} else {
		printf ("KHR_debug extension NOT found\n");
	}

	// 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);
	//vysnch
//	glfwSwapInterval (1);
	return true;
}
コード例 #7
0
JNIEXPORT jstring JNICALL Java_com_badlogic_jglfw_Glfw_glfwGetVersionString(JNIEnv* env, jclass clazz) {


//@line:571

		return env->NewStringUTF(glfwGetVersionString());
	

}
コード例 #8
0
ファイル: GLFW_Window.cpp プロジェクト: noamg97/easyGL
bool GLFW_Window::Initialize( const char* name, bool full_screen, int width, int height, int opengl_version_major, int opengl_version_minor, int anti_aliasing )
{
	GLFW_Window::instance = this;

	GLFWmonitor* mon = NULL;
	if(full_screen)
	{
		mon = glfwGetPrimaryMonitor ();
		const GLFWvidmode* vmode = glfwGetVideoMode (mon);

		this->width = vmode->width;
		this->height = vmode->height;
	}
	else
	{
		if(!(width && height))
		{
			LogMessage ("ERROR: window width or height are 0 when full_screen is false");
			return 1;
		}
		this->width = width;
		this->height = height;
	}


	assert(GLFW_Window::RestartLog());
	LogMessage ("starting GLFW\n%s\n", glfwGetVersionString ());

	glfwSetErrorCallback (GLFW_Window::GLFWErrorCallback);

	if (!glfwInit ()) {
		LogMessage ("ERROR: could not start GLFW3");
		return 1;
	}


	glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, opengl_version_major);
	glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, opengl_version_minor);
	glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


	glfwWindowHint (GLFW_SAMPLES, anti_aliasing);


	this->handle = glfwCreateWindow (this->width, this->height, name, mon, NULL);


	glfwMakeContextCurrent (this->handle);
	glfwSetWindowSizeCallback (this->handle, GLFW_Window::GLFWWindowSizeCallback);


	return 0;
}
コード例 #9
0
static void print_version(void)
{
    int major, minor, revision;
    glfwGetVersion(&major, &minor, &revision);

    printf("GLFW header version: %u.%u.%u\n",
           GLFW_VERSION_MAJOR,
           GLFW_VERSION_MINOR,
           GLFW_VERSION_REVISION);
    printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
    printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
}
コード例 #10
0
ファイル: scene.cpp プロジェクト: Razbit/razngin
Scene::Scene()
{
    log = Game::log;

    // Create OpenGL context
    if (!glfwInit())
    {
        log->write("Failed to init GLFW\n");
        exit(EXIT_FAILURE);
    }

    log->write("GLFW version: %s\n", glfwGetVersionString());

    glfwWindowHint(GLFW_SAMPLES, Game::settings->get("video.aa_samples")->n);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); /* OS X */
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    window = glfwCreateWindow(Game::settings->get("video.width")->n,  \
                              Game::settings->get("video.height")->n, \
                              "Razngin", NULL, NULL);

    if (window == NULL)
    {
        log->write("Failed to open GLFW window\n");
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glewExperimental = true;

    if (glewInit() != GLEW_OK)
    {
        log->write("Failed to init GLEW\n");
        exit(EXIT_FAILURE);
    }

    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    glClearColor(0,0,0,0);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glGenVertexArrays(1, &vao_id);
    glBindVertexArray(vao_id);
}
コード例 #11
0
/*--------------------------------GLFW3 and GLEW-----------------------------*/
bool start_gl() {
	const GLubyte *renderer;
	const GLubyte *version;

	gl_log( "starting GLFW %s", 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
	/*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, "Shaders", NULL, NULL );
	if ( !g_window ) {
		fprintf( stderr, "ERROR: could not open window with GLFW3\n" );
		glfwTerminate();
		return false;
	}
	glfwSetFramebufferSizeCallback( g_window, glfw_framebuffer_size_callback );
	glfwMakeContextCurrent( g_window );

	glfwWindowHint( GLFW_SAMPLES, 4 );

	/* start GLEW extension handler */
	glewExperimental = GL_TRUE;
	glewInit();

	/* get version info */
	renderer = glGetString( GL_RENDERER ); /* get renderer string */
	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 );

	previous_seconds = glfwGetTime();

	return true;
}
コード例 #12
0
bool VideoManager::InitalizeEngine()
{
	LogMessage("\n--------------------- Program Startup ----------------------\n");
	glfwSetErrorCallback(glfw_error_cb);

	if (!glfwInit())
	{
		LogError("GLFW INIT", "Could not start GLFW3");
		return false;
	}

	LogMessage("Starting GLFW: %s\n", glfwGetVersionString());

	return true;
}
コード例 #13
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;
	}

	// uncomment these lines if on Apple OS X
	/*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);
*/
	
	/*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);
	
	glfwWindowHint (GLFW_SAMPLES, 4);
	
	// 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;
}
コード例 #14
0
ファイル: gl_utils.cpp プロジェクト: capnramses/opengl_expmts
/*--------------------------------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 */

	glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 2);
	glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);


	/*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);
	
	glfwWindowHint (GLFW_SAMPLES, 16);
	
	// 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;
}
コード例 #15
0
ファイル: window.cpp プロジェクト: JWalker1995/cellsim-2
Window::Window(Simulation *sim)
    : sim(sim)
{
    std::cout << "GLFW version: " << glfwGetVersionString() << std::endl;

    glfwSetErrorCallback(window_error_callback);

    // Initialize GLFW
    if (!glfwInit())
    {
        std::cerr << "GLFW error!" << std::endl;
        error = true;
        return;
    }

    // Create GLFW window
    window = glfwCreateWindow(640, 480, "CellSim", NULL, NULL);
    if (!window)
    {
        std::cerr << "Could not create GLFW window!" << std::endl;
        error = true;
        return;
    }
    glfwMakeContextCurrent(window);

    // Initialize GLEW
    GLenum glew_init = glewInit();
    if (glew_init != GLEW_OK)
    {
        std::cerr << glewGetErrorString(glew_init) << std::endl;
        error = true;
        return;
    }

    std::cout << "GLEW version: " << glewGetString(GLEW_VERSION) << std::endl;

    // Set GLFW options
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
    glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, GL_TRUE);

    glClearColor(0.0, 0.0, 0.2, 0.0);

    //glfwSetCursorPosCallback(window, cursor_callback);
}
コード例 #16
0
int main()
{
    GLFWwindow *window;
    char *userptr = "userptr";

    glfwSetErrorCallback(errorcb);
    assert(glfwInit() == GL_TRUE);
    assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten"));
    assert(glfwGetCurrentContext() == NULL);

    {
        int major, minor, rev;
        glfwGetVersion(&major, &minor, &rev);
        assert(major == 3);
        assert(minor == 2);
        assert(rev == 1);
    }

    {
        int count, x, y, w, h;
        GLFWmonitor **monitors = glfwGetMonitors(&count);
        assert(count == 1);
        for (int i = 0; i < count; ++i) {
            assert(monitors[i] != NULL);
        }

        assert(glfwGetPrimaryMonitor() != NULL);
        glfwGetMonitorPos(monitors[0], &x, &y);
        glfwGetMonitorPhysicalSize(monitors[0], &w, &h);
        assert(glfwGetMonitorName(monitors[0]) != NULL);
        glfwSetMonitorCallback(monitcb);

        // XXX: not implemented
        // assert(glfwGetVideoModes(monitors[0], &count) != NULL);
        // assert(glfwGetVideoMode(monitors[0]) != NULL);
        // glfwSetGamma(monitors[0], 1.0f);
        // assert(glfwGetGammaRamp(monitors[0]) != NULL);
        // glfwSetGammaRamp(monitors[0], ramp);
    }

    {
        int x, y, w, h;
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        glfwSetWindowPosCallback(window, wposicb);
        glfwSetWindowSizeCallback(window, wsizecb);
        glfwSetWindowCloseCallback(window, wcloscb);
        glfwSetWindowRefreshCallback(window, wrfrscb);
        glfwSetWindowFocusCallback(window, wfocucb);
        glfwSetWindowIconifyCallback(window, wiconcb);
        glfwSetFramebufferSizeCallback(window, wfsizcb);

        assert(glfwWindowShouldClose(window) == 0);
        glfwSetWindowShouldClose(window, 1);
        assert(glfwWindowShouldClose(window) == 1);

        glfwSetWindowTitle(window, "test");
        glfwSetWindowTitle(window, "glfw3.c");

        // XXX: not implemented
        // glfwSetWindowPos(window, 1, 1);

        glfwGetWindowPos(window, &x, &y); // stub
        glfwGetWindowSize(window, &w, &h);
        assert(w == 640 && h == 480);

        glfwSetWindowSize(window, 1, 1);
        glfwGetWindowSize(window, &w, &h);
        assert(w == 1 && h == 1);

        glfwSetWindowSize(window, 640, 480);
        glfwGetFramebufferSize(window, &w, &h);

        // XXX: not implemented
        // glfwIconifyWindow(window);
        // glfwRestoreWindow(window);
        // glfwShowWindow(window);
        // glfwHideWindow(window);

        assert(glfwGetWindowMonitor(window) == NULL);
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL);
        assert(window != NULL);
        assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor());
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API);

        assert(glfwGetWindowUserPointer(window) == NULL);
        glfwSetWindowUserPointer(window, userptr);
        assert(glfwGetWindowUserPointer(window) == userptr);
    }

    {
        double x, y;

        glfwSetKeyCallback(window, wkeypcb);
        glfwSetCharCallback(window, wcharcb);
        glfwSetMouseButtonCallback(window, wmbutcb);
        glfwSetCursorPosCallback(window, wcurpcb);
        glfwSetCursorEnterCallback(window, wcurecb);
        glfwSetScrollCallback(window, wscrocb);

        // XXX: stub, events come immediatly
        // glfwPollEvents();
        // glfwWaitEvents();

        assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);

        // XXX: not implemented
        // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);

        glfwGetKey(window, GLFW_KEY_A);
        glfwGetMouseButton(window, 0);
        glfwGetCursorPos(window, &x, &y);

        // XXX: not implemented
        // glfwSetCursorPos(window, 0, 0);
    }

    {
        // XXX: not implemented
        // glfwJoystickPresent(joy);
        // glfwGetJoystickAxes(joy, &count);
        // glfwGetJoystickButtons(joy, &count);
        // glfwGetJoystickName(joy);
    }

    {
        // XXX: not implemented
        // glfwSetClipboardString(window, "string");
        // glfwGetClipboardString(window);
    }

    {
        glfwGetTime();
        glfwSetTime(0);
    }

    {
        glfwMakeContextCurrent(window); // stub
        assert(glfwGetCurrentContext() == window);
        glfwSwapBuffers(window); // stub
        glfwSwapInterval(0); // stub
    }

    {
        assert(glfwExtensionSupported("nonexistant") == 0);
        assert(glfwGetProcAddress("nonexistant") == NULL);
    }

    glfwTerminate();

#ifdef REPORT_RESULT
    REPORT_RESULT(1);
#endif
    return 0;
}
コード例 #17
0
int main(int argc, const char *arg[]) {
	
	std::string modelname = "../../media/models/primitive/cube.obj";

	if (argc > 1) {
		std::string model(arg[1]);
		if (model == "corsair") {
			modelname = "../../media/models/aircraft/f4u-corsair/f4u-no-propeller.obj";
		}
		else if (model == "p47") {
			modelname = "../../media/models/aircraft/p47-thunderbolt/p47.obj";
		}
		else if (model == "ki-84" || model == "kate") {
			modelname = "../../media/models/aircraft/ki-84/ki84-no-propeller.obj";
		}
		else if (model == "p40" || model == "warhawk") {
			modelname = "../../media/models/aircraft/p40-warkhawk/P40.obj";
		}
		else if (model == "p38" || model == "lightning") {
			modelname = "../../media/models/aircraft/p38-lightning/P38.obj";
		}
		else if (model == "uboat" || model == "U99") {
			modelname = "../../media/models/marine/uboat-u99/U99.obj";
		}
		else if (model == "cube") {
			modelname = "../../media/models/primitive/cube.obj";
		}
		else if (model == "trex" || model == "t-rex") {
			modelname = "../../media/models/objects/absurd/t-rex/t-rex.obj";
		}
		else if (model == "path" && argc > 2) {
			modelname = arg[2];
		}
	}

	Log::initialize("RenderRigidModel.log", Log::All);
	LogReport() << "GLFW version: " << glfwGetVersionString();
	LogReport() << "Rendering model '" << modelname << "'.";

	std::cout << "Rendering model '" << modelname << "'." << std::endl;

  GLFWwindow* window;
  glfwSetErrorCallback(error_callback);

  if (!glfwInit()) {
		exit(EXIT_FAILURE);
	}
  window = glfwCreateWindow(800, 800, "Render Rigid Body", NULL, NULL);
  if (!window) {
		glfwTerminate();
		exit(EXIT_FAILURE);
  }

  glfwMakeContextCurrent(window);
  glfwSetKeyCallback(window, key_callback);
		
	int width, height;
	glfwGetFramebufferSize(window, &width, &height);
	glViewport(0, 0, width, height);

	try {
		if (!application.initialize(modelname)) {
			return 0;
		}
	}
	catch (std::runtime_error &e) {
		LogError() << e.what();
		std::cerr << e.what() << std::endl;
		return -1;
	}

	try {
		while (!glfwWindowShouldClose(window)) {
			application.update();
			application.render();
			glfwSwapBuffers(window);
			glfwPollEvents();
		}
		glfwDestroyWindow(window);
		glfwTerminate();
		exit(EXIT_SUCCESS);
	}
	catch (std::runtime_error &e) {
		LogError() << e.what();
		std::cerr << e.what() << std::endl;
	}

	return 0;
}
コード例 #18
0
int main(int argc, char *argv[])
{
	//start context
	if (!glfwInit())
	{
		fprintf(stderr, "Error, could not start GLFW3\n");
		return 1;
	}
	else
	{
		fprintf(stderr, "GLFW initialized properly.");
	}

	//Forward compatibility from version 3.2.
	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, 4); //Anti aliasing (4 passes)
	
	//start logs
	Logger::restartLog(GL_LOG_FILE);
	glfwSetErrorCallback(glfwErrorCallback);

	GLFWmonitor* monitor = glfwGetPrimaryMonitor();
	const GLFWvidmode* mode = glfwGetVideoMode(monitor);

	//init window with primary monitor resolution
	//Set these modes for a fullscreen window and don't for classic fullscreen:
	/*glfwWindowHint(GLFW_RED_BITS, mode->redBits);
	glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
	glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
	glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);*/
	//------------------------------------------------

	//GLFWwindow * window = glfwCreateWindow(mode->width, mode->height, "Tutorial 1: Draw a triangle", monitor, NULL); //Fullscreen
	GLFWwindow * window = glfwCreateWindow(800, 600, "Tutorial 1: Draw a triangle", NULL, NULL); //Not Fullscreen

	//if window initialisation failed
	if (!window)
	{
		fprintf(stderr, "Could not open window with GLFW3\n");
		glfwTerminate();
		return 1;
	}

	glfwMakeContextCurrent(window);
	glfwSetWindowSizeCallback(window, glfwWindowSizeCallback);

	//start glew extension handler;
	glewExperimental = GL_TRUE;
	glewInit();

	//get version info
	const GLubyte * renderer = glGetString(GL_RENDERER);
	const GLubyte * version = glGetString(GL_VERSION);

	//Log informations
	Logger::printToLog(GL_LOG_FILE, "Starting GLFW: %s \n", glfwGetVersionString());
	logGlParams();

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	//draw triangle
	initTriangles();

	Shader vertex = Shader("vertex.vert", GL_VERTEX_SHADER);
	Shader frag_1 = Shader("frag1.frag", GL_FRAGMENT_SHADER);
	Shader frag_2 = Shader("frag2.frag", GL_FRAGMENT_SHADER);

	Shader shaders_1[2] = { vertex, frag_1 };
	Shader shaders_2[2] = { vertex, frag_2 };

	ShaderProgram shader_programme_1 = ShaderProgram(shaders_1, VERT_FRAG);
	ShaderProgram shader_programme_2 = ShaderProgram(shaders_2, VERT_FRAG);

	while (!glfwWindowShouldClose(window)) {
		updateFpsCounter(window);

		// wipe the drawing surface clear 
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, g_gl_width, g_gl_height);

		glClearColor(0.1f, 0.1f, 0.1f, 0.0f);

		glUseProgram(shader_programme_1.get_program());
		glBindVertexArray(vao_1);

		// draw points 0-5 from the currently bound VAO with current in-use shader 
		glDrawArrays(GL_TRIANGLES, 0, 6);

		glUseProgram(shader_programme_2.get_program());
		glBindVertexArray(vao_2);

		// draw points 0-5 from the currently bound VAO with current in-use shader 
		glDrawArrays(GL_TRIANGLES, 0, 3);

		// update other events like input handling 
		glfwPollEvents();
		// put the stuff we've been drawing onto the display 
		glfwSwapBuffers(window);

		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) 
		{
			glfwSetWindowShouldClose(window, 1);
		}
	}

	//close gl context and other glfw resources
	glfwTerminate();

	return 0;
}
コード例 #19
0
//********************//
//Engine Display Class//
//********************//
void Engine_Init::RunDisplay()
{
	//GLFW Initiate
	errchk(glfwInit());
	cout << glfwGetVersionString() << endl;

	//GLFW Set Window Properties
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	glfwWindowHint(GLFW_SAMPLES, props.MSAA);

	props.init(); //Initialize the engine properties from the properties input file "Settings."
	camera.init(props); //Initialize the camera class.

	//Initialize Window
	switch(props.FullScreen)
	{
	 case 0: 
	 {window = glfwCreateWindow(props.WinWidth, props.WinHeight, "GameEngine Test", nullptr, nullptr);break;}
	 case 1: 
	 {window = glfwCreateWindow(props.WinWidth, props.WinHeight, "GameEngine Test", glfwGetPrimaryMonitor(), nullptr);break;}
	}

	if( window == NULL ){
        	fprintf( stderr, "Failed to open GLFW window.\n" );
        	glfwTerminate();
    	}

	glfwMakeContextCurrent(window);
	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

	//Set the call back functions
	setEventHandling();
        glfwSetKeyCallback(window, StateBase::keycallback_dispatch);
        glfwSetCursorPosCallback(window, StateBase::mousecallback_dispatch);
        glfwSetScrollCallback(window, StateBase::scrollcallback_dispatch);

	//Initialize Glew
	glewExperimental = GL_TRUE;
	glewInit();

	//Set view port dimensions
	glViewport(0, 0, props.WinWidth, props.WinHeight); 

	//Setup OpenGL Options
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_MULTISAMPLE);
    	glEnable(GL_CULL_FACE);
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//Poly Fill Mode	
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

	//System Processors
	int NProc = sysconf( _SC_NPROCESSORS_ONLN );
	cout << "Number of System Processors: " << NProc << endl;

	//Max Number of Attributes
	GLint nrAttributes;
	glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);
	cout << "Maximum nr of vertex attributes supported: " << nrAttributes << std::endl;

	GLErrorCatch("GL Preamble");

	//Set the frames per second timer
	fpsTimer ft;

	//This sets the View and Projection "Matrices" Uniform Buffer Object at global location 0;
	//TM.SetViewUniformBufferObject();

	//Setup screen text writing
	SW.Setup("bin/fonts/FreeSans.ttf",props.WinWidth,props.WinHeight);//Setup screen font
	GLErrorCatch("Screen Writer Setup");

	//Initialize Shaders
	SCC.ShaderLoader();
	GLErrorCatch("Shader Handling");

	//Initialize SolarSystem
	double TIMECHECK = glfwGetTime();
	solarsystem.SetupClass(OPC);
	cout << "SolarSys CLASS SETUP TIME: " << glfwGetTime() - TIMECHECK  << "\n";
	cout << "SolarSystem class Setup...\n";
	solarsystem.GenerateSolarSystem(OPC,0,0);
	cout << "SolarSystem Generated...\n";
	GLErrorCatch("SolarSystem Generation");

	//Setup Global Uniform Handler
	GGUBO.SetGlobalUBO(SCC);
	camera.SetProjViewUBO(SCC);
	
	GLErrorCatch("Uniform Handling");

	//Setup Timing Stats
	TimingStats TS(SW,props);
	TS.SetObject("Preamble");
	TS.SetObject("camera.PrepareCameraData");
	TS.SetObject("GGUBO.UpdateGlobalUBO");
	TS.SetObject("solarsystem.PrepareData");
	TS.SetObject("ProcessDrawArray");
	TS.SetObject("PrintScreenTimers");
	TS.SetObject("Screen_Console");
	TS.SetObject("glfwSwapBuffers");
	TS.SetObject("drawArray.ClearDrawArrays");
	TS.SetObject("EventPolling");
	TS.SetObject("Skybox Drawing");

	while(!glfwWindowShouldClose(window))
	{
                //*********************
                //Frame Timer
                //*********************
		TS.TS(0);
                dt.SetTime();

		//*************************
		//Sets the background color
                //*************************
                glClearColor(Env.bgColor.x, Env.bgColor.y, Env.bgColor.z, 0.0f);
                glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
		TS.TE(0);

		//***************
		//Setup Scene
		//***************
		//Prepare the camera class for the frame
		//cout << "***TEST1***" << endl;
		TS.TS(1);
		camera.PrepareCameraData();
		TS.TE(1);
		//Update the global uniform buffer objects
		TS.TS(2);
		GGUBO.UpdateGlobalUBO(camera);
		TS.TE(2);
		//Prepare the solarsystem data
		//cout << "***TEST2***" << endl;
		TS.TS(3);
		solarsystem.PrepareData(OPC,drawArray,drawInstArray,camera,dt,false);
		TS.TE(3);

		//***************
                //Scene Rendering
                //***************
		//cout << "***TEST3***" << endl;
		//Draw all objects

		TS.TS(10);
		skybox.DrawSkybox(camera,props);
		TS.TE(10);

		TS.TS(4);
		ProcessDrawArray();
		TS.TE(4);

		//*******************
		//Interface Rendering
		//*******************
		//Render Frame Timer
		TS.TS(5);
		PrintScreenTimers(SW,ft);
		TS.TE(5);
		//cout << "***TEST4***" << endl;
		//Console Functions
		TS.TS(6);
		Screen_Console(SW);
		TS.TE(6);

		//Statistics Rendering
		TS.CalcAndRenderStats();

		//*************
		//Swap Buffers
		//*************
		TS.TS(7);
		//glfwSwapInterval(1); //Seems to slow the program to 30fps
		glfwSwapBuffers(window);//Something is wrong here, SUPER expensive
		TS.TE(7);

                //*********************
                //Check and call events
                //*********************
                TS.TS(9);
                glfwPollEvents();
                //glfwWaitEvents();
                Do_Movement();
                TS.TE(9);

                //*************
                //Frame Cleanup
                //*************
		TS.TS(8);
		drawArray.DrawArrayReset();
		drawInstArray.ClearInstDrawArrays();
		TS.TE(8);
		//cout << "FRAME END\n";

		//GLErrorCatch("MainLoop");
	}

	drawArray.ClearDrawArrays();
	glfwTerminate();
}
コード例 #20
0
ファイル: glfwinfo.c プロジェクト: bioinfornatics/glfw
int main(int argc, char** argv)
{
    int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
    GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
    GLint flags, mask;
    GLFWwindow window;

    while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
    {
        switch (ch)
        {
            case 'd':
                debug = GL_TRUE;
                break;
            case 'f':
                forward = GL_TRUE;
                break;
            case 'h':
                usage();
                exit(EXIT_SUCCESS);
            case 'l':
                list = GL_TRUE;
                break;
            case 'm':
                major = atoi(optarg);
                break;
            case 'n':
                minor = atoi(optarg);
                break;
            case 'p':
                if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
                    profile = GLFW_OPENGL_CORE_PROFILE;
                else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
                    profile = GLFW_OPENGL_COMPAT_PROFILE;
                else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
                    profile = GLFW_OPENGL_ES2_PROFILE;
                else
                {
                    usage();
                    exit(EXIT_FAILURE);
                }
                break;
            case 'r':
                if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
                    strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
                else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
                    strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
                else
                {
                    usage();
                    exit(EXIT_FAILURE);
                }
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    argc -= optind;
    argv += optind;

    glfwSetErrorCallback(error_callback);

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

    if (major != 1 || minor != 0)
    {
        glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
        glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
    }

    if (debug)
        glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    if (forward)
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    if (profile != 0)
        glfwWindowHint(GLFW_OPENGL_PROFILE, profile);

    if (strategy)
        glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);

    // We assume here that we stand a better chance of success by leaving all
    // possible details of pixel format selection to GLFW

    window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
    if (!window)
        exit(EXIT_FAILURE);

    glfwMakeContextCurrent(window);

    // Report GLFW version

    glfwGetVersion(&major, &minor, &revision);

    printf("GLFW header version: %u.%u.%u\n",
           GLFW_VERSION_MAJOR,
           GLFW_VERSION_MINOR,
           GLFW_VERSION_REVISION);

    printf("GLFW library version: %u.%u.%u\n", major, minor, revision);

    if (major != GLFW_VERSION_MAJOR ||
        minor != GLFW_VERSION_MINOR ||
        revision != GLFW_VERSION_REVISION)
    {
        printf("*** WARNING: GLFW version mismatch! ***\n");
    }

    printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());

    // Report OpenGL version

    printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));

    major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR);
    minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR);
    revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION);

    printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision);

    // Report OpenGL context properties

    if (major >= 3)
    {
        glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
        printf("OpenGL context flags (0x%08x):", flags);

        if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
            printf(" forward-compatible");
        if (flags & 0)
            printf(" debug");
        putchar('\n');

        printf("OpenGL context flags parsed by GLFW:");

        if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT))
            printf(" forward-compatible");
        if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT))
            printf(" debug");
        putchar('\n');
    }

    if (major > 3 || (major == 3 && minor >= 2))
    {
        glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
        printf("OpenGL profile mask (0x%08x): %s\n", mask, get_profile_name(mask));

        printf("OpenGL profile mask parsed by GLFW: %s\n",
               get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
    }

    printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER));
    printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR));

    if (major > 1)
    {
        printf("OpenGL context shading language version: \"%s\"\n",
               glGetString(GL_SHADING_LANGUAGE_VERSION));
    }

    // Report OpenGL extensions
    if (list)
        list_extensions(major, minor);

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
コード例 #21
0
ファイル: session.hpp プロジェクト: milasudril/glinde
			static const char* versionGet() noexcept
				{return glfwGetVersionString();}
コード例 #22
0
ファイル: Window.cpp プロジェクト: henry4k/konstrukt
void InitWindow()
{
    const int width  = GetConfigInt("window.width",  640);
    const int height = GetConfigInt("window.height", 480);
    const char* title = GetConfigString("window.title", "Konstrukt");

    const bool debug = GetConfigBool("opengl.debug", false);
    const bool vsync = GetConfigBool("opengl.vsync", true);

    LogInfo("Compiled with GLFW %d.%d.%d",
             GLFW_VERSION_MAJOR,
             GLFW_VERSION_MINOR,
             GLFW_VERSION_REVISION);
    LogInfo("Using GLFW %s", glfwGetVersionString());

    assert(g_Window == NULL);
    glfwSetErrorCallback(OnGLFWError);
    if(!glfwInit())
        FatalError("GLFW init failed.");

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_DEPTH_BITS, GetConfigInt("opengl.depth-bits", 24));
    glfwWindowHint(GLFW_STENCIL_BITS, 0);
    glfwWindowHint(GLFW_SAMPLES, GetConfigInt("opengl.samples", 0));
    glfwWindowHint(GLFW_SRGB_CAPABLE, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, debug ? GL_TRUE : GL_FALSE);

    g_Window = glfwCreateWindow(width, height, title, NULL, NULL);
    if(!g_Window)
        FatalError("Window creation failed.");

    glfwGetWindowSize(g_Window, &g_WindowWidth, &g_WindowHeight);
    glfwGetFramebufferSize(g_Window, &g_FramebufferWidth, &g_FramebufferHeight);

    glfwMakeContextCurrent(g_Window);

    if(!flextInit(g_Window))
        FatalError("Failed to load OpenGL extensions.");

    LogInfo("Using OpenGL %s\n"
            "Vendor: %s\n"
            "Renderer: %s\n"
            "GLSL: %s",
            glGetString(GL_VERSION),
            glGetString(GL_VENDOR),
            glGetString(GL_RENDERER),
            glGetString(GL_SHADING_LANGUAGE_VERSION));

    if(vsync)
    {
        if(glfwExtensionSupported("GLX_EXT_swap_control_tear") ||
           glfwExtensionSupported("WGL_EXT_swap_control_tear"))
            glfwSwapInterval(-1); // enable vsync (allow the driver to swap even if a frame arrives a little bit late)
        else
            glfwSwapInterval(1); // enable vsync
    }
    else
    {
        glfwSwapInterval(0); // disable vsync
    }

    glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
    glfwSetInputMode(g_Window, GLFW_STICKY_KEYS, GL_FALSE);
    glfwSetInputMode(g_Window, GLFW_STICKY_MOUSE_BUTTONS, GL_FALSE);

    if(debug)
    {
        if(!FLEXT_ARB_debug_output)
            FatalError("Debug output requested, but it's not supported!");

        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
        glDebugMessageCallbackARB(OnDebugEvent, NULL);
        LogInfo("Debug output supported! You may receive debug messages from your OpenGL driver.");
    }

    glfwSetWindowSizeCallback(g_Window, OnWindowResize);
    glfwSetFramebufferSizeCallback(g_Window, OnFramebufferResize);
    glfwSetMouseButtonCallback(g_Window, OnMouseButtonAction);
    glfwSetScrollCallback(g_Window, OnMouseScroll);
    glfwSetCursorPosCallback(g_Window, OnCursorMove);
    glfwSetKeyCallback(g_Window, OnKeyAction);
}
コード例 #23
0
// Very complex stuff, impossible to explain.
int main(int argc, char *argv [])
{
	//Set the error callback
	glfwSetErrorCallback(onError);

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

	//Set the GLFW window creation hints - these are optional
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //Request a specific OpenGL version
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //Request a specific OpenGL version
	//glfwWindowHint(GLFW_SAMPLES, 4); //Request 4x antialiasing
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	//Declare a window object
	GLFWwindow* window;

	window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT,
		"Screen Space Fluid Rendering",
		NULL /* glfwGetPrimaryMonitor() */,
		NULL);

	if (!window){
		fprintf(stderr, "Failed to open GLFW window.\n");
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	glfwMakeContextCurrent(window);

	// Output some information
	puts(glfwGetVersionString());
	printf("OpenGL version supported %s\n", glGetString(GL_VERSION));

	
	setupCallback(window);
	
	// AssImp init
	// get a handle to the predefined STDOUT log stream and attach
	// it to the logging system. It remains active for all further
	// calls to aiImportFile(Ex) and aiApplyPostProcessing.
	aiLogStream aiStream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT, NULL);
	aiAttachLogStream(&aiStream);

	// --------------------------------------------
	//			Initialize GLEW
	// --------------------------------------------

	glewExperimental = GL_TRUE;
	GLenum err = glewInit();

	//If GLEW hasn't initialized
	if (err != GLEW_OK){
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
		return 1;
	}

	// --------------------------------------------
	//			DevIL init
	// --------------------------------------------

	ilInit();

	/* 
	* Now that we should have a valid GL context, perform our OpenGL
	* initialization, before we enter our main loop.
	*/
	initialize(window);

	mainLoop(window);

	unload(window);

	// We added a log stream to the library, it's our job to disable it
	// again. This will definitely release the last resources allocated
	// by Assimp.
	aiDetachAllLogStreams();

	//Close OpenGL window and terminate GLFW
	glfwDestroyWindow(window);
	//Finalize and clean up GLFW
	glfwTerminate();

	exit(EXIT_SUCCESS);
}
コード例 #24
0
ファイル: main.cpp プロジェクト: iancarnation/AIE_Projects
int main()
{


	// open an OS window using GLFW
	if(!glfwInit())
	{
		fprintf (stderr, "ERROR: could not start GLFW3\n");
		return 1;
	}
	char message[256];
	sprintf (message, "starting GLFW %s", glfwGetVersionString());
	assert (gl_log (message, __FILE__, __LINE__));
	glfwSetErrorCallback (glfw_error_callback);

	// Anti-Aliasing
	glfwWindowHint (GLFW_SAMPLES, 4);

	// get the primary monitor
	GLFWmonitor* mon = glfwGetPrimaryMonitor();

	// this lets us use the video mode for the monitor we pass
	const GLFWvidmode* vmode = glfwGetVideoMode(mon);
		
	//GLFWwindow* window2 = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init",mon/* mon*/, NULL);
	//	if (!window2)
	//		{
	//			fprintf (stderr, "ERROR: could not open window with GLFW3\n");
	//			glfwTerminate();
	//			return 1;
	//		}

	//glfwSetWindowSize (window2, vmode->width, vmode->height);
	//glfwMakeContextCurrent (window2);

	GLFWwindow * window = glfwCreateWindow(640,480,"Hello Triangle", NULL, NULL);
		if (!window)
		{
			fprintf (stderr, "ERROR: could not open window with GLFW3\n");
			glfwTerminate();
			return 1;
		}

	glfwMakeContextCurrent(window);	// set as active 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);

	// tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); // enable depth-testing
	glDepthFunc (GL_LESS);
	// depth-testing interprets a smaller value as "closer"

	//const char* vertex_shader = 
	//"#version 330\n"
	//"in vec3 vp;"
	//"void main () {"
	//" gl_Position = vec4 (vp, 1.0);"
	//"}";

	//const char* fragment_shader = 
	//"#version 330\n"
	//"out vec4 frag_colour;"
	//"void main () {" 
	//" float lerpValue = gl_FragCoord.y / 480.0f;"
	//" frag_colour = mix(vec4 (1.0f, 1.0f, 1.0f, 1.0f), vec4 (0.5, 0.0, 0.5, 1.0), lerpValue);"
	//"}";

	//// Create a shader
	//GLuint vs = glCreateShader (GL_VERTEX_SHADER);
	//// put actual char* into the shader
	//glShaderSource (vs, 1, &vertex_shader, NULL);
	//// compile the shader
	//glCompileShader(vs);
	//printShaderInfoLog(vs);

	//GLuint fs = glCreateShader (GL_FRAGMENT_SHADER);
	//glShaderSource (fs, 1, &fragment_shader, NULL);
	//glCompileShader (fs);
	//printShaderInfoLog(fs);

	//// create the container that holds your shaders
	//GLuint shaderProgram = glCreateProgram ();
	//// attach the shaders you compiled
	//glAttachShader (shaderProgram, fs);
	//glAttachShader (shaderProgram, vs);

	//// this links the shaders together, its kinda like a compile
	//glLinkProgram (shaderProgram);
	//printProgramInfoLog(shaderProgram);

	//std::vector<Quad> v_quads;

	//Quad * tester = new Quad();
	Sprite * richard = new Sprite("simmons.png",384,324,Vector4(1,1,1,1),window);
	//v_quads.push_back(initQuad);

	while (!glfwWindowShouldClose (window)) 
	{
		_update_fps_counter (window);
		// wipe the drawing surface clear
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport (0,0, g_gl_width, g_gl_height);
		glClearColor(0,1,1,1);
		//glUseProgram (shaderProgram);

		//// if key is pressed
		//if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
		//{
		//// make new quad object
		//	Quad newQuad;
		//	v_quads.push_back(newQuad);
		//}

		/*for (int i=0;i<7;i++)
		{
			Quad newQuad;
			v_quads.push_back(newQuad);
		}*/

		// for each quad in vector,  bind its VAO and draw
		/*for(auto quad= v_quads.begin(); quad != v_quads.end(); ++quad)
		{
			glBindVertexArray (quad->m_VAO);
 			glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
		}*/
		
		richard->Draw();
		// glBindVertexArray (0);

		// put the stuff we've been drawing onto the display
		glfwSwapBuffers (window);	
	}



	// close GL context and any other GLFW resources
	glfwTerminate();


	//char* pause = "not";
	//std::cin>> pause;

	return 0;
}
コード例 #25
0
ファイル: main.cpp プロジェクト: iancarnation/AIE_Projects
int main()
{
	//setup to log some GLFW stuff

	char message[256];
	sprintf (message, "starting GLFW %s", glfwGetVersionString ());
	assert (gl_log (message, __FILE__, __LINE__));
	glfwSetErrorCallback (glfw_error_callback);

	//open an OS window using GLFW
	if(!glfwInit())
	{
		fprintf (stderr,"ERROR: could not start GLFW3\n");
		return 1;
	}

	// uncomment these lines if on Apple OS X
	/*	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);
	*/	
	//Anti-Aliasing
	glfwWindowHint (GLFW_SAMPLES, 4);

	//get the primary monitor
	GLFWmonitor* mon = glfwGetPrimaryMonitor ();
	//this lets us the the video mode for the monitor we pass
	const GLFWvidmode* vmode = glfwGetVideoMode (mon);
	GLFWwindow* window = glfwCreateWindow (
		vmode->width, vmode->height, "Extended GL Init",NULL/* mon*/, NULL
		);
	glfwSetWindowSize(window, g_gl_width, g_gl_height);

	if (!window) {
		fprintf (stderr, "ERROR: could not open window with GLFW3\n");
		glfwTerminate();
		return 1;
	}
	//not sure if this works
	//log_gl_params ();

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

	// tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); // enable depth-testing
	glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"

	float speed = 1.0f; // move at 1 unit per second
	float last_position = 0.0f;

	//Quad * tester = new Quad();

	Sprite * richard = new Sprite("./resources/simmons.png", 384, 324, Vector4(1,1,1,1), window); 


	//int matrix_location = glGetUniformLocation (shaderProgram, "matrix");
	//glUniform1i(glGetUniformLocation(shaderProgram, "Texture"), 0);

	Ortho = new Matrix4();
	Orthographic(0, g_gl_width, g_gl_height, 0, 0, -1, Ortho);

	while (!glfwWindowShouldClose (window)) {

		/* add a timer for doing animation
  static double previous_seconds = glfwGetTime ();
  double current_seconds = glfwGetTime ();
  double elapsed_seconds = current_seconds - previous_seconds;
  previous_seconds = current_seconds;
   // reverse direction when going to far left or right
  if (fabs(last_position) > 1.0f) {
    speed = -speed;
  }
  */

		glEnable (GL_CULL_FACE); // cull face
		glCullFace (GL_BACK); // cull back face
		glFrontFace (GL_CW); // GL_CCW for counter clock-wise

		// wipe the drawing surface clear
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//resize window
		glViewport (0, 0, g_gl_width, g_gl_height);

	
		
		  // update the matrix
//  matrix[12] = elapsed_seconds * speed + last_position;
//  last_position = matrix[12];
		//set the shader for this VAO
//		glUseProgram (shaderProgram);
		//Here is where we attach the marix
//		glUniformMatrix4fv (matrix_location, 1, GL_FALSE, matrix);
		//bind the VAO to be drawn
//		glBindVertexArray (VAO);
		// draw points 0-3 from the currently bound VAO with current in-use shader
//		glDrawArrays (GL_TRIANGLES, 0, 3);

		richard->Input();
		richard->Draw();

		// update other events like input handling 
		glfwPollEvents ();
		// put the stuff we've been drawing onto the display
		glfwSwapBuffers (window);


		//When do i exit?
		if (GLFW_PRESS == glfwGetKey (window, GLFW_KEY_ESCAPE)) {
			glfwSetWindowShouldClose (window, 1);
		}
	}

	// close GL context and any other GLFW resources
	glfwTerminate();
	return 0;

}
コード例 #26
0
ファイル: Lesson2.cpp プロジェクト: iancarnation/AIE_Projects
int notmain2()
{
	char message[256];
sprintf (message, "starting GLFW %s", glfwGetVersionString ());
assert (gl_log (message, __FILE__, __LINE__));
glfwSetErrorCallback (glfw_error_callback);

    //open an OS window using GLFW
    if(!glfwInit())
    {
        fprintf (stderr,"ERROR: could not start GLFW3\n");
        return 1;
    }

    // uncomment these lines if on Apple OS X
    /*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, 4);

    GLFWwindow * window = glfwCreateWindow(640,480,"Hello Triangle",NULL,NULL);
    if (!window) {
        fprintf (stderr, "ERROR: could not open window with GLFW3\n");
        glfwTerminate();
        return 1;
    }

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

    // tell GL to only draw onto a pixel if the shape is closer to the viewer
    glEnable (GL_DEPTH_TEST); // enable depth-testing
    glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"

    /* OTHER STUFF GOES HERE NEXT */
	
  float points[] = 
    {
        0.0f,0.5f,0.0f,
        0.5f,-0.5f,0.0f,
        -0.5f,-0.5f,0.0f,

    };
    GLuint VBO = 0;
    glGenBuffers (1, &VBO);
    glBindBuffer (GL_ARRAY_BUFFER, VBO);
    glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (float), points, GL_STATIC_DRAW);

	GLuint VAO = 0;
glGenVertexArrays (1, &VAO);
glBindVertexArray (VAO);
glEnableVertexAttribArray (0);
glBindBuffer (GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

const char* vertex_shader =
"#version 400\n"
"in vec3 vp;"
"void main () {"
"  gl_Position = vec4 (vp, 1.0);"
"}";

const char* fragment_shader =
"#version 400\n"
"out vec4 frag_colour;"
"void main () {"
"  frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"
"}";

//Create a shader
GLuint vs = glCreateShader (GL_VERTEX_SHADER);
//put the actual char* into the shader 
glShaderSource (vs, 1, &vertex_shader, NULL);
//Compile the shader 
glCompileShader (vs);


GLuint fs = glCreateShader (GL_FRAGMENT_SHADER);
glShaderSource (fs, 1, &fragment_shader, NULL);
glCompileShader (fs);


//Create the container that holds your shaders
GLuint shaderProgram = glCreateProgram ();
//attach the shaders you compiled
glAttachShader (shaderProgram, fs);
glAttachShader (shaderProgram, vs);
//this is links the shaders together, its kinda like a compile
glLinkProgram (shaderProgram);

while (!glfwWindowShouldClose (window)) {
  // wipe the drawing surface clear
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glUseProgram (shaderProgram);
  glBindVertexArray (VAO);
  // draw points 0-3 from the currently bound VAO with current in-use shader
  glDrawArrays (GL_TRIANGLES, 0, 3);
  // update other events like input handling 
  glfwPollEvents ();
  // put the stuff we've been drawing onto the display
  glfwSwapBuffers (window);
}

    // close GL context and any other GLFW resources
    glfwTerminate();
    return 0;


}
コード例 #27
0
ファイル: glfw_main.cpp プロジェクト: SantanMaddi/RiftRay
int main(int argc, char** argv)
{
    LOG_INFO("RiftRay version %s", pRiftRayVersion);
#if defined(_WIN32)
    LOG_INFO("Windows build.");
#elif defined(_LINUX)
    LOG_INFO("Linux build.");
#elif defined(_MACOS)
    LOG_INFO("MacOS build.");
#endif

    bool useOpenGLCoreContext = false;

    g_renderMode.outputType = RenderingMode::OVR_SDK;

#ifdef USE_CORE_CONTEXT
    useOpenGLCoreContext = true;
#endif

#ifdef _LINUX
    // Linux driver seems to be lagging a bit
    useOpenGLCoreContext = false;
#endif

    LOG_INFO("Using GLFW3 backend.");
    LOG_INFO("Compiled against GLFW %i.%i.%i",
        GLFW_VERSION_MAJOR,
        GLFW_VERSION_MINOR,
        GLFW_VERSION_REVISION);
    int major, minor, revision;
    glfwGetVersion(&major, &minor, &revision);
    LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision);
    LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString());

    // Command line options
    for (int i=0; i<argc; ++i)
    {
        const std::string a = argv[i];
        LOG_INFO("argv[%d]: %s", i, a.c_str());
        if (!a.compare("-sdk"))
        {
            g_renderMode.outputType = RenderingMode::OVR_SDK;
        }
        else if (!a.compare("-client"))
        {
            g_renderMode.outputType = RenderingMode::OVR_Client;
        }
        else if (!a.compare("-core"))
        {
            useOpenGLCoreContext = true;
        }
        else if (!a.compare("-compat"))
        {
            useOpenGLCoreContext = false;
        }
    }

    LoadConfigFile();

    g_app.initHMD();

    GLFWwindow* l_Window = NULL;
    glfwSetErrorCallback(ErrorCallback);
    if (!glfwInit())
    {
        exit(EXIT_FAILURE);
    }

#ifdef __APPLE__
    // Set the working directory to the Resources dir of the .app bundle
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
    char path[PATH_MAX];
    CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX);
    CFRelease(resourcesURL);
    strcat( path, "/shaders" );
    struct stat sb;
    if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode))
        chdir(path);
#endif

#ifndef _LINUX
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
#  if defined(_MACOS)
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
#  else
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#  endif
#endif //ndef _LINUX
    if (useOpenGLCoreContext)
    {
        LOG_INFO("Using OpenGL core context.");
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    }
    else
    {
#ifndef _LINUX
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
#endif
    }

    glfwWindowHint(GLFW_SAMPLES, 0);
#ifdef _DEBUG
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif

    std::string windowTitle = "RiftRay-v" + std::string(pRiftRayVersion);
#ifdef USE_OCULUSSDK
    const ovrSizei sz = g_app.getHmdResolution();
    const ovrVector2i pos = g_app.getHmdWindowPos();

    if (g_app.UsingDebugHmd() == true)
    {
        // Create a normal, decorated application window
        LOG_INFO("Using Debug HMD mode.");
        windowTitle += "-GLFW-DebugHMD";

        l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL);
        g_app.m_dashScene.m_bDraw = false;
        g_renderMode.outputType = RenderingMode::Mono_Buffered;
    }
    else if (g_app.UsingDirectMode())
    {
        LOG_INFO("Using Direct to Rift mode.");
        windowTitle += "-GLFW-Direct";

        l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL);

#if defined(_WIN32)
        g_app.AttachToWindow((void*)glfwGetWin32Window(l_Window));
#endif
    }
    else
    {
        LOG_INFO("Using Extended desktop mode.");
        windowTitle += "-GLFW-Extended";

        glfwWindowHint(GLFW_DECORATED, 0);
        l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL);
        glfwWindowHint(GLFW_DECORATED, 1);
        glfwSetWindowPos(l_Window, pos.x, pos.y);
    }

    resize(l_Window, sz.w, sz.h); // inform AppSkeleton of window size

#else
    const glm::vec2 sz(800, 600);
    // Create a normal, decorated application window
    LOG_INFO("Using No VR SDK.");
    windowTitle += "-GLFW-NoVRSDK";
    g_renderMode.outputType = RenderingMode::Mono_Buffered;

    l_Window = glfwCreateWindow(sz.x, sz.y, windowTitle.c_str(), NULL, NULL);
    resize(l_Window, sz.x, sz.y); // inform AppSkeleton of window size
#endif //USE_OSVR|USE_OCULUSSDK

    if (!l_Window)
    {
        LOG_INFO("Glfw failed to create a window. Exiting.");
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

#ifdef USE_OCULUSSDK
    // Required for SDK rendering (to do the buffer swap on its own)
#  if defined(_WIN32)
    g_app.setWindow(glfwGetWin32Window(l_Window));
#  elif defined(__linux__)
    g_app.setWindow(glfwGetX11Display());
#  endif
#endif

    glfwMakeContextCurrent(l_Window);
    glfwSetWindowSizeCallback(l_Window, resize);
    glfwSetMouseButtonCallback(l_Window, mouseDown);
    glfwSetCursorPosCallback(l_Window, mouseMove);
    glfwSetScrollCallback(l_Window, mouseWheel);
    glfwSetKeyCallback(l_Window, keyboard);

    memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int));

    FindPreferredJoystick();

    // Log system monitor information
    const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor();
    int monitorCount = 0;
    GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount);
    for (int i=0; i<monitorCount; ++i)
    {
        GLFWmonitor* pCur = ppMonitors[i];
        const GLFWvidmode* mode = glfwGetVideoMode(pCur);
        if (mode != NULL)
        {
            LOG_INFO("Monitor #%d: %dx%d @ %dHz %s",
                i,
                mode->width,
                mode->height,
                mode->refreshRate,
                pCur==pPrimary ? "Primary":"");
        }
    }

    printGLContextInfo(l_Window);
    glfwMakeContextCurrent(l_Window);
    g_pHMDWindow = l_Window;


    // Don't forget to initialize Glew, turn glewExperimental on to
    // avoid problems fetching function pointers...
    glewExperimental = GL_TRUE;
    const GLenum l_Result = glewInit();
    if (l_Result != GLEW_OK)
    {
        LOG_INFO("glewInit() error.");
        exit(EXIT_FAILURE);
    }

#ifdef _DEBUG
    // Debug callback initialization
    // Must be done *after* glew initialization.
    glDebugMessageCallback(myCallback, NULL);
    glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
    glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0,
        GL_DEBUG_SEVERITY_NOTIFICATION, -1, "Start debugging");
    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
#endif

#ifdef USE_ANTTWEAKBAR
    LOG_INFO("Using AntTweakbar.");
    TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL);
    InitializeBar();
#endif

    LOG_INFO("Calling initGL...");
    g_app.initGL();
    LOG_INFO("Calling initVR...");
    g_app.initVR();
    LOG_INFO("initVR complete.");

    SetVsync(1); // default to vsync on

    StartShaderLoad();

    while (!glfwWindowShouldClose(l_Window))
    {
        const bool tapped = g_app.CheckForTapOnHmd();
        if (tapped && (g_receivedFirstTap == false))
        {
            g_app.RecenterPose();
            g_receivedFirstTap = true;
        }

        glfwPollEvents();
        joystick();
        timestep();
        g_fps.OnFrame();
        if (g_dynamicallyScaleFBO)
        {
            DynamicallyScaleFBO();
        }

#ifdef USE_ANTTWEAKBAR
        TwRefreshBar(g_pTweakbar);
        TwRefreshBar(g_pShaderTweakbar);
#endif

        displayToHMD();

#ifndef _LINUX
        // Indicate FPS in window title
        // This is absolute death for performance in Ubuntu Linux 12.04
        {
            std::ostringstream oss;
            oss << windowTitle
                << " "
                << static_cast<int>(g_fps.GetFPS())
                << " fps";
            glfwSetWindowTitle(l_Window, oss.str().c_str());
            if (g_AuxWindow != NULL)
                glfwSetWindowTitle(g_AuxWindow, oss.str().c_str());
        }
#endif
        const float dumpInterval = 1.f;
        if (g_logDumpTimer.seconds() > dumpInterval)
        {
            LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS()));
            g_logDumpTimer.reset();
        }

        // Optionally display to auxiliary mono view
        if (g_AuxWindow != NULL)
        {
            glfwMakeContextCurrent(g_AuxWindow);
            glClearColor(0.f, 0.f, 0.f, 0.f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            ///@note VAOs *cannot* be shared between contexts.
            ///@note GLFW windows are inextricably tied to their own unique context.
            /// For these two reasons, calling draw a third time for the auxiliary window
            /// is not possible. Furthermore, it is not strictly desirable for the extra
            /// rendering cost.
            /// Instead, we share the render target texture from the stereo render and present
            /// just the left eye to the aux window.
            if (g_drawToAuxWindow)
            {
                presentSharedFboTexture();
            }

#ifdef USE_ANTTWEAKBAR
            TwDraw(); ///@todo Should this go first? Will it write to a depth buffer?
#endif

            glfwSwapBuffers(g_AuxWindow);

            if (glfwWindowShouldClose(g_AuxWindow))
            {
                destroyAuxiliaryWindow(g_AuxWindow);
            }

            // Set context to Rift window when done
            glfwMakeContextCurrent(l_Window);
        }
    }

    g_app.exitVR();
    glfwDestroyWindow(l_Window);
    glfwTerminate();

    exit(EXIT_SUCCESS);
}
コード例 #28
0
int main() {
	char message[256];
	sprintf(message, "staring glfw %s", glfwGetVersionString());
	assert(GL_log(message, __FILE__, __LINE__));
	glfwSetErrorCallback(glfw_error_callback);

	//open and OS window using glfw
	if (!glfwInit()) {
		fprintf (stderr,"ERROR: could not start GLFW3\n");
		return 1;
	}

	glfwWindowHint(GLFW_SAMPLES, 4);

	//get primary monitor
	GLFWmonitor* mon = glfwGetPrimaryMonitor();

	//this lets us use the video mode for the monitor we pass
	const GLFWvidmode* vmode = glfwGetVideoMode(mon);

	GLFWwindow* window = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init", NULL/*mon*/, NULL);

	glfwSetWindowSize(window, g_gl_width, g_gl_height);

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

	glfwMakeContextCurrent(window);

	//start glew extention handler
	glewExperimental = GL_TRUE;
	glewInit();

	//get version info
	const GLubyte * renderer = glGetString (GL_RENDERER); //get renderer string
	const GLubyte * version = glGetString (GL_VERSION); //get version as a string
	printf ("Renerer: %s\n", renderer);
	printf ("OpenGL version supported %s\n", version);

	//tell GL to only draw onto a pixel if the shape is closer to the viewer
	glEnable (GL_DEPTH_TEST); //enable depth testing
	glDepthFunc (GL_LESS);

	/* other stuff goes here */

	/*float points[] = {
		0.0f, 0.5, 0.0f,
		0.5f, -0.5f, 0.0f,
		-0.5f, -0.5f, 0.0f
	};

	GLuint VBO = 0;
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, 9 * sizeof (float), points, GL_STATIC_DRAW);
	GLuint VAO = 0;
	glGenVertexArrays(1, &VAO);
	glBindVertexArray(VAO);
	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

	const char* vertex_shader =
		"#version 330\n"
		"in vec3 pos;\n"
		"void main() {"
		"gl_Position = vec4(pos, 1.0);\n"
		"}";
	const char* fragment_shader =
		"#version 330\n"
		"out vec4 frag_colour;\n"
		"void main() {"
		"frag_colour = vec4(0.5, 0.0, 0.5, 1.0);\n"
		"}";

	//create a shader
	GLuint vs = glCreateShader(GL_VERTEX_SHADER);
	//put the actual cha* int the shader
	glShaderSource(vs, 1, &vertex_shader, NULL);
	//compile the shader
	glCompileShader(vs);
	PrintShaderInfoLog(vs);
	GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fs, 1, &fragment_shader, NULL);
	glCompileShader(fs);
	PrintShaderInfoLog(fs);
	//create the container that holds the shaders
	GLuint shaderProgram = glCreateProgram();
	//attach the shaders
	glAttachShader(shaderProgram, fs);
	glAttachShader(shaderProgram, vs);
	//this inks the shaders together, its kinda like a compile
	glLinkProgram(shaderProgram);
	PrintProgramInfoLog(shaderProgram);



	//new object
	float Spoints[] = {
		-0.25f, -0.5f, 0.0f,
		-0.25f, -0.75f, 0.0f,
		0.25f, -0.5f, 0.0f,
		0.25f, -0.75f, 0.0f
	};

	GLuint VBO2 = 0;
	glGenBuffers(1, &VBO2);
	glBindBuffer(GL_ARRAY_BUFFER, VBO2);
	glBufferData(GL_ARRAY_BUFFER, 12 * sizeof (float), Spoints, GL_STATIC_DRAW);
	GLuint VAO2 = 0;
	glGenVertexArrays(1, &VAO2);
	glBindVertexArray(VAO2);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);

	const char* vertex_shader2 =
		"#version 330\n"
		"in vec3 vp;\n"
		"void main() {"
		"gl_position = vec4(vp, 2.0);\n"
		"}";
	const char* fragment_shader2 =
		"#version 330\n"
		"out vec4 frag_colour;\n"
		"void main() {"
		"frag_colour = vec4(0.5, 0.0, 0.0, 1.0);\n"
		"}";

	//create a shader
	GLuint vs2 = glCreateShader(GL_VERTEX_SHADER);
	//put the actual char* in the shader
	glShaderSource(vs2, 1, &vertex_shader2, NULL);
	//compile the shader
	glCompileShader(vs2);
	PrintShaderInfoLog(vs2);
	GLuint fs2 = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fs2, 1, &fragment_shader2, NULL);
	glCompileShader(fs2);
	PrintShaderInfoLog(fs2);
	//create the container that holds the shaders
	GLuint secondProgram = glCreateProgram();
	//attach the shaders
	glAttachShader(secondProgram, fs2);
	glAttachShader(secondProgram, vs2);
	//this inks the shaders together, its kinda like a compile
	glLinkProgram(secondProgram);
	PrintProgramInfoLog(secondProgram);
	*/

	Ortho = new Matrix4();
	Orthographic(0, g_gl_width, g_gl_height, 0, 0, -1, Ortho);

	//Quad * tester1 = new Quad();

	AnimatedSprite * tester = new AnimatedSprite("../resources/MegamanXSheet.xml", window);

	tester->SetAnimation("teleport", ONCE);
	

	while (!glfwWindowShouldClose(window)) {
		//_update_fps_counter(window);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.5);
		glEnable(GL_ALPHA);
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
		glFrontFace(GL_CW);

		//wipe the drawing surface
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//resize window
		glViewport (0, 0, g_gl_width, g_gl_height);
		
		tester->Update();
		//tester->Draw();
		//tester->Input();
		
		//update other events like input handling
		glfwPollEvents();
		//put the stuff we've been drawing into the display
		glfwSwapBuffers(window);
		
		resetDeltaTime();
		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) {
			glfwSetWindowShouldClose(window, 1);
		}
	}

	//close GL context and any other GLFW resources
	//delete Ortho;
	//delete tester;
	glfwTerminate();
	return 0;
}
コード例 #29
0
ファイル: window_gl.cpp プロジェクト: Vtec234/psi-engine
std::unique_ptr<psi_serv::IWindowService> psi_serv::start_gl_window_service(GLWindowServiceArgs args) {
	// -- START GLFW --
	if (glfwInit() == 0)
		throw std::runtime_error("Failed to initialize GLFW.");

	glfwSetErrorCallback(
		[] (GLint code, char const* desc) {
			psi_log::error("GLFW") << "(" << code << "): " << desc << "\n";
		}
	);

	psi_log::info("GLWindowService") << "Initialized GLFW " << glfwGetVersionString() << "\n";

	// -- START GLFW WINDOW --
	// GL version 4.4
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
	// No backwards compatibility
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
	// Resizability of this window
	glfwWindowHint(GLFW_RESIZABLE, args.resizable);
	// Whether the window is always on top
	glfwWindowHint(GLFW_FLOATING, args.always_on_top);
	// How many samples to take for anti-aliasing (MSAA)
	glfwWindowHint(GLFW_SAMPLES, args.samples);
	// Whether it's a debug context
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, args.debug);
	// sets the window to be sRGB capable, meaning it can convert linear output from shader to sRGB in framebuffer
	glfwWindowHint(GLFW_SRGB_CAPABLE, true);

	auto window = glfwCreateWindow(args.width, args.height, args.title, nullptr, nullptr);
	if (window == nullptr)
		throw std::runtime_error("Failed to create a GLFW window.");

	// key presses are remembered until polled
	glfwSetInputMode(window, GLFW_STICKY_KEYS, true);

	// create the service and map its address to the user pointer in GLFW
	auto service = new GLWindowService(window);
	glfwSetWindowUserPointer(window, service);

	glfwSetFramebufferSizeCallback(window,
		[] (GLFWwindow* win, int width, int height) {
			if (width <= 1 || height <= 1)
				return;

			static_cast<GLWindowService*>(glfwGetWindowUserPointer(win))->framebuffer_size_callback(width, height);
		}
	);
	service->framebuffer_size_callback(args.width, args.height);

	glfwSetKeyCallback(window,
		[] (GLFWwindow* win, int key, int scancode, int action, int mods) {
			static_cast<GLWindowService*>(glfwGetWindowUserPointer(win))->key_pressed_callback(key, scancode, action, mods);
		}
	);

	glfwSetMouseButtonCallback(window,
		[] (GLFWwindow* win, int button, int action, int mods) {
			static_cast<GLWindowService*>(glfwGetWindowUserPointer(win))->mouse_pressed_callback(button, action, mods);
		}
	);


	glfwSetCursorPosCallback(window,
		[] (GLFWwindow* win, double x, double y) {
			static_cast<GLWindowService*>(glfwGetWindowUserPointer(win))->cursor_moved_callback(x, y);
		}
	);

	glfwMakeContextCurrent(window);

	// -- INITIALIZE OPENGL --
	auto load_status = gl::sys::LoadFunctions();
	if (!load_status)
		throw std::runtime_error(std::string("OpenGL Core ") + std::to_string(gl::sys::GetMajorVersion()) + "." + std::to_string(gl::sys::GetMinorVersion()) + " initialization failed.\n"
		+ "Number of functions that failed to load: " + std::to_string(load_status.GetNumMissing()));

	gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS);
	gl::DebugMessageCallback(gl_error_callback, nullptr);

	psi_log::info("GLWindowService") << "Initialized OpenGL Core " << gl::sys::GetMajorVersion() << "." << gl::sys::GetMinorVersion() << "\n";

	// -- RETURN SERVICE --
	return std::unique_ptr<IWindowService>(service);
}
コード例 #30
0
ファイル: Game_Init.cpp プロジェクト: ishellstrike/Space
int Game::Initialize(){
    
    LOG(info) << "Jarg initialization start";
    glfwSetErrorCallback([](int a,const char* description){LOG(error) << description;});

    int glfwErrorCode = glfwInit();
    if (!glfwErrorCode)
    {
        LOG(error) << "glfwInit error " << glfwErrorCode;
        return glfwErrorCode;
    }

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, Game::MAJOR_GL);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, Game::MINOR_GL);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    monitor = nullptr;
    if(fullscreen)
    {
        monitor = glfwGetPrimaryMonitor();
    }

    window = glfwCreateWindow(width, height, title.c_str(), monitor, nullptr);
    if (!window)
    {
        glfwTerminate();
        LOG(fatal) << "Ошибка создания окна GLFW.";
        return false;
    }
    glfwMakeContextCurrent(window);
    //glfwSetWindowTitle(window, AutoVersion::GetTitle().c_str());

    glfwSwapInterval(0);

    if (glewInit() != GLEW_OK) 
    {
        LOG(fatal) << "GLEW не инициализирован.";
        return false;
    }

    GameObject go;
    go.seed = 123;
    for (int i =0; i<100; i++)
    {
        GenerateStar(&go);
    }

    int glVersion[2] = {-1, -1};
    glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]); 
    glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]); 

    LOG(info) << "Renderer: " << glGetString(GL_RENDERER);
    LOG(info) << "Vendor: " <<  glGetString(GL_VENDOR);
    LOG(info) << "Version: " <<  glGetString(GL_VERSION);
    LOG(info) << "GLSL version: " <<  glGetString(GL_SHADING_LANGUAGE_VERSION);
    LOG(info) << "using OpenGL: " << std::to_string(glVersion[0]) << "." << std::to_string(glVersion[1]);
    LOG(info) << "glfw: " << glfwGetVersionString();

    Keyboard::Initialize();
    glfwSetKeyCallback(window, [](GLFWwindow *win, int key, int scancode, int action, int mods){Keyboard::SetKey(key, scancode, action, mods);});

    Mouse::Initialize(window);
    Mouse::SetWindowSize(width, height);
    //	Mouse::SetFixedPosState(true);
    glfwSetCursorPosCallback(window, [](GLFWwindow *window, double xpos, double ypos){Mouse::SetCursorPos(xpos, ypos);});
    glfwSetCursorEnterCallback(window, [](GLFWwindow *window, int entered){Mouse::CursorClientArea(entered);});	
    glfwSetWindowFocusCallback(window, [](GLFWwindow *window, int focused){Mouse::WindowFocus(focused);});
    glfwSetMouseButtonCallback(window, [](GLFWwindow *window, int a, int b, int c){Mouse::SetButton(a, b, c);});
    glfwSetWindowSizeCallback(window, [](GLFWwindow *window, int a, int b){Game::Resize(a, b); Mouse::SetWindowSize(a, b);});
    glfwSetScrollCallback(window, [](GLFWwindow *window, double a, double b){Mouse::Scroll(b);});
    wire = 1;
    spd = 1;

    //////////////////////////////////////////////////////////////////////////
    LinesShader = std::shared_ptr<BasicJargShader>(new BasicJargShader());
    LinesShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/colored.glsl");
    LinesShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/colored.glsl");
    LinesShader->Link();
    mvpLine = LinesShader->locateVars("MVP");

    TextureShader = std::shared_ptr<BasicJargShader>(new BasicJargShader());
    TextureShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/textured.glsl");
    TextureShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/textured.glsl");
    TextureShader->Link();
    mvpTex = TextureShader->locateVars("MVP");

    FXAAShader = std::shared_ptr<BasicJargShader>(new BasicJargShader());
    FXAAShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/fxaa.glsl");
    FXAAShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/fxaa.glsl");
    FXAAShader->Link();

    BasicShader = std::shared_ptr<BasicJargShader>(new BasicJargShader());
    BasicShader->loadShaderFromSource(GL_VERTEX_SHADER, "Shaders/minnaert.glsl");
    BasicShader->loadShaderFromSource(GL_FRAGMENT_SHADER, "Shaders/minnaert.glsl");
    BasicShader->loadShaderFromSource(GL_TESS_CONTROL_SHADER, "Shaders/minnaert.glsl");
    BasicShader->loadShaderFromSource(GL_TESS_EVALUATION_SHADER, "Shaders/minnaert.glsl");
    BasicShader->Link();
    BasicShader->UpdateUniforms();
    BasicShader->locateVars("transform.viewProjection"); //var0
    BasicShader->locateVars("transform.model"); //var1
    BasicShader->locateVars("transform.normal"); //var2
    BasicShader->locateVars("material.texture");

    testtex = std::shared_ptr<Texture>(new Texture());
    testtex->Empty(vec2(256,256));

    uptex = std::shared_ptr<Texture>(new Texture());
    uptex->Load("up.png");

    //////////////////////////////////////////////////////////////////////////

    light.position = vec4(5.0f, 12.0f, 3.0f, 1.0f);
    light.ambient = vec4(0.2f, 0.2f, 0.2f, 1.0f);
    light.diffuse = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    light.specular = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    light.attenuation = vec3(0.000f, 0.0f, 0.00000f);

    batched = std::unique_ptr<Batched>(new Batched());
    batched->Initialize(TextureShader.get(), LinesShader.get());

    font = std::unique_ptr<Font>(new Font());
    font->Initialize();
    //actually not load json
    if(!font->Create("font.json")){
        LOG(error) << "failed to load\process font.json";
    }

    WindowsDesigner();

    camera = std::unique_ptr<Camera>(new Camera());
    camera->SetViewport(0, 0, width, height);
    camera->SetPosition(vec3(2,2,2));
    camera->SetLookAt(vec3(0));
    gt = std::unique_ptr<GameTimer>(new GameTimer);

    Generation gen;

    rs = new QuadTreePlane();
    rs->Init(BasicShader, *camera);

    auto tex = std::shared_ptr<Texture>(new Texture());
    tex->Load("normal.png");

    icos = std::unique_ptr<Mesh>(new Mesh(Cube::getMesh()));
    icos->Bind();
    icos->shader = BasicShader;
    icos->material = std::shared_ptr<Material>(new Material());
    icos->material->texture = tex;

    //test.LoadBinary("untitled.m");
    test.Bind();
    for (int i = 0; i<test.meshes.size(); i++)
    {
        test.meshes[i]->shader = BasicShader;
    }

    return true;
}