bool BaseApplication::createWindow(const char* title, int width, int height) {

	if (glfwInit() == GL_FALSE)
		return false;

	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
	if (m_window == nullptr) {
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(m_window);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED) {
		glfwDestroyWindow(m_window);
		glfwTerminate();
		return false;
	}

	glfwSetWindowSizeCallback(m_window, [](GLFWwindow*, int w, int h){ glViewport(0, 0, w, h); });

	glClearColor(1, 1, 1, 1);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	
	return true;
}
Esempio n. 2
0
    /**
     * @brief initializeGL sets variables up.
     */
    void initializeGL(){

        initializeOpenGLFunctions();

        #ifdef PIC_WIN32
            if(ogl_LoadFunctions() == ogl_LOAD_FAILED) {
                printf("OpenGL functions are not loaded!\n");
            }
        #endif

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

        //reading an input image
        img.Read("../data/input/bottles.hdr");
        img.generateTextureGL();

        //creating a screen aligned quad
        pic::QuadGL::getProgram(program,
                                pic::QuadGL::getVertexProgramV3(),
                                pic::QuadGL::getFragmentProgramForView());

        quad = new pic::QuadGL(true);

        //allocating a new filter for simple tone mapping
        tmo = new pic::FilterGLColorConv(new pic::ColorConvGLRGBtosRGB());

        //allocating Drago et al.'s TMO
        drago_tmo = new pic::DragoTMOGL();

        //allocating Reinhard et al.'s TMO
        reinhard_tmo = new pic::ReinhardTMOGL();
    }
ApplicationFail Application::Init() {
    BeforeInit();

    if ( glfwInit() == false ) { return ApplicationFail::GLFW_INIT; }

    window_glfw_ = glfwCreateWindow( 1280, 720, name_string_.c_str(), nullptr, nullptr );
    if ( window_glfw_ == nullptr ) {
        glfwTerminate();
        return ApplicationFail::GLFW_CREATE_WINDOW;
    }
    glfwMakeContextCurrent( window_glfw_ );

    if ( ogl_LoadFunctions() == ogl_LOAD_FAILED ) {
        glfwDestroyWindow( window_glfw_ );
        glfwTerminate();
        return ApplicationFail::OGL_LOAD_FUNCTIONS;
    }

    const int OGL_MAJOR = ogl_GetMajorVersion();
    const int OGL_MINOR = ogl_GetMinorVersion();
    printf( "OpenGL Version: %i.%i\n", OGL_MAJOR, OGL_MINOR );

    glClearColor( 0.25f, 0.25f, 0.25f, 1.0f );
    glEnable( GL_DEPTH_TEST );

    time_previous_d_ = glfwGetTime();

    InputDevice::Init( window_glfw_ );

    AfterInit();

    return ApplicationFail::NONE;
}
Esempio n. 4
0
bool App::StartUp()
{
	if (glfwInit() == false)
		return false;
	
	window = glfwCreateWindow(m_wWidth, m_wHeight, "Physics", nullptr, nullptr);
	if (window == nullptr)
	{
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(window);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(window);
		glfwTerminate();
		return false;
	}

	std::cout << "OpenGL loaded" << std::endl;

	//m_bar = 
	_gameCamera.SetInputWindow(window);


	keypress = false;

	m_clearColour = glm::vec4(1.0f, 1.0f, 1.00f, 1.0f);
	return true;
}
Esempio n. 5
0
Renderer* Init(Settings vs)
{
	assert(!initted);
	if (initted) return 0;

	// no mode set, find an ok one
	if ((vs.width <= 0) || (vs.height <= 0)) {
		const std::vector<VideoMode> modes = GetAvailableVideoModes();
		assert(!modes.empty());

		vs.width = modes.front().width;
		vs.height = modes.front().height;
	}

	WindowSDL *window = new WindowSDL(vs, "Pioneer");
	width = window->GetWidth();
	height = window->GetHeight();

	const int didLoad = ogl_LoadFunctions();
	if (!didLoad)
		Error("glLoadGen failed to load functions.\n");

	{
		std::ostringstream buf;
		write_opengl_info(buf);

		FILE *f = FileSystem::userFiles.OpenWriteStream("opengl.txt", FileSystem::FileSourceFS::WRITE_TEXT);
		if (!f)
			Output("Could not open 'opengl.txt'\n");
		const std::string &s = buf.str();
		fwrite(s.c_str(), 1, s.size(), f);
		fclose(f);
	}

	if (ogl_ext_EXT_texture_compression_s3tc == ogl_LOAD_FAILED) {
		Error("OpenGL extension GL_EXT_texture_compression_s3tc not supported.\nPioneer can not run on your graphics card as it does not support compressed (DXTn/S3TC) format textures.");
	}

	// We deliberately ignore the value from GL_NUM_COMPRESSED_TEXTURE_FORMATS, because some drivers
	// choose not to list any formats (despite supporting texture compression). See issue #3132.
	// This is (probably) allowed by the spec, which states that only formats which are "suitable
	// for general-purpose usage" should be enumerated.
	
	Renderer *renderer = new RendererOGL(window, vs);

	Output("Initialized %s\n", renderer->GetName());

	std::ostringstream dummy;
	dump_and_clear_opengl_errors(dummy);

	initted = true;

	MaterialDescriptor desc;
	desc.effect = EFFECT_VTXCOLOR;
	desc.vertexColors = true;
	vtxColorMaterial = renderer->CreateMaterial(desc);
	vtxColorMaterial->IncRefCount();

	return renderer;
}
Esempio n. 6
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	/* add command line argument "classic" for a pre-3.x context */
	if ((argc != 2) || (strcmp(argv[1], "classic") != 0)) {
		glutInitContextVersion(3, 3);
		glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
	}
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	int windowID = glutCreateWindow("Stenciltest");
	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glutDestroyWindow(windowID);
		return 1;
	}

	init();
	readback_buffer();
	writeback_buffer();
	readback_buffer();
	glutDisplayFunc(draw);
	glutKeyboardFunc(keyboard);
	glutMainLoop();

	return 0;
}
Esempio n. 7
0
bool initWindow(int width, int height) {
    if (!glfwInit()) {
        std::cerr << "Couldn't init GLFW.\n";
        return false;
    }

    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 5);
    //glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    //glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
    if (!glfwOpenWindow(width, height, 8, 8, 8, 0, 0, 8, GLFW_WINDOW)) {
        std::cerr << "Couldn't open window.\n";
        return false;
    }

    if (ogl_LoadFunctions() != ogl_LOAD_SUCCEEDED) {
        std::cerr << "Couldn't init OpenGL functions.\n";
        return false;
    }

    if (ogl_IsVersionGEQ(1, 5)) {
        std::cerr << "OpenGL 1.5 not supported.\n";
        return false;
    }

    glfwSwapInterval(1);
    glViewport(0, 0, width, height);

    return true;
}
bool Application::startup()
{
	if (glfwInit() == false)
	{
		return false;
	}

	this->m_window = glfwCreateWindow(1280, 720, "Computer Graphics", nullptr, nullptr);
	if (this->m_window == nullptr)
	{
		return false;
	}

	glfwMakeContextCurrent(this->m_window);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(this->m_window);
		glfwTerminate();
		return false;
	}

	int major_version = ogl_GetMajorVersion();
	int minor_version = ogl_GetMinorVersion();
	printf("successfully loaded OpenGL version %d.%d\n", major_version, minor_version);

	return true;
}
Esempio n. 9
0
int Window::InitializeGLFW()
{
  if (!glfwInit())
    return -1;

  window_ = glfwCreateWindow(width_, height_, title_.c_str(), nullptr, nullptr);

  if (!window_)
  {
    glfwTerminate();
    return -1;
  }

  glfwMakeContextCurrent(window_);
  glfwSetWindowUserPointer(window_, this);

  ogl_LoadFunctions();

  glfwSetMouseButtonCallback(window_, StaticHandleMouseButton);
  glfwSetCursorPosCallback(window_, StaticHandleMouseMove);
  glfwSetKeyCallback(window_, StaticHandleKey);
  glfwSetWindowSizeCallback(window_, StaticReshape);

  return 0;
}
Esempio n. 10
0
int OglEngine::Init()
{
	_oglContext->Init();

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		return 0;
	}

#if _DEBUG
	ogl_LoadDebugFunctions();
#endif

	// Initialize shader cache.
	_shaderCache = std::make_unique<OglShaderCache>();
	Word defaultShader = "PositionTexture";
	if (!_shaderCache->GetShaderProgram(defaultShader, &_currentShader))
	{
		Log("There was a problem when looking for the shader " + defaultShader);
		_currentShader = _shaderCache->GetDefaultShaderProgram();
	}

	_textureCache = std::make_unique<OglTextureCache>();
	TextureObject textureObj;
	_textureCache->GetTexture("", &textureObj);

	_renderBatch = std::make_unique<OglRenderBatch>(_shaderCache.get(), _textureCache.get());

	_renderFrame = std::make_unique<OglRenderFrame>(_shaderCache.get());
	_renderFrame->Init();

	return 0;
}
bool Application::BaseStartup() 
{
	if (glfwInit() == false)
		return false;

	window = glfwCreateWindow(1280, 720,
	                          "Computer Graphics",
	                          nullptr, nullptr);

	if (window == nullptr)
	{
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(window);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(window);
		glfwTerminate();
		return false;
	}

	Gizmos::create();

	glClearColor(0.25f, 0.25f, 0.25f, 1);

	return Startup();
}
Esempio n. 12
0
int Application::startup()
{
	if (glfwInit() == false)
		return -1;

	window = glfwCreateWindow(1280, 720, "Computer Graphics", nullptr, nullptr);

	if (window == nullptr)
		glfwTerminate();

	glfwMakeContextCurrent(window);

	//the rest of our code goes here!
	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(window);
		glfwTerminate();
		return -3;
	}

	//testing what version of OpenGL we are running
	auto major = ogl_GetMajorVersion();
	auto minor = ogl_GetMinorVersion();
	printf_s("GL: %i.%i\n", major, minor);

	return 1;
}
Esempio n. 13
0
bool GLApplication::InitializeOpenGL()
{
	if (glfwInit() == false)
		return false;

	m_pWindow = glfwCreateWindow(m_windowWidth, m_windowHeight, m_appTitle.c_str(), nullptr, nullptr);

	if (m_pWindow == nullptr)
	{
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(m_pWindow);
	//glfwSetInputMode(m_pWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(m_pWindow);
		glfwTerminate();
		return false;
	}

	auto major = ogl_GetMajorVersion();
	auto minor = ogl_GetMinorVersion();
	printf("GL: %i.%i\n", major, minor);

	m_clearColour = vec3(0.25f);
	glEnable(GL_DEPTH_TEST);

	return true;
}
Esempio n. 14
0
bool GLFramework::Startup(const int width, const int height, const char * title, const Color clearColor)
{
	if (!glfwInit())
	{
		return false;
	}
	sWindow->height = height;
	sWindow->width = width;
	sWindow->title = title;

	sWindow->handle = glfwCreateWindow(width, height, title, nullptr, nullptr);

	if (nullptr == sWindow->handle)
	{
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(sWindow->handle);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(sWindow->handle);
		glfwTerminate();
		return false;
	}

	SetClearColor(clearColor);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	return true;
}
Esempio n. 15
0
int main()
{
    // GLFW and OpenGL initialization
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(1280, 720, "OpenGL Application", NULL, NULL);
    glfwMakeContextCurrent(window);
    ogl_LoadFunctions();

    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        // Clearing of buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   			// Do rendering

        // Swap front and back buffers and poll events
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    // Termination of program
    glfwTerminate();
    return 0;
}
Esempio n. 16
0
/* Entry point of program */
int main(int argc, char* argv[])
{
    GLWrapper *glw = new GLWrapper(1024, 768, "Lab2: Hello 3D");;

    if (!ogl_LoadFunctions())
    {
        fprintf(stderr, "ogl_LoadFunctions() failed. Exiting\n");
        return 0;
    }

    /* Note it you might want to move this call to the wrapper class */
    glw->setErrorCallback(error_callback);

    glw->setRenderer(display);
    glw->setKeyCallback(keyCallback);
    glw->setMouseCallback(mouseCallback);
    glw->setReshapeCallback(reshape);

    init(glw);

    glw->eventLoop();

    delete(glw);
    return 0;
}
		bool Window::init()
		{
			if (!glfwInit())
			{
				std::cout << "Failed to initialize OpenGL." << std::endl;
				return false;
			}
			m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
			if (m_Window == nullptr)
			{
				std::cout << "Failed to create window." << std::endl;
				return false;
			}
			glfwMakeContextCurrent(m_Window);
			glfwSetWindowUserPointer(m_Window, this);
			glfwSetWindowSizeCallback(m_Window, window_resize);
			glfwSetKeyCallback(m_Window, key_callback);
			glfwSetMouseButtonCallback(m_Window, mouse_button_callback);
			glfwSetCursorPosCallback(m_Window, cursor_position_callback);
			if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
			{
				glfwDestroyWindow(m_Window);
				std::cout << "Failed to load window." << std::endl;
				return false;
			}
			return true;
		}
Esempio n. 18
0
void EnvironmentCore::initializeFunctionPointers()
{
	static bool sInitialized = false;
	if( ! sInitialized ) {
		ogl_LoadFunctions();
		sInitialized = true;
	}
}
Esempio n. 19
0
// Ues the glLoadGen'd functions to acquire OpenGL function pointers
void acquireFunctions() {
    // Acquire the OpenGL functions
    int oglLoadResult = ogl_LoadFunctions();
    if (oglLoadResult != ogl_LOAD_SUCCEEDED) {
        LOGERR("Unable to load OpenGL functions!\n");
        exit(EXIT_FAILURE);
    }
}
Esempio n. 20
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;
	}
Esempio n. 21
0
RendererOGL::RendererOGL(WindowSDL *window, const Graphics::Settings &vs)
: Renderer(window, window->GetWidth(), window->GetHeight())
, m_numLights(0)
, m_numDirLights(0)
//the range is very large due to a "logarithmic z-buffer" trick used
//http://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html
//http://www.gamedev.net/blog/73/entry-2006307-tip-of-the-day-logarithmic-zbuffer-artifacts-fix/
, m_minZNear(0.0001f)
, m_maxZFar(10000000.0f)
, m_useCompressedTextures(false)
, m_invLogZfarPlus1(0.f)
, m_activeRenderTarget(0)
, m_activeRenderState(nullptr)
, m_matrixMode(MatrixMode::MODELVIEW)
{
	if (!initted) {
		initted = true;

		if (!ogl_LoadFunctions())
			Error("glLoadGen failed to load functions.\n");

		if (ogl_ext_EXT_texture_compression_s3tc == ogl_LOAD_FAILED)
			Error(
				"OpenGL extension GL_EXT_texture_compression_s3tc not supported.\n"
				"Pioneer can not run on your graphics card as it does not support compressed (DXTn/S3TC) format textures."
			);
	}

	m_viewportStack.push(Viewport());

	const bool useDXTnTextures = vs.useTextureCompression;
	m_useCompressedTextures = useDXTnTextures;

	//XXX bunch of fixed function states here!
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

	SetMatrixMode(MatrixMode::MODELVIEW);

	m_modelViewStack.push(matrix4x4f::Identity());
	m_projectionStack.push(matrix4x4f::Identity());

	SetClearColor(Color4f(0.f, 0.f, 0.f, 0.f));
	SetViewport(0, 0, m_width, m_height);

	if (vs.enableDebugMessages)
		GLDebug::Enable();
}
Esempio n. 22
0
/// Initialize the renderer
void RendererOpenGL::Init() {
    render_window->MakeCurrent();

    int err = ogl_LoadFunctions();
    if (ogl_LOAD_SUCCEEDED != err) {
        LOG_CRITICAL(Render_OpenGL, "Failed to initialize GL functions! Exiting...");
        exit(-1);
    }

    LOG_INFO(Render_OpenGL, "GL_VERSION: %s", glGetString(GL_VERSION));
    InitOpenGLObjects();
}
Esempio n. 23
0
ApplicationFail App::Init() {
    //Init GLFW
    if(glfwInit() == false) {
        return ApplicationFail::GLFW_INIT;
    }

    //Generate Window
    CreateGLWindow();

    //
    if(ogl_LoadFunctions() == ogl_LOAD_FAILED) {
        glfwDestroyWindow(window);
        glfwTerminate();
        return ApplicationFail::OGL_LOAD_FUNCATIONS;
    }

    //Load Gizmos
    Gizmos::create();

    //Camera
    CreateCamera();

    // Load Model File
    model = LoadFBX("./rsc/models/soulspear/soulspear.fbx");
    renderOBJ = CreateRenderObject(model);

    //FrameBuffer
    //CreateFrameBuffer();
    //CreatePlane();
    //CreatePlaneShader();

    //Quad - Post Process Init
    CreateQuad();
    CreateQuadShader();
    CreateQuadBuffer();

    //Load + Bind Texture File
    LoadTexture();

    //Set Clear Screen
    glClearColor(0.25f, 0.25f, 0.25f, 1);
    glEnable(GL_DEPTH_TEST); // enables the depth buffer

    //Texture Shader
    CreateShaderProgram();




    //Time

    return ApplicationFail::NONE;
}
Esempio n. 24
0
void nsfw::Window::init(unsigned width, unsigned height)
{
	//TODO_D("Should create and set an active windowing context. ONLY GLFW! No GL!");

	

	//set width and height for later use
	this->width = width;
	this->height = height;

	//Initialize glfw
	glfwInit();
	//tell glfw to use debug stuff
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
	//create title of the window
	const char* title = "nsfwgl Test";

	//create the window
	window = glfwCreateWindow(width, height, title, nullptr, nullptr);

	//check to make sure window is created and functioning
	//if window isn't creating properly then let the console know
	if (window == nullptr)
		std::cout << "\n\n\n\n ERROR: WINDOW CREATION UNSUCCESSFUL \n\n\n\n" << std::endl;

	//set window to current context
	glfwMakeContextCurrent(window);

	//load functions
	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(window);
		glfwTerminate();
	}

	//this is for glfw debug 
#ifdef _DEBUG
	if (glDebugMessageCallback)
	{
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
		glDebugMessageCallback(oglErrorDefaultCallback, nullptr);

		GLuint unusedIDs = 0;
		glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIDs, true);
	}
	else
	{
		std::cerr << "Failed to subscribe to glDebugMessageCallback." << std::endl;
	}
#endif
}
Esempio n. 25
0
int Application::Run()
{
	if (glfwInit() == false)
		return -1;

	window = glfwCreateWindow(1280, 720, "Not A Wondow", nullptr, nullptr);

	if (!window)
	{
		glfwTerminate();
		return -2;
	}

	glfwMakeContextCurrent(window);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED) {
		glfwDestroyWindow(window);
		glfwTerminate();
		return -3;
	}
	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(0.f, 0.1f, 0.2f, 1.f);

	Input::Initialize(window);
	Time::Initialize();
	Initialize();


	while (!glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		Time::getInstance()->Update();

		Update();
		Draw();

		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	Shutdown();

	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}
Esempio n. 26
0
int main(int argc, char *argv[])
{
	string recipe = parseCLArgs(argc, argv);

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

#ifdef __APPLE__
  // Select OpenGL 4.1
  glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
  glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
#else
	// Select OpenGL 4.3
	glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
	glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 );
#endif
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

	// Open the window
	string title = "Chapter 02 -- " + recipe;
	window = glfwCreateWindow( WIN_WIDTH, WIN_HEIGHT, title.c_str(), NULL, NULL );
	if( ! window ) {
		glfwTerminate();
		exit( EXIT_FAILURE );
	}
	glfwMakeContextCurrent(window);

	// Load the OpenGL functions.
	if( ogl_LoadFunctions() == ogl_LOAD_FAILED ) {
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	GLUtils::dumpGLInfo();

	// Initialization
	initializeGL();
	resizeGL(WIN_WIDTH,WIN_HEIGHT);

	// Enter the main loop
	mainLoop();

	// Close window and terminate GLFW
	glfwTerminate();
	// Exit program
	exit( EXIT_SUCCESS );
}
Esempio n. 27
0
	void BaseApplication::InitDependency(vec3 a_vCamPos)
	{
		if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
		{
			glfwTerminate();
			printf("<ERROR>: ogl_LoadFunctions has fail initialization. \n");
			exit(EXIT_FAILURE);
		}
		else
		{
			printf("--------------------------------------------------------------------------------");
			printf("-- OGL LOADED SUCCESSFULLY. \n");
			if (this->m_oApp->APPINFO.Flags.m_uiDebug)
			{ 
				glDebugMessageCallback(debug_callback, NULL);
				if (glDebugMessageCallback != NULL)
				{
					glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
				}
				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\n");
			}
			//this->DATA.m_oTweeking = new Bar();
			//this->DATA.m_oTweeking->InitTweek();
			printf("-- GL DEBUG MESSAGE ENABLED. \n");
			glfwSetCharModsCallback(this->m_oApp->DATA.m_oWin, on_char_callback);
			printf("-- CHAR_CALLBACK ENABLED. \n");
			glfwSetKeyCallback(this->m_oApp->DATA.m_oWin, key_callback);
			printf("-- KEY_CALLBACK ENABLED. \n");
			glfwSetMouseButtonCallback(this->m_oApp->DATA.m_oWin, mouse_button_callback);
			glfwSetCursorPosCallback(this->m_oApp->DATA.m_oWin, mouse_callback);
			glfwSetCursorPos(this->m_oApp->DATA.m_oWin, (double)this->m_oApp->APPINFO.m_viWinSize.x / 2.0, (double)this->m_oApp->APPINFO.m_viWinSize.y / 2.0);
			printf("-- MOUSE_CALLBACK ENABLED. \n");
			glfwSetScrollCallback(this->m_oApp->DATA.m_oWin, scroll_callback);
			printf("-- SCROLL_CALLBACK ENABLED. \n");
			glfwSetFramebufferSizeCallback(this->m_oApp->DATA.m_oWin, framebuffer_size_callback);
			printf("-- WINDOW_BUFFER_CALLBACK ENABLED. \n");
			//
			this->m_oApp->DATA.m_oCurrCamera = new Camera(vec2(this->m_oApp->APPINFO.m_viWinSize.x,
				this->m_oApp->APPINFO.m_viWinSize.y));
			this->m_oApp->DATA.m_oCurrCamera->BuildCamera(a_vCamPos);
			this->m_oApp->DATA.m_oTotalCameras[0] = this->m_oApp->DATA.m_oCurrCamera;
			printf("-- CAMERA BUILT SUCCESSFULLY. \n");
			//Note: I should consider moving this function call into the appropriate application.
			//m_oTweek.InitTweek();
			printf("--------------------------------------------------------------------------------");
		}
	}
Esempio n. 28
0
static int
init_gl(void)
{
	int missing;

	missing = ogl_LoadFunctions();

	if (missing == ogl_LOAD_FAILED) {
		ERR("couldn't initialize openGL.\n");
		return -1;
	} else if (missing > ogl_LOAD_SUCCEEDED)
		ERR("openGL initialized, but missing %d functions.\n",
				missing - ogl_LOAD_SUCCEEDED);

	return 0;
}
Esempio n. 29
0
void initEntryPoints(HWND hwnd, const PIXELFORMATDESCRIPTOR &pfd){
	HDC hdc = GetDC(hwnd);

	int nPixelFormat = ChoosePixelFormat(hdc, &pfd);
	SetPixelFormat(hdc, nPixelFormat, &pfd);

	HGLRC hglrc = wglCreateContext(hdc);
	wglMakeCurrent(hdc, hglrc);

  ogl_LoadFunctions();
	wgl_LoadFunctions(hdc);

	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hglrc);
	ReleaseDC(hwnd, hdc);
}
Esempio n. 30
0
int main(int argc, char *argv[]) {
	printf("Welcome to the OpenGL / 3D Vision bridge demo!\n");

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
		printf("Could not initialize SDL video\n");
		return 1;
	}

	window = SDL_CreateWindow("OpenGL / 3D Vision Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	if (!window) {
		printf("Could not create SDL window\n");
		return 1;
	}

	SDL_GL_SetSwapInterval(1); // enable vsync when not using 3D Vision

	SDL_GLContext gl = SDL_GL_CreateContext(window);
	if (!gl) {
		printf("Could not create SDL OpenGL context\n");
		return 1;
	}

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED) {
		printf("Could not bind OpenGL API\n");
		return 1;
	}

	SDL_SysWMinfo wmInfo = {0};
	SDL_GetWindowWMInfo(window, &wmInfo);
	HWND hWnd = wmInfo.info.win.window;

	GLD3DBuffers_create(&gl_d3d_buffers, hWnd, true, true);

	printf("Press Q to quit and N to toggle NVIDIA 3D Vision\n");

	SDL_StartTextInput();
	while (handle_input()) {
		render();
	}
	SDL_StopTextInput();

	GLD3DBuffers_destroy(&gl_d3d_buffers);
	SDL_GL_DeleteContext(gl);
	SDL_DestroyWindow(window);
	SDL_Quit();
	return 0;
}