Colimits for gluing schemes and the functor of points 1 Closely related questions been asked several times in different forms on here but I feel like none really spell out what's going on. I have been looking more at glueing schemes, and particularly relative glueing to construct the projective bundle over a scheme and I really want to understand what is going on in terms of colimits in the category of schemes. 
I am hoping to break this into two questions since it will be a lot to include in just one. First let's say I just have a pair of topological spaces, $X_{1}$ and $X_{2}$ with $U_{1} \subseteq X$ and $U_{2} \subseteq X$ open sets with a homeomorphism 
$$
\phi: U_{1} \stackrel{\simeq}{\longrightarrow} U_{2}
$$
Now say I want to glue $X_{1}$ and $X_{2}$ along the homeomorphism $\phi$. As a set, this is not hard to write down just as a disjoint union modulo the relation $p \sim \phi(p)$. But what is actually going on here categorically? If there is no gluing involved, then we just have the categorical sum, 
$$
X = X_{1} \sqcup X_{2}.
$$
This has the universal property that to give a morphism from $X$ is precisely to give a morphism from $X_{1}$ and a morphism from $X_{2}$. As someone brand new to the idea of a functor of points, can $X$ then be seen as a representing object for some functor of points? 
When we try to incorporate glueing along $\phi$ is when I get more confused. In some sense, I need a colimit that captures the notion:

To give a morphism from $X$ to some $Y$ is precisely to give morphisms $\psi_{1}: X_{1} \rightarrow Y$ and $\psi_{2}: X_{2} \rightarrow Y$ so that $\psi_{1} = \psi_{2} \circ \phi$ on $U$.

I suspect that this is somehow a coequalizer, but I haven't been able to formulate it. So what diagram should I take so that $X_{1} \sqcup X_{2} / \sim$ is the colimit object? 
This seems to be complicated even further if I have more than two objects to glue. Say I have a family $\{ X_{i} \}_{i \in I}$ with open subsets $U_{ij} \subseteq X_{i}$ along with homeomorphisms 
$$\phi_{ij}: U_{ij} \stackrel{\simeq}{\longrightarrow} U_{ji}  $$
satisfying the appropriate cocycle condition. Can the resulting space formed from gluing be realized as a colimit of some diagram? Is there some generalization of a coequalizer? And again, can this be realized as the representing object of some functor of points? 
Is there any reference either in the category theory or the topology literature that treats gluing explicitly in this way?
I'm hoping to ask another question later specifically about certain colimits in the category of schemes, but I wanted to simplify things first by only considering the topological side of things. 
Any insight into this would be appreciated. 
 A: You can write the first gluing as a pushout. The second can be seen as a coequalizer diagram $$\coprod_{i,j} U_{i,j}\rightrightarrows \coprod
_iU_i\to X$$
The upper horizontal map includes each $U_{i,j}$ into its superspace $U_i$. The $i,j$-th component of the lower horizontal map  is $U_{i,j}\cong U_{j,i}\to U_j$. In a coequalizer diagram as above I always view the space $\coprod_iU_i$ as the material you like to glue, and what is on the left are the gluing conditions.
If you want to know the functor of points of $X$, then you need to compute what the morphisms $\text{Spec }R\to X$ are. For field valued points this is easy. If $K$ is a field then
$$\coprod_{i,j} U_{i,j}(K) \rightrightarrows \coprod
_iU_i(K) \to X(K)$$
is a coequalizer diagram. This corresponds to the fact that the underlying topological space of the scheme $X$ is the colimit of the topological spaces of the $U_i$. But in general $\text{Spec } R$ does not look point like, and the geometric picture suggests that a morphism $\text{Spec }R\to X$ must only locally lie in a subspace $U_i$.
Proposition. A morphism $x:\text{Spec }R\to X$ is determined by a collection  of morphism $x_k: \text{Spec }R[1/f_k] \to U_{i_k}$ on an open cover $(f_1,...,f_n)=(1)$ of $R$ which agree on overlaps modulo the compatibility isomorphisms $U_{i_ki_l}\cong U_{i_li_k}$ if their codomains are unequal. A second such collection $y_l:\text{Spec }R[1/g_l]\to U_{j_l}$ defines the same morphism $x_k$ if and only if they have a common refinement where they are equal (modulo the isomorphisms $U_{ij}=U_{ji}$ of course).
This is a description of the functor of points, and it is as nice as it gets. But it certainly makes sense from the geometric viewpoint. Picture a space covered by some open subspaces and a curve, which crosses some of the open subspaces. It does not lie completely in any of the $U_i$, but it lies locally in the $U_i$.
In fact, if we stay completely in the functor of points picture, then the coequalizer in $\text{Sh}(\text{Aff})$ can be formed by taking the coequalizer in the presheaf category $\text{Pr}(\text{Aff})$ and sheafifying it (see Grothendieck topology on a category). Here $\text{Aff}$ is the opposite of the category of affine schemes (equivalently the opposite of the category of commutative rings).
