Beispiel #1
0
/*!
Key action eventhandler sets the modifier key state & forewards the event to
the slKeyPress function.
*/
static void onKeyAction(GLFWwindow* window, int GLFWKey, int scancode, int action, int mods)
{     
   SLKey key = mapKeyToSLKey(GLFWKey);
    
   if (action==GLFW_PRESS)
   {  switch (key)
      {  case KeyCtrl:  modifiers = (SLKey)(modifiers|KeyCtrl);  return;
         case KeyAlt:   modifiers = (SLKey)(modifiers|KeyAlt);   return;
         case KeyShift: modifiers = (SLKey)(modifiers|KeyShift); return;
      }
   } else 
   if (action==GLFW_RELEASE)
   {  switch (key)
      {  case KeyCtrl:  modifiers = (SLKey)(modifiers&~KeyCtrl);  return;
         case KeyAlt:   modifiers = (SLKey)(modifiers&~KeyAlt);   return;
         case KeyShift: modifiers = (SLKey)(modifiers&~KeyShift); return;
      }
   }
   
   // Special treatment for ESC key
   if (key == KeyEsc && action==GLFW_RELEASE) 
   {  
      if (fullscreen)
      {  fullscreen = !fullscreen;
         glfwSetWindowSize(window, scrWidth, scrHeight);
         glfwSetWindowPos(window, 10, 30);   
      } else 
      if (slKeyPress(svIndex, key, modifiers)) // ESC during RT stops it and returns false
      {  onClose(window);
         glfwSetWindowShouldClose(window, GL_TRUE);
      }
   } else 
   // Toggle fullscreen mode
   if (key == KeyF9 && action==GLFW_PRESS)
   {
      fullscreen = !fullscreen;

      if (fullscreen ) 
      {  GLFWmonitor* primary = glfwGetPrimaryMonitor();
         const GLFWvidmode* mode = glfwGetVideoMode(primary);
         glfwSetWindowSize(window, mode->width, mode->height);
         glfwSetWindowPos(window, 0, 0);
      } else 
      {  glfwSetWindowSize(window, scrWidth, scrHeight);
         glfwSetWindowPos(window, 10, 30);            
      }
   } else
   {  
      if (action==GLFW_PRESS)
         slKeyPress(svIndex, key, modifiers);
      else if (action==GLFW_RELEASE)
         slKeyRelease(svIndex, key, modifiers);
   }
}
static int luaWindow_set_position(lua_State* L){
    auto window = reinterpret_cast<GLFWwindow*>(lua_touserdata(L, lua_upvalueindex(1)));
    int x = lua_tointeger(L, 1);
    int y = lua_tointeger(L, 2);
    glfwSetWindowPos(window, x, y);
    return 0;
}
Beispiel #3
0
//vec2 cur;
void initgl()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_SAMPLES, 4);

    window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", nullptr, nullptr); // Windowed
    glfwMakeContextCurrent(window);

    // Set the required callback functions
    glfwSetKeyCallback(window, key_callback);
#ifndef RAWMOUSE
    glfwSetCursorPosCallback(window, mouse_callback);
#endif
    glfwSetScrollCallback(window, scroll_callback);

    // Options
    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

    // Initialize GLEW to setup the OpenGL Function pointers
    glewExperimental = GL_TRUE;
    glewInit();

    // Define the viewport dimensions
    glViewport(0, 0, screenWidth, screenHeight);

    // Setup some OpenGL options
    glEnable(GL_DEPTH_TEST);
    glfwSetWindowPos(window, 780, 280);
}
Beispiel #4
0
void Graphics::SetWindowPosition(const IntVector2& position)
{
    if(window2_)
        glfwSetWindowPos(window2_,position.x_, position.y_);
    else
        position_ = position; // Sets as initial position for OpenWindow()
}
Beispiel #5
0
	void Display::Create(const std::string& title, int width, int height)
	{
		s_title = title;
		s_width = width;
		s_height = height;

		glfwSetErrorCallback(error_callback);

		if (!glfwInit())
		{
			std::cerr << "GLFW failed to initialize!" << std::endl;
			Destroy();
			exit(1);
		}

		glfwDefaultWindowHints();
		glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
		glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

		s_pWindow = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);

		const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
		glfwSetWindowPos(s_pWindow, (vidmode->width - width) / 2, (vidmode->height - height) / 2);

		glfwMakeContextCurrent(s_pWindow);

		if (glewInit() != GLEW_OK)
		{
			std::cerr << "GLEW failed to initialize!" << std::endl;
			exit(1);
		}

		glfwShowWindow(s_pWindow);
	}
//----------
void ofxSplashScreen::begin(float minimumDuration) {
	if (!this->image.isAllocated()) {
		ofLogError("ofxSplashScreen") << "Cannot show splash screen since no image has been loaded";
		return;
	}
	this->endTime = ofGetElapsedTimef() + minimumDuration;
	this->appWindow = glfwGetCurrentContext();
	
	glfwHideWindow(this->appWindow);
	glfwWindowHint(GLFW_DECORATED, GL_FALSE);
	this->splashScreenWindow = glfwCreateWindow(this->image.getWidth(), this->image.getHeight(), "ofxSplashScreen", NULL, this->appWindow);
	glfwSetWindowPos(this->splashScreenWindow, (ofGetScreenWidth() - this->image.getWidth()) / 2.0f, (ofGetScreenHeight() - this->image.getHeight()) / 2.0f);
	glfwWindowHint(GLFW_DECORATED, GL_TRUE);
	glfwMakeContextCurrent(this->splashScreenWindow);
	
	//set the drawing matrices to normalised coordinates
	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadIdentityMatrix();
	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadIdentityMatrix();
	
	//draw the images
	ofClear(0,0,0);
	this->image.update();
	this->image.draw(-1,-1,2,2);
	glfwSwapBuffers(this->splashScreenWindow);
	glFlush();
	
	//set the context back to main for rest of setup
	glfwMakeContextCurrent(this->appWindow);
	ofSetupScreen();
}
Beispiel #7
0
int			sp_init_glfw(t_env *e)
{
	glfwSetErrorCallback(error_callback);
	glfwInit();
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	glfwWindowHint(GLFW_SAMPLES, 2);
#ifdef MAC_OS_MODE
		glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);
#endif
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
	glfwWindowHint(GLFW_OPENGL_PROFILE, OPENGL_PROFILE);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	e->win = glfwCreateWindow(WIN_WIDTHI, WIN_HEIGHTI, "Scop", NULL, NULL);
	if (!e->win)
	{
		glfwTerminate();
		return (ERROR("glfwCreateWindow"));
	}
#ifndef MAC_OS_MODE
	glfwSetWindowPos(e->win, 1000, 0);
#endif
	glfwSetWindowFocusCallback(e->win, &focus_callback);
	glfwSetKeyCallback(e->win, key_callback);
	glfwMakeContextCurrent(e->win);
	if (!INIT_GLEW)
		return (ERROR("glewInit()"));
	glViewport(0, 0, WIN_WIDTHI, WIN_HEIGHTI);
	glEnable(GL_DEPTH_TEST);
	return (0);
}
Beispiel #8
0
void VogueWindow::InitializeWindowContext(GLFWwindow* window)
{
	/* Window resize callback */
	glfwSetWindowSizeCallback(window, WindowResizeCallback);

	/* Window close message callback */
	glfwSetWindowCloseCallback(window, WindowCloseCallback);

	/* Input callbacks */
	glfwSetKeyCallback(window, KeyCallback);
	glfwSetCharCallback(window, CharacterCallback);
	glfwSetMouseButtonCallback(window, MouseButtonCallback);
	glfwSetScrollCallback(window, MouseScrollCallback);

	/* Center on screen */
	const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
	glfwGetWindowSize(window, &m_windowWidth, &m_windowHeight);
	glfwSetWindowPos(window, (vidmode->width - m_windowWidth) / 2, (vidmode->height - m_windowHeight) / 2);

	/* Make the window's context current */
	glfwMakeContextCurrent(window);
	glfwSwapInterval(m_pVogueSettings->m_vsync);

	/* Force resize */
	WindowResizeCallback(window, m_windowWidth, m_windowHeight);

	/* Show the window */
	glfwShowWindow(window);
}
	static void setGraphics(int w, int h)
	{
		glfwSetWindowSize(w, h);
		GLFWvidmode desktopMode;
		glfwGetDesktopMode( &desktopMode );
		glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 );
	}
Beispiel #10
0
	Init() {
		if(!glfwInit()) {
			std::cerr << "\nCould not initialize glfw!";
			return;
		}

		glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, true);

		if(!glfwOpenWindow(screenSizeX, screenSizeY, 8, 8, 8, 8, 8, 8, GLFW_WINDOW)) {
			std::cerr << "\nCould not open the window!";
			glfwTerminate();
			return;
		}

		glfwSetWindowTitle("Colorful Game of Life");
		glfwSetWindowPos(350, 150);
		glfwSwapInterval(0);
		glfwSetTime(0);

		if(gl3wInit() != 0) {
			std::cerr << "\nCould not initialize gl3w!";
			glfwTerminate();
			return;
		}
	}
Beispiel #11
0
GLPresenter::GLPresenter(DeckLinkCapture &capture, int w, int h, int hz) : 
	data_size(w*h*2),
	capture(capture), running(true), fullscreen(false), useVsync(false), rgbFull(false),
	texId(0), displayList(0), 
	convertUYVY(NULL),
	buffer(NULL), buffer2(NULL),
	reqW(w), reqH(h), reqHz(hz), 
	frameIndex(0), drawnFrameIndex(0), aspect(16.0/9.0), oneToNScaleFactor(-1.0)
{
	self = this;

	sprintf(prepend, "#define FRAME_WIDTH %d\n#define FRAME_HEIGHT %d\n", reqW, reqH);

	RT_ASSERT(glfwInit() == GL_TRUE, "Failed to initalize GLFW.");
	RT_ASSERT(glfwOpenWindow(w, h, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE, "Failed to open GLFW window.");

	string title("PtBi ");
	title += VER_STRING;
	glfwSetWindowTitle(title.c_str());
	glfwSetWindowPos(10, 10);

	dataPointers[0] = malloc(data_size);
	dataPointers[1] = malloc(data_size);

	glewInit();
	checkExtensions();

	ilInit();

	glfwDisable(GLFW_AUTO_POLL_EVENTS);
	glfwSwapInterval(0);
	glfwSetWindowCloseCallback(closeCallback);
	glfwSetWindowSizeCallback(resizeCallback);
	glfwSetMousePosCallback(mousePosCallback);
	glfwSetKeyCallback(keyCallback);

	hdc = wglGetCurrentDC();
	hrc = wglGetCurrentContext();

	initGL();

	convertUYVY = new GLFragmentProgram("shaders/uyvy_to_rgb_smooth.glsl", getShaderPrependString());

	buffer = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer->setFilterMode(GL_LINEAR);
	buffer2 = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
	buffer2->setFilterMode(GL_LINEAR);

	scalingManager = new ScalingManager(*this);
	aaManager = new AAManager(*this);
	ipManager = new IPManager(*this);
	keyBinding = new KeyBinding(this);
	capture.registerDisplayListener(this);

	hwnd = GetForegroundWindow();

	RT_GL_ASSERT("Error during GL initialization.");

	reshape(reqW, reqH);
}
Beispiel #12
0
void drawSplashScreen(const std::string &filename){
	if(splashScreen.ID) gl::DeleteTextures(1, &splashScreen.ID);
	else {
		ResourceLoader loader;
		loader.reloadShader("ApplyFBO");
		splashScreen = loader.loadImage(filename);

		glfwShowWindow(Global::main.window);
		glfwSetWindowPos(Global::main.window, Global::main.screenSize.x/2.f - splashScreen.width/2, Global::main.screenSize.y/2.f - splashScreen.height/2);
		glfwSetWindowSize(Global::main.window, splashScreen.width, splashScreen.height);
	}
	gl::Viewport(0, 0, splashScreen.width, splashScreen.height);
	gl::ClearColor(0.f, 0.f, 0.f, 0.f);
	gl::Clear(gl::COLOR_BUFFER_BIT);
	gl::DepthMask(gl::FALSE_);
	gl::Enable(gl::BLEND);
	gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);

	gl::BindBuffer(gl::ARRAY_BUFFER, 0);
	gl::DisableVertexAttribArray(0);
	gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0);

	auto shader = assets::getShader("ApplyFBO");
	shader.bind();
	float width = Global::main.size.x;
	float height = Global::main.size.y;

	shader.texture("uTexture", splashScreen.ID);

	drawScreen();

	glfwSwapBuffers(Global::main.window);

	CHECK_FOR_ERRORS
}
Beispiel #13
0
int main() {
    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        return -1;

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

    window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL);
    if (!window) {
        glfwTerminate();
        return -1;
    }

    glfwSetKeyCallback(window, key_callback);
    glfwSetMouseButtonCallback(window, mouse_callback);

    const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode->width - WIDTH) / 2, (vidmode->height - HEIGHT) / 2);

    glfwMakeContextCurrent(window);

    glfwSwapInterval(1);
    glfwShowWindow(window);

    loop();

    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}
Beispiel #14
0
/*! This function initializes CX functionality. It should probably only be called once, at program start.
\param config The intial CX configuration.
\return `true` if intialization was successful, `false` if there was an error. If there was an error, it should be logged.
*/
bool initializeCX(CX_InitConfiguation config) {

	if (config.clockPrecisionTestIterations < 10000) {
		config.clockPrecisionTestIterations = 10000;
	}

#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 9 && OF_VERSION_PATCH >= 0
	ofInit();
#else //Older versions...
	ofSetWorkingDirectoryToDefault();
#endif
	
	ofSetEscapeQuitsApp(false);

	CX::Instances::Log.captureOFLogMessages(config.captureOFLogMessages);
	CX::Instances::Log.levelForAllModules(CX_Logger::Level::LOG_ALL);
	CX::Instances::Log.levelForModule(CX_Logger::Level::LOG_NOTICE, "ofShader"); //Try to eliminate some of the verbose shader gobbeldygook.

	CX::Private::learnOpenGLVersion(); //Should come before reopenWindow.

	bool openedSucessfully = CX::reopenWindow(config.windowConfig); //or for the first time.

	if (!openedSucessfully) {
		CX::Instances::Log.error("CX_EntryPoint") << "The window was not opened successfully.";
	} else {
		// Set up the clock
		CX::Instances::Clock.setup(nullptr, true, config.clockPrecisionTestIterations);

		CX::Instances::Input.pollEvents(); //Do this so that the window is at least minimally responding and doesn't get killed by the OS.
			//This must happen after the window is configured because it relies on GLFW.

		if (config.framePeriodEstimationInterval != CX_Millis(0)) {
			CX::Instances::Disp.estimateFramePeriod(config.framePeriodEstimationInterval);
			CX::Instances::Log.notice("CX_EntryPoint") << "Estimated frame period for display: " << CX::Instances::Disp.getFramePeriod().millis() << " ms.";
		}

		setupKeyboardShortcuts();


		// Set up sound
		CX::Instances::SoundPlayer.setup(&CX::Instances::SoundStream);
		CX::Instances::SoundRecorder.setup(&CX::Instances::SoundStream);


		//This is temporary: I think there's an oF bug about it
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 8
		glfwSetWindowPos(CX::Private::glfwContext, 200, 200);
#endif
		
	}

	CX::Instances::Log.verbose() << endl << endl << "### End of startup logging data ###" << endl << endl;
	CX::Instances::Log.flush(); //Flush logs after setup, so user can see if any errors happened during setup.

	CX::Instances::Log.levelForAllModules(CX_Logger::Level::LOG_NOTICE);
	CX::Instances::Log.levelForModule(CX_Logger::Level::LOG_WARNING, "ofFbo"); //It isn't clear that this should be here, but the fbos
		//are really verbose when allocated and it is a lot of gibberish.

	return openedSucessfully;
}
Beispiel #15
0
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 OpenGL	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	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);	
	glOrtho(0,width,height,0,0,1000);

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

	// Inicializamos temporizador
	lastTime = glfwGetTime();
	elapsed = 0;
}
Beispiel #16
0
// --------------------------------------------------------------------------------------------------------------------
void window::position(int x, int y)
{
    if (is_open())
    {
        glfwSetWindowPos(_internal->_window, x, y);
    }
}
Beispiel #17
0
int main(void)
{
    int i, result;
    Thread threads[] =
    {
        { NULL, "Red", 1.f, 0.f, 0.f, 0 },
        { NULL, "Green", 0.f, 1.f, 0.f, 0 },
        { NULL, "Blue", 0.f, 0.f, 1.f, 0 }
    };
    const int count = sizeof(threads) / sizeof(Thread);

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

    for (i = 0;  i < count;  i++)
    {
        threads[i].window = glfwCreateWindow(200, 200,
                                             GLFW_WINDOWED,
                                             threads[i].title,
                                             NULL);
        if (!threads[i].window)
        {
            fprintf(stderr, "Failed to open GLFW window: %s\n",
                    glfwErrorString(glfwGetError()));
            exit(EXIT_FAILURE);
        }

        glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);

        if (thrd_create(&threads[i].id, thread_main, threads + i) !=
            thrd_success)
        {
            fprintf(stderr, "Failed to create secondary thread\n");
            exit(EXIT_FAILURE);
        }
    }

    while (running)
    {
        assert(glfwGetCurrentContext() == NULL);

        glfwWaitEvents();

        for (i = 0;  i < count;  i++)
        {
            if (glfwGetWindowParam(threads[i].window, GLFW_CLOSE_REQUESTED))
                running = GL_FALSE;
        }
    }

    for (i = 0;  i < count;  i++)
        thrd_join(threads[i].id, &result);

    exit(EXIT_SUCCESS);
}
Beispiel #18
0
void Window::updateWindowShape()
{
    if (_screenId == -1)
    {
        glfwSetWindowPos(_window->get(), _windowRect[0], _windowRect[1]);
        glfwSetWindowSize(_window->get(), _windowRect[2], _windowRect[3]);
    }
}
Beispiel #19
0
void ctx_fullscreen(struct context *ctx)
{
	glfwSetWindowPos(ctx->win, 0, 0);
	glfwSetWindowSize(ctx->win, ctx->vidmode->width, ctx->vidmode->height);

	ctx->winw = ctx->vidmode->width;
	ctx->winh = ctx->vidmode->height;
}
Beispiel #20
0
        void resize( int x, int y )
        {
            w = (x <= 0 ? 0 : x);
            h = (y <= 0 ? 1 : y);

            glfwSetWindowSize( window, w, h );
            glfwSetWindowPos( window, ( screen_w - w ) / 2, ( screen_h - h ) / 2 );
        }
Beispiel #21
0
/////////////////////////////////////////////////////////
// offsetMess
//
/////////////////////////////////////////////////////////
void gemglfw2window :: offsetMess(int x, int y)
{
  m_xoffset = x;
  m_yoffset = y;
  if(makeCurrent()){
    glfwSetWindowPos(x, y);
  }
}
Beispiel #22
0
int main(void)
{
    int i, result;
    Thread threads[] =
    {
        { NULL, "Red", 1.f, 0.f, 0.f, 0 },
        { NULL, "Green", 0.f, 1.f, 0.f, 0 },
        { NULL, "Blue", 0.f, 0.f, 1.f, 0 }
    };
    const int count = sizeof(threads) / sizeof(Thread);

    glfwSetErrorCallback(error_callback);

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

    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);

    for (i = 0;  i < count;  i++)
    {
        threads[i].window = glfwCreateWindow(200, 200,
                                             threads[i].title,
                                             NULL, NULL);
        if (!threads[i].window)
        {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);
        glfwShowWindow(threads[i].window);

        if (thrd_create(&threads[i].id, thread_main, threads + i) !=
            thrd_success)
        {
            fprintf(stderr, "Failed to create secondary thread\n");

            glfwTerminate();
            exit(EXIT_FAILURE);
        }
    }

    while (running)
    {
        glfwWaitEvents();

        for (i = 0;  i < count;  i++)
        {
            if (glfwWindowShouldClose(threads[i].window))
                running = GL_FALSE;
        }
    }

    for (i = 0;  i < count;  i++)
        thrd_join(threads[i].id, &result);

    exit(EXIT_SUCCESS);
}
Beispiel #23
0
JNIEXPORT void JNICALL Java_com_badlogic_jglfw_Glfw_glfwSetWindowPos(JNIEnv* env, jclass clazz, jlong window, jint x, jint y) {


//@line:740

		glfwSetWindowPos((GLFWwindow*)window, x, y);
	

}
    void* LinuxWindowImpl::create(const WindowSettings& settings)
    {
        ensureGLFWInit();

        GLFWwindow* wndwHandle;

        glfwWindowHint(GLFW_ALPHA_BITS, settings.useBlending ? 8 : 0);
        glfwWindowHint(GLFW_DEPTH_BITS, settings.useDepthBuffer ? 16 : 0);
        glfwWindowHint(GLFW_STENCIL_BITS, settings.useStencilBuffer ? 8 : 0);
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);

        int majorVer = settings.contextVersionMajor == 0 ? 4 : settings.contextVersionMajor,
            minorVer = settings.contextVersionMajor == 0 ? 4 : settings.contextVersionMinor;

        do
        {
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVer);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVer);

            wndwHandle = glfwCreateWindow(settings.size.w, settings.size.h, settings.title.c_str(), settings.fullScreen ? glfwGetPrimaryMonitor() : NULL, NULL);

            if (--minorVer < 0)
            {
                --majorVer;
                minorVer = 9;
            }

        } while (!wndwHandle && majorVer > 0);


        if (!wndwHandle)
        {
            std::cout << "Failed to create an OpenGL context! Exiting..." <<std::endl;
            std::exit(EXIT_FAILURE);
        }

        ++windowRefs;
        glfwMakeContextCurrent(wndwHandle);

        glfwSetWindowPos(wndwHandle, settings.position.x, settings.position.y);
        glfwSwapInterval(settings.useVsync ? 1 : 0);

		std::cout << "glew init might produces GL_INVALID_ENUM error. Just ignore it" << std::endl;
		glewExperimental = GL_TRUE;
        oglCheck(glewInit());
        
        if(majorVer >= 3)
        {
            GLuint vertexArray;
            glGenVertexArrays(1, &vertexArray);
            glBindVertexArray(vertexArray);
        }


        return static_cast<void*>(wndwHandle);
    }
Beispiel #25
0
 virtual void SetUp(void) {
     glfwInit();
     glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
     window = glfwCreateWindow(TEST_WIDTH, TEST_HEIGHT, "gtest", nullptr, nullptr);
     glfwSetWindowPos(window, 300, 300);
     glfwMakeContextCurrent(window);
     ASSERT_EQ(GLEW_OK, glewInit());
     PHYSFS_init("gtest");
     PHYSFS_addToSearchPath("data", true);
 }
Beispiel #26
0
/* do__set_window_position
 *
 * opengl-client.api        type:    { session: Session, x: Int, y: Int } -> Void
 * opengl-client-driver.api type:   (Session, Int, Int) -> Void
 */
static Val   do__set_window_position   (Task* task, Val arg)
{

    int               i0 =                            GET_TUPLE_SLOT_AS_INT( arg, 1);
    int               i1 =                            GET_TUPLE_SLOT_AS_INT( arg, 2);

    glfwSetWindowPos( /*x*/i0, /*y*/i1 );

    return HEAP_VOID;
}
Beispiel #27
0
	int Init(bool a_bSetFullScreen, unsigned int a_uiWidth, unsigned int a_uiHeight, int a_uiPosX, int a_uiPosY)
	{
		Monitor = glfwGetMonitors(aiNumOfMonitors);
		Mode = glfwGetVideoMode(Monitor[0]);

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

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

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

			glfwSetWindowPos(Window, a_uiPosX, a_uiPosY);
		}

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

		//make the glfw window 
		glfwMakeContextCurrent(Window);

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

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

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

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

		return 0;
	}
Beispiel #28
0
// width, height 生成時のサイズ
// full_screen   true: フルスクリーン
// dynamic_size  true: ウインドウサイズにあわせて画面を変更
AppEnv::AppEnv(const int width, const int height,
               const bool full_screen, const bool dynamic_size) :
  dynamic_window_size_(dynamic_size),
  window_(width, height, false, full_screen),
  window_size_(width, height),
  current_window_size_(window_size_),
  viewport_ofs_(0, 0),
  viewport_size_(width, height),
  bg_color_(0, 0, 0, 0),
  key_page_(0),
  mouse_left_press_(false),
  mouse_right_press_(false),
  mouse_pos_(0, 0),
  mouse_last_pos_(0, 0),
  mouse_current_pos_(0, 0),
  buttons_page_(0)
{
  DOUT << "AppEnv()" << std::endl;

  // Windowを画面の中央へ移動
  const auto* video_mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
  glfwSetWindowPos(window_(), (video_mode->width - width) / 2, (video_mode->height - height) / 2);

  // GLFWのハンドルに自分自身を登録
  glfwSetWindowUserPointer(window_(), this);

  // ウインドウのサイズ変更
  glfwSetWindowSizeCallback(window_(), changeWindowSize);
    
  // キーが押された時に呼ばれる関数を登録
  glfwSetCharCallback(window_(), createCharaInfo);
  glfwSetKeyCallback(window_(), createKeyInfo);

  // マウスイベント
  glfwSetMouseButtonCallback(window_(), mouseButtonCallback);
  glfwSetCursorPosCallback(window_(), mouseMoveCallback);

  // GamePad
  gamepads_ = initGamePad();
  
  glEnable(GL_POINT_SMOOTH);
  glEnable(GL_LINE_SMOOTH);

  // Windowの表示開始
  glfwShowWindow(window_());

  if (full_screen) {
    // フルスクリーンはモニタによって解像度がまちまちなので、viewportで補正
    int width, height;
    glfwGetFramebufferSize(window_(), &width, &height);
    DOUT << "framebuffer size:" << width << "," << height << std::endl;

    dynamicViewport(width, height);
  }
}
Beispiel #29
0
int PCRender::Init(SWindow *win) {
    GLint vpos_loc, tbuf_loc;
    m_sWindow = win;

    if (m_iWidth * m_iHeight > 0) {
        glfwSetWindowSize(m_sWindow, m_iWidth, m_iHeight);
        GLFWvidmode *mode = (GLFWvidmode*)glfwGetVideoMode(glfwGetPrimaryMonitor());
        glfwSetWindowPos(m_sWindow, (mode->width-m_iWidth)/2, (mode->height-m_iHeight)/2);
    }

    glfwMakeContextCurrent(m_sWindow);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

    glGenBuffers(1, &m_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    m_shaderProgram = MakeShaderProgram(vs, fs);
    if (m_shaderProgram == 0u) {
        return -1;
    }

    vpos_loc = glGetAttribLocation(m_shaderProgram , "vertexIn");
    glEnableVertexAttribArray(vpos_loc);
    glVertexAttribPointer(vpos_loc, 2, GL_FLOAT, GL_FALSE,
                          sizeof(float) * 4, (void*) 0);

    tbuf_loc = glGetAttribLocation(m_shaderProgram , "textureIn");
    glEnableVertexAttribArray(tbuf_loc);
    glVertexAttribPointer(tbuf_loc, 2, GL_FLOAT, GL_FALSE,
                          sizeof(float) * 4, (void*) (sizeof(float) * 2));

    //Init Texture
    glGenTextures(3, m_textures);
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);
    glBindTexture(GL_TEXTURE_2D, m_textures[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);
    glBindTexture(GL_TEXTURE_2D, m_textures[2]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);

    glfwMakeContextCurrent(NULL);

    return 0;
}
Beispiel #30
0
int main(int argc, char **argv){

  t = 0.;

  glfwInit();

  /* glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); */
  /* glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); */
  /* glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); */

  glfwOpenWindow(500,500,0,0,0,0,0,0,GLFW_WINDOW);

  glfwSetWindowPos(50,100);

  glfwSetWindowTitle("halfshadow triangle");

  createshader();

  glfwSwapInterval(1);

  glClearColor(0.,0.,0.5,1.);	/* blue background */

  create_VBO();

  /* prepare_rectangle(); */

  while(glfwGetWindowParam(GLFW_OPENED)){

    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(shader_program);

    univar = sin(4.*t);

    /* this is called after glUseProgram() is called. */
    uniID = glGetUniformLocation(shader_program,"uniID");
    glUniform1f(uniID,univar);

    glUniform3f(glGetUniformLocation(shader_program,"uniform2"),sin(3.*t),sin(t),cos(t));
    int index = glGetAttribLocation(shader_program,"myatr");

    glVertexAttrib3f(index,1.,0.,0.);

    time_evolution_triangle();

    draw_VBO();

    glfwSwapBuffers();
  }

  glfwTerminate();

  return 0;
}