コード例 #1
1
static inline jlong wrapped_Java_com_badlogic_jglfw_Glfw_glfwCreateWindowJni
(JNIEnv* env, jclass clazz, jint width, jint height, jstring obj_title, jlong monitor, jlong share, char* title) {

//@line:704

		GLFWwindow* window = glfwCreateWindow(width, height, title, (GLFWmonitor*)monitor, (GLFWwindow*)share);
		if (window) {
			glfwSetWindowPosCallback(window, windowPos);
			glfwSetWindowSizeCallback(window, windowSize);
			glfwSetWindowCloseCallback(window, windowClose);
			glfwSetWindowRefreshCallback(window, windowRefresh);
			glfwSetWindowFocusCallback(window, windowFocus);
			glfwSetWindowIconifyCallback(window, windowIconify);
			glfwSetKeyCallback(window, key);
			glfwSetCharCallback(window, character);
			glfwSetMouseButtonCallback(window, mouseButton);
			glfwSetCursorPosCallback(window, cursorPos);
			glfwSetCursorEnterCallback(window, cursorEnter);
			glfwSetScrollCallback(window, scroll);
			glfwSetDropCallback(window, drop);
		}
		return (jlong)window;
	
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Kingwl/ray
    void init(std::size_t w, std::size_t h)
    {
		glfwInit();

		_window = glfwCreateWindow(w, h, "UI", nullptr, nullptr);
		if (_window)
		{
			glfwSetWindowUserPointer(_window, this);
			glfwSetWindowFocusCallback(_window, &setWindowFocusCallback);
			glfwSetWindowCloseCallback(_window, &setWindowCloseCallback);

			HWND hwnd = glfwGetWin32Window(_window);

			if (!this->open(hwnd, w, h))
				throw ray::failure("App::open() fail");

			if (!this->openScene("dlc:UI\\scene.map"))
				throw ray::failure("App::openScene('dlc:UI\\scene.map') fail");
		}
    }
コード例 #3
0
void veViewerDesktop::create()
{
    if (_hwnd) return;
    _hwnd = glfwCreateWindow(_width, _height, _title.c_str(), nullptr, _sharedViewer? _sharedViewer->_hwnd: nullptr);
    
    glfwSetWindowUserPointer(_hwnd, this);
    glfwSetKeyCallback(_hwnd, collectKeyEvent);
    glfwSetCharCallback(_hwnd, collectCharEvent);
    glfwSetMouseButtonCallback(_hwnd, collectMouseEvent);
    glfwSetCursorPosCallback(_hwnd, collectMouseMoveEvent);
    glfwSetScrollCallback(_hwnd, collectScrollEvent);
    glfwSetWindowSizeCallback(_hwnd, collectWindowSizeEvent);
    glfwSetWindowFocusCallback(_hwnd, collectWindowFocusEvent);
    glfwSetWindowCloseCallback(_hwnd, collectWindowClose);
    
    _currentEvent.setEventType(veEvent::VE_WIN_INIT);
    _currentEvent.setWindowWidth(_width);
    _currentEvent.setWindowHeight(_height);
    _eventList.push_back(_currentEvent);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: anhhuybidv/snes9xnext
int openWindow(bool fullscreen)
{
	unsigned long windowFlag = (fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW);

	// load GLFW
	if (glfwInit() != GL_TRUE)
	{
		fprintf(stderr, "ERROR: Could not initialize GLFW\n");
		return EXIT_FAILURE;
	}

	// set core profile OpenGL 3.3+
	//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // Set OpenGL version to 3.3+
	//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
	//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Request core profile
	//glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Disable legacy

	// Initialize the window & create
	if (glfwOpenWindow(RESOLUTION_X, RESOLUTION_Y,
			8, 8, 8, 8, // RGBA bits
			16, 0, // depth, stencil bits
			windowFlag) != GL_TRUE)
	{
		fprintf(stderr, "ERROR: Could not open window\n");
		glfwTerminate();
		return EXIT_FAILURE;
	}

	glfwSetWindowTitle(APP_TITLE);

	// Set up callbacks
	glfwSetKeyCallback(glfwKeyboard);
	glfwSetMousePosCallback(glfwMouseMove);
	glfwSetMouseButtonCallback(glfwMouseInput);
	glfwSetMouseWheelCallback(glfwMouseWheel);

	glfwSetWindowSizeCallback(glfwResize);
	glfwSetWindowCloseCallback(glfwWindowClosed);

	return 0;
}
コード例 #5
0
int
main()
{
    // GLFW Init and Core Profile Setup
    if (!glfwInit())
    {
        std::cerr << "Failed to initialize GLFW. Aborting." << std::endl;
        return EXIT_FAILURE;
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    auto width = 768;
    auto height = 768;
    // Create a window
    auto window = glfwCreateWindow(width, height, "Testapp", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        std::cerr << "Failed to create window" << std::endl;
    }
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, glfwKeyCallback);
    glfwSetWindowCloseCallback(window, glfwWindowCloseCallback);
    
    std::cout << "OpenGLVersion" << glGetString(GL_VERSION) << std::endl;

    initShader();
    while (!closeWindow)
    {
        // Render
        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        render();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
}
コード例 #6
0
ファイル: Window.cpp プロジェクト: Adrianis/bakge
Window* Window::Create(int Width, int Height)
{
    Window* Win = new Window;

    Win->WindowHandle = glfwCreateWindow(Width, Height, "Bakge", NULL, NULL);
    if(Win->WindowHandle == NULL) {
        delete Win;
        return NULL;
    }

    /* Store pointer to Bakge window so global callbacks can access it */
    glfwSetWindowUserPointer(Win->WindowHandle, (void*)Win);

    glfwSetWindowCloseCallback(Win->WindowHandle, WindowClosed);
    glfwSetWindowSizeCallback(Win->WindowHandle, WindowResized);
    glfwSetWindowPosCallback(Win->WindowHandle, WindowMoved);

    Win->Bind();

    return Win;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: csellsword/RWL
//program main
int
main(void){
	God god;
	god.newGame();
	glfwSetWindowCloseCallback(closeWindow);
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glfwSwapBuffers();
	glfwSetTime(0);
	double ptime = glfwGetTime();
	while(!gameOver){
		if(glfwGetTime() > ptime + ftime){
			ptime += ftime;
			god.draw();
			glfwSwapBuffers();
			god.input();
		}
	}
	glfwTerminate();
	return 1;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: CalebVDW/smr-motion
bool setupWindow( int width, int height, bool fullscreen )
{
	// Create OpenGL window
	if( !glfwOpenWindow( width, height, 8, 8, 8, 8, 24, 8, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW ) )
	{
		glfwTerminate();
		return false;
	}

	if( !fullscreen ) glfwSetWindowTitle( caption );
	
	// Disable vertical synchronization
	glfwSwapInterval( 0 );

	// Set listeners
	glfwSetWindowCloseCallback( windowCloseListener );
	glfwSetKeyCallback( keyPressListener );
	glfwSetMousePosCallback( mouseMoveListener );
	
	return true;
}
コード例 #9
0
ファイル: main.c プロジェクト: DCPUTeam/DCPUToolchain
void* dtemu_create_context(const char* title, int width, int height, bool resizeable, void* ud)
{
    GLFWwindow* context = malloc(sizeof(GLFWwindow));

    if (!resizeable)
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    *context = (GLFWwindow) glfwCreateWindow(width, height, GLFW_WINDOWED, title, NULL);
    
    if (*context == NULL)
        dhalt(ERR_COULD_NOT_CREATE_OPENGL_CONTEXT, "glfwCreateWindow returned NULL.");

    glfwSetWindowUserPointer(*context, ud);
    glfwMakeContextCurrent(*context);
    glfwSetWindowCloseCallback(&vm_hw_glfw_close_window_callback);
    glfwSetWindowSizeCallback(&vm_hw_glfw_resize_window_callback);
    glfwSwapInterval(0);

    glfwSetTime(0.0);

    return context;
}
コード例 #10
0
ファイル: EApp.cpp プロジェクト: neko-para/EzGui
	EApp::EApp(std::function<void(void)> startUp, int w, int h) : end(false), close([&]() {
		end = true;
	}), quit(s_quit) {
		if (eApp) {
			throw Exceptions::AppAlreadyConstructed();
		} else {
			eApp = this;
			msgQueue = EMsgQueue::create();
			glfwInit();
			handle = glfwCreateWindow(w, h, "", 0, 0);
			glfwSetWindowCloseCallback(handle, CloseCallback);
			glfwSetWindowSizeCallback(handle, ResizeCallback);
			glfwSetCursorPosCallback(handle, CursorPosCallback);
			coreThread = new std::thread([&](std::function<void(void)> startUp, int w, int h) {
				glfwMakeContextCurrent(handle);
				glfwSwapInterval(0);
				glewInit();

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

				glViewport(0, 0, w, h);
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				gluOrtho2D(0, w, 0, h);
				glTranslated(0, h, 0);
				glScaled(1, -1, 1);
				glMatrixMode(GL_MODELVIEW);

				int px, py;
				glfwGetWindowPos(handle, &px, &py);
				eRootWindow = new EMainWindow(px, py, w, h);
				s_quit.connect(loop.quit);
				startUp();
				loop.exec();
				close();
			}, startUp, w, h);
		}
	}
コード例 #11
0
CanvasGLFW::CanvasGLFW(std::string windowTitle, uvec2 dimensions)
    : CanvasGL(dimensions)
    , windowTitle_(windowTitle)
    , glWindow_(nullptr)
    , mouseButton_(MouseEvent::MOUSE_BUTTON_NONE)
    , mouseState_(MouseEvent::MOUSE_STATE_NONE)
    , mouseModifiers_(InteractionEvent::MODIFIER_NONE) {
    
    glfwWindowHint(GLFW_FLOATING, alwaysOnTop_ ? GL_TRUE : GL_FALSE);
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);

#ifdef __APPLE__
    if (!sharedContext_ && OpenGLCapabilities::getPreferredProfile() == "core") {
        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

    glWindow_ = glfwCreateWindow(getScreenDimensions().x, getScreenDimensions().y,
                                 windowTitle_.c_str(), nullptr, sharedContext_);

    if (!glWindow_) {
        glfwTerminate();
        throw Exception("Could not create GLFW window.", IvwContext);
    }

    if (!sharedContext_) sharedContext_ = glWindow_;

    // register callbacks
    glfwSetKeyCallback(glWindow_, keyboard);
    glfwSetMouseButtonCallback(glWindow_, mouseButton);
    glfwSetCursorPosCallback(glWindow_, mouseMotion);
    glfwSetScrollCallback(glWindow_, scroll);
    glfwSetWindowCloseCallback(glWindow_, closeWindow);
    glfwSetWindowUserPointer(glWindow_, this);
    glfwSetWindowSizeCallback(glWindow_, reshape);
    glfwSetWindowPosCallback(glWindow_, move);
}
コード例 #12
0
ファイル: render.cpp プロジェクト: grzegorz-k-karch/sph
void initOpenGL()
{
  glfwSetErrorCallback(error_callback);

  if (!glfwInit()) {
    printf("Failed to initialize GLFW\n");
    exit(EXIT_FAILURE);
  }

  window = glfwCreateWindow(windowWidth, windowHeight, "OpenGL", NULL, NULL);
  if (!window) {
    printf("Could not open window with GLFW\n");
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
  glfwMakeContextCurrent(window);

  // Callbacks
  glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
  glfwSetWindowCloseCallback(window, window_close_callback);
  glfwSetKeyCallback(window, key_callback);
  glfwSetCursorPosCallback(window, cursor_pos_callback);
  glfwSetMouseButtonCallback(window, mouse_button_callback);

  // start GLEW extension handler
  glewInit();
  if (glewInit() != GLEW_OK) {
    printf("Failed to initialize GLEW\n");
    exit(EXIT_FAILURE);
  }

  glEnable(GL_DEPTH_TEST); // enable depth-testing

  trackball(curquat, 0.0f, 0.0f, 0.0f, 0.0f);

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

  program = initShaderProgram();
}
コード例 #13
0
	void WindowContext::init()
	{
		ChangeManager::get().add(this, { Message::MsgType::SET_MOUSE });

		cout << "Creating window context" << endl;
		
		LOG("Creating window context");

		// Initialize GLFW
		if (!glfwInit())
		{
			LOG_ERR("Could not initialize GLFW");
			return;
		}
		// Multisampling
		glfwWindowHint(GLFW_SAMPLES, 8);

		// Create a window
		window = glfwCreateWindow(Constants::get().getNum<int>("window_width"), Constants::get().getNum<int>("window_height"), Constants::get().getString("window_title").c_str(), nullptr, nullptr);
		if (!window)
		{
			LOG_ERR("Could not create GLFW window");
			return;
		}
		glfwMakeContextCurrent(window);
		glfwSwapInterval(1);
		glfwSetWindowUserPointer(window, this);
		quit = false;

		// Initialize callbacks
		//glfwSetMouseButtonCallback(window, mouseBtnCallback);
		glfwSetCursorPosCallback(window, cursorPosCallback);
		//glfwSetCursorEnterCallback(window, cursorEnterCallback);
		//glfwSetScrollCallback(window, scrollCallback);
		glfwSetKeyCallback(window, keyCallback);
		glfwSetWindowCloseCallback(window, closeCallback);
		glfwSetWindowSizeCallback(window, sizeCallback);
		glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
	}
コード例 #14
0
ファイル: glfw.c プロジェクト: flufy3d/emscripten
void Init()
{
    const int window_width = 800,
              window_height = 600;

    if (glfwInit() != GL_TRUE)
        Shut_Down(1);

    glfwEnable(GLFW_KEY_REPEAT); // test for issue #3059

    int red_bits = glfwGetWindowParam(GLFW_RED_BITS);
    glfwOpenWindowHint(GLFW_RED_BITS, 8);
    assert(glfwGetWindowParam(GLFW_RED_BITS) == 8);
    glfwOpenWindowHint(GLFW_RED_BITS, red_bits);

    // 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
    if (glfwOpenWindow(window_width, window_height, 5, 6, 5,
                       0, 0, 0, GLFW_WINDOW) != GL_TRUE)
        Shut_Down(1);
    glfwSetWindowTitle("The GLFW Window");

    glfwSetKeyCallback( OnKeyPressed );
    glfwSetCharCallback( OnCharPressed );
    glfwSetWindowCloseCallback(OnClose);
    glfwSetWindowSizeCallback(OnResize);
    glfwSetWindowRefreshCallback(OnRefresh);
    glfwSetMouseWheelCallback(OnMouseWheel);
    glfwSetMousePosCallback(OnMouseMove);
    glfwSetMouseButtonCallback(OnMouseClick);

    // set the projection matrix to a normal frustum with a max depth of 50
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    float aspect_ratio = ((float)window_height) / window_width;
    glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
    glMatrixMode(GL_MODELVIEW);

    PullInfo();
}
コード例 #15
0
ファイル: Window.cpp プロジェクト: dcobban/Marbles
// --------------------------------------------------------------------------------------------------------------------
window::builder::builder(/*allocator*/)
: _win(nullptr)
, _name("Marbles")
, _width(1280)
, _height(720)
, _fullscreen(false)
, _validation(false)
{
    _pre.reserve(8);
    _pre.push_back(async(launch::deferred, [this]() -> int
    {
        glfwDefaultWindowHints();
        if (glfwVulkanSupported())
        {
            glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // use vulkan
        }
        return 0;
    }));

    _post.reserve(8);
    _post.push_back(async(launch::deferred, [this]() -> int
    {
        GLFWwindow* glfwWin = this->_win->_internal->_window;
        glfwSetWindowUserPointer(glfwWin, this->_win);
        glfwSetWindowPosCallback(glfwWin, [](GLFWwindow* glfwWin, int x, int y)
        {
            window* win = reinterpret_cast<window*>(glfwGetWindowUserPointer(glfwWin));
            win->onReposition(win, x, y);
        });
        glfwSetWindowCloseCallback(glfwWin, [](GLFWwindow* glfwWin)
        {
            window* win = reinterpret_cast<window*>(glfwGetWindowUserPointer(glfwWin)); 
            win->onClose(win);
        });
        

        return 0;
    }));
}
コード例 #16
0
static int open_window(int width, int height, int mode)
{
    double base = glfwGetTime();

    if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode))
    {
        fprintf(stderr, "Failed to create %s mode GLFW window\n", get_mode_name(mode));
        return 0;
    }

    glfwSetWindowTitle("Window Re-opener");
    glfwSetWindowSizeCallback(window_size_callback);
    glfwSetWindowCloseCallback(window_close_callback);
    glfwSetKeyCallback(key_callback);
    glfwSwapInterval(1);

    printf("Opening %s mode window took %0.3f seconds\n",
           get_mode_name(mode),
           glfwGetTime() - base);

    return 1;
}
コード例 #17
0
ファイル: Window.cpp プロジェクト: dabbertorres/OpenGL-GLFW
	void Window::create(const Vector<uint, 2>& res, const std::string& t, const Monitor& mon, bool fs)
	{
		title = t;
		isFullscreen = fs;
		
		window = glfwCreateWindow(res[0], res[1], title.c_str(), fs ? mon.monitor : nullptr, nullptr);

		if(!window)
			throw std::runtime_error("Could not create the window.");
			
		glfwMakeContextCurrent(window);
		
		if(!numOfWindows)
		{
			// setup GLEW if this is the first Window
			glewExperimental = GL_TRUE;
			GLenum err = glewInit();

			if(err != GLEW_OK)
				throw std::runtime_error("glewInit failed!");		
		}
		
		{
			std::lock_guard<std::mutex> windowsLock(windowStaticLock);
			++numOfWindows;
			windows.emplace(window, this);
		}
		
		glfwSetKeyCallback(window, &keyboardCallback);
		glfwSetCharCallback(window, &unicodeCallback);
		glfwSetCursorEnterCallback(window, &mouseEnteredCallback);
		glfwSetCursorPosCallback(window, &mouseMovedCallback);
		glfwSetMouseButtonCallback(window, &mouseButtonCallback);
		glfwSetScrollCallback(window, &scrollCallback);
		glfwSetWindowPosCallback(window, &positionCallback);
		glfwSetWindowSizeCallback(window, &sizeCallback);
		glfwSetWindowCloseCallback(window, &closeCallback);
	}
コード例 #18
0
ファイル: Window.cpp プロジェクト: RibaldRhino/blue
    Window::Window(int width, int height, std::string title, bool fullScreen) :
            _inputManagerUPtr(std::unique_ptr<InputManager>(new InputManager())) {
        glfwSetErrorCallback(OnError);
        glfwInit();
        glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
        glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        if (!fullScreen)
            _glfwWindowPtr = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
        else
            _glfwWindowPtr = glfwCreateWindow(width, height, title.c_str(), glfwGetPrimaryMonitor(), NULL);

        glfwMakeContextCurrent(_glfwWindowPtr);

        glewExperimental = GL_TRUE;
        glewInit();
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);


        glfwSetWindowUserPointer(_glfwWindowPtr, this);
        glfwSetWindowCloseCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowClosed);
        glfwSetWindowFocusCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowFocused);
        glfwSetWindowSizeCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowResized);
        glfwSetWindowIconifyCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowIconify);
        glfwSetWindowPosCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowPositionChanged);
        glfwSetFramebufferSizeCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowFramebufferResized);
        glfwSetWindowRefreshCallback(_glfwWindowPtr, _inputManagerUPtr->OnWindowRefreshed);
        glfwSetKeyCallback(_glfwWindowPtr, _inputManagerUPtr->OnKeyPressed);
        glfwSetMouseButtonCallback(_glfwWindowPtr, _inputManagerUPtr->OnMouseButton);
        glfwSetScrollCallback(_glfwWindowPtr, _inputManagerUPtr->OnScroll);
        glfwSetCursorEnterCallback(_glfwWindowPtr, _inputManagerUPtr->OnCursorEnter);
        glfwSetCursorPosCallback(_glfwWindowPtr, _inputManagerUPtr->OnCursorPositionChanged);

        _inputManagerUPtr->OnWindowResized(_glfwWindowPtr, width, height);

    }
コード例 #19
0
ファイル: screen.cpp プロジェクト: LibelulaV/U-gine
void Screen::Open(uint16 width, uint16 height, bool fullscreen) {
	// Abrimos la ventana
	glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
	glfwOpenWindow(int(width), int(height), 8, 8, 8, 8, 0, 0, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW );
	if ( !fullscreen )
		glfwSetWindowPos((GetDesktopWidth()-width)/2, (GetDesktopHeight()-height)/2);
	glfwSetWindowCloseCallback(GLFWwindowclosefun(CloseCallback));
	glfwSwapInterval(1);
	SetTitle("");
	opened = true;

	// Inicializamos los estados de OpenGL
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	// Configuramos viewport
	glViewport(0, 0, width, height);

	this->width = width;
	this->height = height;

	// Configuramos matriz de proyeccion
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity(); 
	// INVERTIMOS -> Modo espejo. 
	glOrtho(0, width, height, 0, 0, 1000); // El 1000 podría ser un 1.

	// Configuramos matriz de modelado
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Inicializamos temporizador
	lastTime = glfwGetTime();
	elapsed = 0;
}
コード例 #20
0
ファイル: fsfocus.c プロジェクト: Ape/DCPUToolchain
int main(void)
{
    GLFWwindow window;

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

    window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
    if (!window)
    {
        glfwTerminate();

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

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);

    glfwSetWindowFocusCallback(window_focus_callback);
    glfwSetKeyCallback(window_key_callback);
    glfwSetWindowCloseCallback(window_close_callback);

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwWaitEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
コード例 #21
0
ファイル: sys.c プロジェクト: niksaak/dame
int start_gfx(const char* title, int width, int height)
{
  if(!glfwInit()) {
    return -1;
  }
  // setting up window:
  glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
  the_window = glfwCreateWindow(width, height, title, NULL, NULL);
  if(the_window == NULL) {
    glfwTerminate();
    return -1;
  }
  glfwMakeContextCurrent(the_window);
  // setting callbacks:
  glfwSetWindowCloseCallback(the_window, on_close);
  glfwSetWindowSizeCallback(the_window, fix_aspect);

  setup_gl();
  //on_resize(the_window, width, height);
  return 0;
}
コード例 #22
0
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::run()
{
    d_sampleApp->initialise();

    // Input callbacks of glfw for CEGUI
    glfwSetKeyCallback(glfwKeyCallback);
    glfwSetCharCallback(glfwCharCallback);
    glfwSetMouseButtonCallback(glfwMouseButtonCallback);
    glfwSetMouseWheelCallback(glfwMouseWheelCallback);
    glfwSetMousePosCallback(glfwMousePosCallback);

    //Window callbacks
    glfwSetWindowCloseCallback(glfwWindowCloseCallback);
    glfwSetWindowSizeCallback(glfwWindowResizeCallback);
    d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // set starting time
    d_frameTime = glfwGetTime();

    while (!d_sampleApp->isQuitting() &&
        glfwGetWindowParam(GLFW_OPENED))
    {
        if (d_windowSized)
        {
            d_windowSized = false;
            CEGUI::System::getSingleton().
                notifyDisplaySizeChanged(
                CEGUI::Sizef(static_cast<float>(d_newWindowWidth),
                static_cast<float>(d_newWindowHeight)));
        }

        drawFrame();
    }

    d_sampleApp->deinitialise();
}
コード例 #23
0
GlfwWindow::GlfwWindow(const char* title, int width, int height, bool fullscreen)
	: m_name(title)
{
	if (!glfwInit())
	{
		throw std::runtime_error("Failed to initialize OpenGL");
	}

	m_glfwWindow = glfwCreateWindow(
		fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->width : width,
		fullscreen ? glfwGetVideoMode(glfwGetPrimaryMonitor())->height : height,
		title,
		fullscreen ? glfwGetPrimaryMonitor() : nullptr,
		nullptr);

	m_instance = this;

	glfwMakeContextCurrent(m_glfwWindow);
	glfwSwapInterval(1);

	glfwSetFramebufferSizeCallback(m_glfwWindow, OnFramebufferSizeCallback);
	glfwSetWindowSizeCallback(m_glfwWindow, OnSizeCallback);
	glfwSetWindowCloseCallback(m_glfwWindow, OnCloseCallback);
}
コード例 #24
0
	void RenderSystem::CreateRenderWindow(OTS::STRING* windowName)
	{
		GLFWmonitor* monitor = NULL;

		// Check if window should be fullscreen
		if (!_isWindowed)
		{
			monitor = this->_getMonitor();
		}

		this->_window = glfwCreateWindow(this->_screenWidth, this->_screenHeight, windowName->c_str(), monitor, NULL);

		if(this->_window == NULL)
		{
			this->_pLogger->LogMessage("[RenderSystem] - Error opening window.");
			throw 10;
		}

		// Make opengl Context current
		glfwMakeContextCurrent(this->_window);

		// Set window callbacks
		glfwSetWindowCloseCallback(this->_window, glfwWindowCloseCallback);
	}
コード例 #25
0
ファイル: main.c プロジェクト: Mekanikles/smugVBO-test
void Graphics_init()
{
	glfwInit();
	glfwOpenWindow(WIDTH, HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
	glfwSetWindowCloseCallback(&closeWindowCallBack, NULL);
    glDisable(GL_CULL_FACE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);      // 4-byte pixel alignment

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,WIDTH,HEIGHT,0,-1, 1);
	glMatrixMode(GL_MODELVIEW);
	//glLoadIdentity();
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    printGLError();
    
    initVBO();
    printGLError();
    
    
    glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D,texture);

    glfwLoadTexture2D("ball.tga", GLFW_BUILD_MIPMAPS_BIT);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glEnable( GL_TEXTURE_2D );
    
    printGLError();
}
コード例 #26
0
ファイル: reopen.c プロジェクト: badlogic/jglfw
static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor)
{
    double base;
    GLFWwindow* window;

    base = glfwGetTime();

    window = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL);
    if (!window)
        return NULL;

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetWindowCloseCallback(window, window_close_callback);
    glfwSetKeyCallback(window, key_callback);

    printf("Opening %s mode window took %0.3f seconds\n",
           monitor ? "fullscreen" : "windowed",
           glfwGetTime() - base);

    return window;
}
コード例 #27
0
ファイル: main.cpp プロジェクト: aem3372/OpenGL_Learn
int main() {

	if (!glfwInit()) {
		fprintf(stderr, "Failed to initialize GLFWn");
		return -1;
	}

	GLFWwindow* window = glfwCreateWindow(800, 600, "My Title", NULL, NULL);
	glfwMakeContextCurrent(window);

	// glewInit must be called after glfwMakeContextCurrent
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEWn");
		return -1;
	}

	glfwSetKeyCallback(window, keyCallback);
	glfwSetWindowSizeCallback(window, sizeChangedCallback);
	glfwSetWindowCloseCallback(window, destoryCallback);
	renderInit(window);

	double lasttime = glfwGetTime();

	while (!glfwWindowShouldClose(window))
	{
		double nowtime = glfwGetTime();
		render(window, (nowtime - lasttime)/100);
		lasttime = nowtime;

		updateFps();

		glfwSwapBuffers(window);
		glfwPollEvents();
	}
	return 0;
}
コード例 #28
0
ファイル: 03texture.cpp プロジェクト: bagobor/OpenGL-Examples
int main()
{
    int width = 640;
    int height = 480;
    
    if(glfwInit() == GL_FALSE)
    {
        std::cerr << "failed to init GLFW" << std::endl;
        return 1;
    }

    // sadly glew doesn't play nice with core profiles... 
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
 
    // create a window
    if(glfwOpenWindow(width, height, 0, 0, 0, 8, 24, 8, GLFW_WINDOW) == GL_FALSE)
    {
        std::cerr << "failed to open window" << std::endl;
        glfwTerminate();
        return 1;
    }
    
    // setup windows close callback
    glfwSetWindowCloseCallback(closedWindow);
    
    
    
    if (gl3wInit())
    {
        std::cerr << "failed to init GL3W" << std::endl;
        glfwCloseWindow();
        glfwTerminate();
        return 1;
    }

    // shader source code
    std::string vertex_source =
        "#version 330\n"
        "layout(location = 0) in vec4 vposition;\n"
        "layout(location = 1) in vec2 vtexcoord;\n"
        "out vec2 ftexcoord;\n"
        "void main() {\n"
        "   ftexcoord = vtexcoord;\n"
        "   gl_Position = vposition;\n"
        "}\n";
        
    std::string fragment_source =
        "#version 330\n"
        "uniform sampler2D tex;\n" // texture uniform
        "in vec2 ftexcoord;\n"
        "layout(location = 0) out vec4 FragColor;\n"
        "void main() {\n"
        "   FragColor = texture(tex, ftexcoord);\n"
        "}\n";
   
    // program and shader handles
    GLuint shader_program, vertex_shader, fragment_shader;
    
    // we need these to properly pass the strings
    const char *source;
    int length;

    // create and compiler vertex shader
    vertex_shader = glCreateShader(GL_VERTEX_SHADER);
    source = vertex_source.c_str();
    length = vertex_source.size();
    glShaderSource(vertex_shader, 1, &source, &length); 
    glCompileShader(vertex_shader);
    if(!check_shader_compile_status(vertex_shader))
    {
        return 1;
    }
 
    // create and compiler fragment shader
    fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
    source = fragment_source.c_str();
    length = fragment_source.size();
    glShaderSource(fragment_shader, 1, &source, &length);   
    glCompileShader(fragment_shader);
    if(!check_shader_compile_status(fragment_shader))
    {
        return 1;
    }
    
    // create program
    shader_program = glCreateProgram();
    
    // attach shaders
    glAttachShader(shader_program, vertex_shader);
    glAttachShader(shader_program, fragment_shader);
    
    // link the program and check for errors
    glLinkProgram(shader_program);
    check_program_link_status(shader_program);
    
    // get texture uniform location
    GLint texture_location = glGetUniformLocation(shader_program, "tex");
    
    // vao and vbo handle
    GLuint vao, vbo, ibo;
 
    // generate and bind the vao
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    
    // generate and bind the vertex buffer object
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
            
    // data for a fullscreen quad (this time with texture coords)
    GLfloat vertexData[] = {
    //  X     Y     Z           U     V     
       1.0f, 1.0f, 0.0f,       1.0f, 1.0f, // vertex 0
      -1.0f, 1.0f, 0.0f,       0.0f, 1.0f, // vertex 1
       1.0f,-1.0f, 0.0f,       1.0f, 0.0f, // vertex 2
      -1.0f,-1.0f, 0.0f,       0.0f, 0.0f, // vertex 3
    }; // 4 vertices with 5 components (floats) each

    // fill with data
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*4*5, vertexData, GL_STATIC_DRAW);
                    
           
    // set up generic attrib pointers
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 0*sizeof(GLfloat));
 
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 3*sizeof(GLfloat));
    
    
    // generate and bind the index buffer object
    glGenBuffers(1, &ibo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
            
    GLuint indexData[] = {
        0,1,2, // first triangle
        2,1,3, // second triangle
    };

    // fill with data
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*2*3, indexData, GL_STATIC_DRAW);
    
    // "unbind" vao
    glBindVertexArray(0);

    // texture handle
    GLuint texture;
    
    // generate texture
    glGenTextures(1, &texture);

    // bind the texture
    glBindTexture(GL_TEXTURE_2D, texture);

    // create some image data
    std::vector<GLubyte> image(4*width*height);
    for(int j = 0;j<height;++j)
        for(int i = 0;i<width;++i)
        {
            size_t index = j*width + i;
            image[4*index + 0] = 0xFF*(j/10%2)*(i/10%2); // R
            image[4*index + 1] = 0xFF*(j/13%2)*(i/13%2); // G
            image[4*index + 2] = 0xFF*(j/17%2)*(i/17%2); // B
            image[4*index + 3] = 0xFF;                   // A
        }
    
    // set texture parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    // set texture content
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image[0]);
    
    running = true;
    while(running)
    {    
        // terminate on excape 
        if(glfwGetKey(GLFW_KEY_ESC))
        {
            running = false;
        }
        
        // clear first
        glClear(GL_COLOR_BUFFER_BIT);
        
        // use the shader program
        glUseProgram(shader_program);

        // bind texture to texture unit 0
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texture);
        
        // set texture uniform
        glUniform1i(texture_location, 0);
        
        // bind the vao
        glBindVertexArray(vao);
        
        // draw
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
       
        // check for errors
        GLenum error = glGetError();
        if(error != GL_NO_ERROR)
        {
            std::cerr << gluErrorString(error);
            running = false;       
        }
        
        // finally swap buffers
        glfwSwapBuffers();       
    }
    
    // delete the created objects
    
    glDeleteTextures(1, &texture);
    
    glDeleteVertexArrays(1, &vao);
    glDeleteBuffers(1, &vbo);
    glDeleteBuffers(1, &ibo);
    
    glDetachShader(shader_program, vertex_shader);	
    glDetachShader(shader_program, fragment_shader);
    glDeleteShader(vertex_shader);
    glDeleteShader(fragment_shader);
    glDeleteProgram(shader_program);

    glfwCloseWindow();
    glfwTerminate();
    return 0;
}
コード例 #29
0
ファイル: gamma.c プロジェクト: csulmone/glfw
int main(int argc, char** argv)
{
    int width, height, ch;
    GLFWmonitor* monitor = NULL;
    GLFWwindow* window;

    while ((ch = getopt(argc, argv, "fh")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                monitor = glfwGetPrimaryMonitor();
                break;

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

    glfwSetErrorCallback(error_callback);

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

    if (monitor)
    {
        GLFWvidmode mode = glfwGetVideoMode(monitor);
        width = mode.width;
        height = mode.height;
    }
    else
    {
        width = 200;
        height = 200;
    }

    window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    set_gamma(1.f);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetKeyCallback(window, key_callback);
    glfwSetWindowCloseCallback(window, window_close_callback);
    glfwSetWindowSizeCallback(window, size_callback);

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

    glClearColor(0.5f, 0.5f, 0.5f, 0);

    while (!closed)
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glColor3f(0.8f, 0.2f, 0.4f);
        glRectf(-0.5f, -0.5f, 0.5f, 0.5f);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
コード例 #30
0
ファイル: events.c プロジェクト: ColinGilbert/noobEngine
int main(int argc, char** argv)
{
    Slot* slots;
    GLFWmonitor* monitor = NULL;
    int ch, i, width, height, count = 1;

    setlocale(LC_ALL, "");

    glfwSetErrorCallback(error_callback);

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

    printf("Library initialized\n");

    glfwSetMonitorCallback(monitor_callback);

    while ((ch = getopt(argc, argv, "hfn:")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                monitor = glfwGetPrimaryMonitor();
                break;

            case 'n':
                count = (int) strtol(optarg, NULL, 10);
                break;

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

    if (monitor)
    {
        const GLFWvidmode* mode = glfwGetVideoMode(monitor);

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

        width = mode->width;
        height = mode->height;
    }
    else
    {
        width  = 640;
        height = 480;
    }

    if (!count)
    {
        fprintf(stderr, "Invalid user\n");
        exit(EXIT_FAILURE);
    }

    slots = calloc(count, sizeof(Slot));

    for (i = 0;  i < count;  i++)
    {
        char title[128];

        slots[i].closeable = GL_TRUE;
        slots[i].number = i + 1;

        sprintf(title, "Event Linter (Window %i)", slots[i].number);

        if (monitor)
        {
            printf("Creating full screen window %i (%ix%i on %s)\n",
                   slots[i].number,
                   width, height,
                   glfwGetMonitorName(monitor));
        }
        else
        {
            printf("Creating windowed mode window %i (%ix%i)\n",
                   slots[i].number,
                   width, height);
        }

        slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL);
        if (!slots[i].window)
        {
            free(slots);
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        glfwSetWindowUserPointer(slots[i].window, slots + i);

        glfwSetWindowPosCallback(slots[i].window, window_pos_callback);
        glfwSetWindowSizeCallback(slots[i].window, window_size_callback);
        glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback);
        glfwSetWindowCloseCallback(slots[i].window, window_close_callback);
        glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback);
        glfwSetWindowFocusCallback(slots[i].window, window_focus_callback);
        glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback);
        glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback);
        glfwSetCursorPosCallback(slots[i].window, cursor_position_callback);
        glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback);
        glfwSetScrollCallback(slots[i].window, scroll_callback);
        glfwSetKeyCallback(slots[i].window, key_callback);
        glfwSetCharCallback(slots[i].window, char_callback);
        glfwSetCharModsCallback(slots[i].window, char_mods_callback);
        glfwSetDropCallback(slots[i].window, drop_callback);

        glfwMakeContextCurrent(slots[i].window);
        glfwSwapInterval(1);
    }

    printf("Main loop starting\n");

    for (;;)
    {
        for (i = 0;  i < count;  i++)
        {
            if (glfwWindowShouldClose(slots[i].window))
                break;
        }

        if (i < count)
            break;

        glfwWaitEvents();

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

    free(slots);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}