Exemplo n.º 1
0
    void InventoryWindow::open()
    {
        updateEncumbranceBar();

        mTrading = false;

        mBoughtItems.clear();

        onWindowResize(static_cast<MyGUI::Window*>(mMainWidget));
    }
Exemplo n.º 2
0
 virtual void onOpen() { onWindowResize(mMainWidget->castType<MyGUI::Window>()); }
Exemplo n.º 3
0
bool RAY_CALL rayOpenWindow(const char* title, int w, int h) noexcept
{
	assert(!_gameApp && !_window);

	try
	{
		if (::glfwInit() == GL_FALSE)
			return false;

#if defined(GLFW_EXPOSE_NATIVE_X11)
		::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
		::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
		::glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
		::glfwWindowHint(GLFW_VISIBLE, false);
#else
		::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
		::glfwWindowHint(GLFW_VISIBLE, false);
#endif

		_window = ::glfwCreateWindow(w, h, title, nullptr, nullptr);
		if (_window)
		{
			::glfwSetWindowUserPointer(_window, &_gameApp);
			::glfwSetWindowFocusCallback(_window, &onWindowFocus);
			::glfwSetWindowCloseCallback(_window, &onWindowClose);
			::glfwSetWindowSizeCallback(_window, &onWindowResize);
			::glfwSetFramebufferSizeCallback(_window, &onWindowFramebufferResize);
			::glfwSetMouseButtonCallback(_window, &onWindowMouseButton);
			::glfwSetCursorPosCallback(_window, &onWindowMouseMotion);
			::glfwSetKeyCallback(_window, &onWindowKey);
			::glfwSetCharModsCallback(_window, &onWindowKeyChar);
			::glfwSetScrollCallback(_window, &onWindowSchool);
			::glfwSetDropCallback(_window, &onWindowDrop);

			auto screen = ::glfwGetVideoMode(::glfwGetPrimaryMonitor());
			::glfwSetWindowPos(_window, (screen->width - w) >> 1, (screen->height - h) >> 1);

			int widthMM, heightMM;
			::glfwGetMonitorPhysicalSize(::glfwGetPrimaryMonitor(), &widthMM, &heightMM);

			int framebuffer_w, framebuffer_h;
			::glfwGetFramebufferSize(_window, &framebuffer_w, &framebuffer_h);

			ray::WindHandle hwnd = (ray::WindHandle)::glfwGetWinHandle(_window);

			_gameApp = std::make_shared<ray::GameApplication>();
			_gameApp->setFileService(true);
			_gameApp->setFileServiceListener(true);
			_gameApp->setFileServicePath(_gameRootPath);

			if (!_gameApp->open(hwnd, w, h, framebuffer_w, framebuffer_h, screen->width / (widthMM / 25.4f) / 100.0f))
			{
				rayCloseWindow();
				return false;
			}

			onWindowFocus(_window, true);
			onWindowResize(_window, w, h);
			onWindowFramebufferResize(_window, framebuffer_w, framebuffer_h);

			if (!_gameScenePath.empty())
			{
				if (!_gameApp->openScene(_gameScenePath))
				{
					rayCloseWindow();
					return false;
				}
			}

			if (!_gameApp->start())
				return false;

			::glfwShowWindow(_window);
			return true;
		}

		return true;
	}
	catch (...)
	{
		rayCloseWindow();
		return false;
	}
}
Exemplo n.º 4
0
int main(void)
{
    if( !initContext(&context) )
    {
        fprintf(stderr, "Failed to initialize application\n");
        return -1;
    }

    window = context.window;

    GLuint VertexArrayID;
    glGenVertexArrays(1, &VertexArrayID);
    glBindVertexArray(VertexArrayID);

    // Create and compile our GLSL program from the shaders
    /* GLuint programID = LoadShaders("data/shader/SimpleVertexShader.vertexshader", "data/shader/SimpleFragmentShader.fragmentshader"); */
    Shader s("data/shader/SimpleVertexShader.vertexshader", "data/shader/SimpleFragmentShader.fragmentshader");
    /* Shader s("data/shader/font_shader.vert", "data/shader/font_shader.frag"); */
    if( !s.link() )
    {
        fprintf(stderr, "Failed to initialize main shader\n");
        return -1;
    }
    programID = s.getProgramId();

    /* Shader gui_shader("data/shader/GuiShader.vert", "data/shader/GuiShader.frag"); */
    /* Shader gui_shader("data/shader/GuiShader.vert", "data/shader/SimpleFragmentShader.fragmentshader"); */
    /* gui_shader.link(); */

	//Create vertex buffer
	GLuint vertex_buffer;
	glGenBuffers(1, &vertex_buffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

	//Create texture coordinate buffer
	GLuint texcoordbuffer;
	glGenBuffers(1, &texcoordbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, texcoordbuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_texture_coordinates), g_texture_coordinates, GL_STATIC_DRAW);


	GLuint colorbuffer;
	glGenBuffers(1, &colorbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW);

	/* GLuint projection_view_loc = glGetUniformLocation(programID, "projection_view"); */

    context.velocity = glm::vec3(0,0,0);

    int png_width, png_height;
//    GLuint font_texture = png_texture_load("data/font/monospaced_bold.png", &png_width, &png_height);
    glBindAttribLocation(programID, ATTRIB_VERTEX_POSITION_LOC, ATTRIB_VERTEX_POSITION_NAME);
    glBindAttribLocation(programID, ATTRIB_VERTEX_COLOR_LOC,    ATTRIB_VERTEX_COLOR_NAME);

    // Prepare rendering
    // 1rst attribute buffer : vertices
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glVertexAttribPointer(
            ATTRIB_VERTEX_POSITION_LOC, 3,
            GL_FLOAT, // type
            GL_FALSE, // normalized?
            0,        // stride
            (void*)0  // array buffer offset
            );
    //
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
    glVertexAttribPointer(
            1,                                // attribute. No particular reason for 1, but must match the layout in the shader.
            3,                                // size
            GL_FLOAT,                         // type
            GL_FALSE,                         // normalized?
            0,                                // stride
            (void*)0                          // array buffer offset
            );
    //
    glEnableVertexAttribArray(3);
    glBindBuffer(GL_ARRAY_BUFFER, texcoordbuffer);
    glVertexAttribPointer(
            3,
            2,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
            );

    onWindowResize(context.window, context.width, context.height);

    context.do_stop = false;
    while( !context.do_stop )
    {
        // Update timing related stuff
        context.time_last_frame = context.time_now;
        context.time_now = glfwGetTime();
        context.time_delta = context.time_now - context.time_last_frame;

        updatePhysics(&context);
        manageUserInput(&context);
        render(&context);

        // Main loop cleanup
        // TODO is this needed?
		/* glDisableVertexAttribArray(0); */

		// Swap buffers
		glfwSwapBuffers(context.window);
		glfwPollEvents();
	}

	// Cleanup VBO
	glDeleteBuffers(1, &vertex_buffer);
	glDeleteVertexArrays(1, &VertexArrayID);

	// Close OpenGL window and terminate GLFW
	glfwTerminate();

	return 0;
}