Add opengl x11 support
This commit is contained in:
		
							parent
							
								
									23694c755d
								
							
						
					
					
						commit
						670354024f
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,5 +1,5 @@
 | 
			
		||||
link/
 | 
			
		||||
.vscode/
 | 
			
		||||
earn/
 | 
			
		||||
run/
 | 
			
		||||
*.swp
 | 
			
		||||
*.swo
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@ F_ROOT=$(readlink -f "$0")
 | 
			
		||||
D_ROOT=$(dirname "${F_ROOT}")/../../.
 | 
			
		||||
D_COMPILE=${D_ROOT}/compile
 | 
			
		||||
D_LINK=${D_ROOT}/link
 | 
			
		||||
D_EARN=${D_ROOT}/earn
 | 
			
		||||
D_RUN=${D_ROOT}/run
 | 
			
		||||
F_COMPILE_LIST=${D_COMPILE}/project_files.txt
 | 
			
		||||
F_LINK_LIST=${D_LINK}/project_files.txt
 | 
			
		||||
echo "" > ${F_LINK_LIST}
 | 
			
		||||
@ -37,12 +37,12 @@ do
 | 
			
		||||
		break
 | 
			
		||||
	fi
 | 
			
		||||
	LINE=$((LINE+1))
 | 
			
		||||
	LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST}) "
 | 
			
		||||
	LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST} | tail -n 1)"
 | 
			
		||||
	echo $LIBRARY >> ${F_LIBRARY_OPTIONS}
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Link.
 | 
			
		||||
I_LINK=$(cat ${F_LINK_LIST})
 | 
			
		||||
I_LIBRARIES=$(cat ${F_LIBRARY_OPTIONS})
 | 
			
		||||
O_LINK=${D_EARN}/executable
 | 
			
		||||
O_LINK=${D_RUN}/executable
 | 
			
		||||
clang++ ${I_LIBRARIES} ${I_LINK} -o ${O_LINK}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								command/linux/rebuild_android.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								command/linux/rebuild_android.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
@ -1 +1,5 @@
 | 
			
		||||
apt install -y libx11-dev
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
apt install -y \
 | 
			
		||||
	libx11-dev \
 | 
			
		||||
	libglew-dev glew-utils libglew2.1 \
 | 
			
		||||
	libglx-dev libglx-mesa0 libglx0
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								command/linux/setup_android.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								command/linux/setup_android.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Make sure we are running this script as root.
 | 
			
		||||
[[ $EUID -ne 0 ]] && echo "This script must be run as root." && exit 1
 | 
			
		||||
 | 
			
		||||
ANDROID_CLI_TOOLS_FILE=commandlinetools-linux-7583922_latest.zip
 | 
			
		||||
ANDROID_CLI_TOOLS_LINK=https://dl.google.com/android/repository/${ANDROID_CLI_TOOLS_FILE}
 | 
			
		||||
ANDROID_CLI_TOOLS_DIR=cmdline-tools
 | 
			
		||||
ANDROID_SDK_DIR=/opt/android_sdk
 | 
			
		||||
 | 
			
		||||
wget $ANDROID_CLI_TOOLS_LINK
 | 
			
		||||
unzip $ANDROID_CLI_TOOLS_FILE
 | 
			
		||||
rm $ANDROID_CLI_TOOLS_FILE
 | 
			
		||||
mkdir $ANDROID_SDK_DIR
 | 
			
		||||
mv $ANDROID_CLI_TOOLS_DIR /opt/android_sdk/
 | 
			
		||||
 | 
			
		||||
${ANDROID_SDK_DIR}/bin/sdkmanager --sdk_root=${ANDROID_SDK_DIR} --install \
 | 
			
		||||
	"platforms;android-21" \
 | 
			
		||||
	"sources;android-21" \
 | 
			
		||||
	"platform-tools" \
 | 
			
		||||
	"build-tools;21.1.2" \
 | 
			
		||||
	"ndk;21.4.7075529"
 | 
			
		||||
@ -1,15 +1,16 @@
 | 
			
		||||
#ifndef ACT_CONTROLLER
 | 
			
		||||
#define ACT_CONTROLLER
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
class controller_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
	enum event_t {
 | 
			
		||||
		start,
 | 
			
		||||
		stop
 | 
			
		||||
	};
 | 
			
		||||
	enum status_t {
 | 
			
		||||
		ok,
 | 
			
		||||
		error
 | 
			
		||||
	};
 | 
			
		||||
	virtual status_t on_event(event_t event_p) = 0;
 | 
			
		||||
	virtual void_t<error_t> on_event(event_t event_p) = 0;
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -1,28 +1,46 @@
 | 
			
		||||
#include "act/controller.h"
 | 
			
		||||
#include "act/root.h"
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "draw/window.h"
 | 
			
		||||
root_controller_t::root_controller_t(root_controller_t::configuration_t* configuration_p) {
 | 
			
		||||
	mode_m = configuration_p->mode_m;
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include "draw/window_service.h"
 | 
			
		||||
 | 
			
		||||
root_controller_t::root_controller_t(
 | 
			
		||||
	root_controller_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p) {
 | 
			
		||||
	window_service_t* window_service = new window_service_t();
 | 
			
		||||
	window_service_t::status_t window_status = window_service->create_window();
 | 
			
		||||
	controller_t::status_t controller_status;
 | 
			
		||||
	switch (window_status) {
 | 
			
		||||
		case window_service_t::status_t::ok:
 | 
			
		||||
			controller_status = controller_t::status_t::ok;
 | 
			
		||||
			break;
 | 
			
		||||
		case window_service_t::status_t::error:
 | 
			
		||||
		default:
 | 
			
		||||
			controller_status = controller_t::status_t::error;
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	return controller_status;
 | 
			
		||||
 | 
			
		||||
void_t<controller_t::error_t> root_controller_t::on_event(
 | 
			
		||||
	controller_t::event_t event_p
 | 
			
		||||
) {
 | 
			
		||||
	text_service_t* text_service_l = configuration_m->provider_m->configuration_m->text_service_m;
 | 
			
		||||
	text_service_l->initialize(
 | 
			
		||||
	);
 | 
			
		||||
	std::string window_title = text_service_l->get_text(
 | 
			
		||||
		text_service_t::text_t::window_title
 | 
			
		||||
	).value_m;
 | 
			
		||||
	configuration_m->provider_m->configuration_m->window_service_m->create_window(
 | 
			
		||||
		&window_title
 | 
			
		||||
	);
 | 
			
		||||
	void_t<controller_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = controller_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
root_controller_t* root_controller_factory_t::create(root_controller_t::configuration_t* configuration_p) {
 | 
			
		||||
	return new root_controller_t(configuration_p);
 | 
			
		||||
 | 
			
		||||
return_t<root_controller_t::error_t, root_controller_t*> root_controller_factory_t::create(
 | 
			
		||||
	root_controller_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	return_t<root_controller_t::error_t, root_controller_t*> return_l;
 | 
			
		||||
	return_l.error_m = root_controller_t::error_t::none;
 | 
			
		||||
	return_l.value_m = new root_controller_t(configuration_p);
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
factory_t<root_controller_t::configuration_t, root_controller_t>::status_t root_controller_factory_t::dispose(root_controller_t* root_controller_p) {
 | 
			
		||||
 | 
			
		||||
void_t<root_controller_t::error_t> root_controller_factory_t::dispose(
 | 
			
		||||
	root_controller_t* root_controller_p
 | 
			
		||||
) {
 | 
			
		||||
	delete root_controller_p;
 | 
			
		||||
	return factory_t<root_controller_t::configuration_t, root_controller_t>::status_t::ok;
 | 
			
		||||
	void_t<root_controller_t::error_t> return_l;
 | 
			
		||||
	return_l.error_m = root_controller_t::error_t::none;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,24 +2,33 @@
 | 
			
		||||
#define ACT_ROOT
 | 
			
		||||
#include "act/controller.h"
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/provider.h"
 | 
			
		||||
#include <vector>
 | 
			
		||||
class root_controller_t : public controller_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum mode_t {
 | 
			
		||||
		cli,
 | 
			
		||||
		app,
 | 
			
		||||
		game
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		mode_t mode_m;
 | 
			
		||||
		provider_t* provider_m;
 | 
			
		||||
	};
 | 
			
		||||
	root_controller_t(configuration_t* configuration_p);
 | 
			
		||||
	controller_t::status_t on_event(event_t event_p) override;
 | 
			
		||||
	root_controller_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<controller_t::error_t> on_event(
 | 
			
		||||
		controller_t::event_t event_p
 | 
			
		||||
	);
 | 
			
		||||
	private:
 | 
			
		||||
	mode_t mode_m;
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
};
 | 
			
		||||
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t> {
 | 
			
		||||
	root_controller_t* create(root_controller_t::configuration_t* configuration_p) override;
 | 
			
		||||
	factory_t::status_t dispose(root_controller_t* root_controller_p) override;
 | 
			
		||||
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t, root_controller_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<root_controller_t::error_t, root_controller_t*> create(
 | 
			
		||||
		root_controller_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<root_controller_t::error_t> dispose(
 | 
			
		||||
		root_controller_t* root_controller_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,13 @@
 | 
			
		||||
#ifndef ALLOCATE_FACTORY
 | 
			
		||||
#define ALLOCATE_FACTORY
 | 
			
		||||
template <class I, class O> class factory_t {
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
template <class I, class O, class E> class factory_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum status_t {
 | 
			
		||||
		ok,
 | 
			
		||||
		error
 | 
			
		||||
	};
 | 
			
		||||
	private:
 | 
			
		||||
	virtual O* create(I* i) = 0;
 | 
			
		||||
	virtual status_t dispose(O* o) = 0;
 | 
			
		||||
	virtual return_t<E, O*> create(
 | 
			
		||||
		I* i
 | 
			
		||||
	) = 0;
 | 
			
		||||
	virtual void_t<E> dispose(
 | 
			
		||||
		O* o
 | 
			
		||||
	) = 0;
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										61
									
								
								compile/code/observable.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								compile/code/observable.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,61 @@
 | 
			
		||||
#include "code/observable.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
 | 
			
		||||
template <class V> observable_t<V>::observable_t(
 | 
			
		||||
	observable_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class V> void observable_t<V>::observe(
 | 
			
		||||
	observer_t<V>* observer_p
 | 
			
		||||
) {
 | 
			
		||||
	observer_p->on_change(configuration_m->value_m);
 | 
			
		||||
	observers_m.push_back(observer_p);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class V> void_t<observable_t::error_t> observable_t<V>::unobserve(
 | 
			
		||||
	observer_t<V>* observer_p
 | 
			
		||||
) {
 | 
			
		||||
	observable_t::error_t error_l = observable_t::error_t::not_observing;
 | 
			
		||||
	for (int i = 0; i < observers_m.size(); i++) {
 | 
			
		||||
		if (observers_m[i] == observer_p) {
 | 
			
		||||
			observers_m.erase(i);
 | 
			
		||||
			error_l = observable_t::error_t::none;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	void_t<observable_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = error_l;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class V> V observable_t<V>::get_value(
 | 
			
		||||
) {
 | 
			
		||||
	return value_m;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class V> void_t<observable_t::error_t> observable_t<V>::change(
 | 
			
		||||
	V* value_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m->value_m = value_p;
 | 
			
		||||
	for (int i = 0; i < observers_m.size(); i++) {
 | 
			
		||||
		observer_m = observers_m[i];
 | 
			
		||||
		observer_m->on_change(configuration_m->value_m);
 | 
			
		||||
	}
 | 
			
		||||
	void_t<observable_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = observable_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class V> return_t<observable_t::error_t, observable_t*> observable_factory_t<V>::create(
 | 
			
		||||
	observable_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	observable_t<V>* observable_l = new observable_t<V>(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return_t<observable_t::error_t, observable_t*> return_l;
 | 
			
		||||
	return_l.error_m = observable_t::error_t::none;
 | 
			
		||||
	return_l.value_m = observable_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										88
									
								
								compile/code/observable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								compile/code/observable.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,88 @@
 | 
			
		||||
#ifndef CODE_OBSERVABLE
 | 
			
		||||
#define CODE_OBSERVABLE
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include <vector>
 | 
			
		||||
template<class V> class observer_t {
 | 
			
		||||
	public:
 | 
			
		||||
	virtual void on_change(
 | 
			
		||||
		V* value_p
 | 
			
		||||
	) = 0;
 | 
			
		||||
};
 | 
			
		||||
template<class V> class observable_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum class error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown,
 | 
			
		||||
		not_observing
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		V* value_m;
 | 
			
		||||
	};
 | 
			
		||||
	observable_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	) {
 | 
			
		||||
		configuration_m = configuration_p;
 | 
			
		||||
	}
 | 
			
		||||
	void_t<error_t> observe(
 | 
			
		||||
		observer_t<V>* observer_p
 | 
			
		||||
	) {
 | 
			
		||||
		observer_p->on_change(configuration_m->value_m);
 | 
			
		||||
		observers_m.push_back(observer_p);
 | 
			
		||||
	}
 | 
			
		||||
	void_t<error_t> unobserve(
 | 
			
		||||
		observer_t<V>* observer_p
 | 
			
		||||
	) {
 | 
			
		||||
		observable_t::error_t error_l = observable_t::error_t::not_observing;
 | 
			
		||||
		for (int i = 0; i < observers_m.size(); i++) {
 | 
			
		||||
			if (observers_m[i] == observer_p) {
 | 
			
		||||
				observers_m.erase(i);
 | 
			
		||||
				error_l = observable_t::error_t::none;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		void_t<observable_t::error_t> void_l;
 | 
			
		||||
		void_l.error_m = error_l;
 | 
			
		||||
		return void_l;
 | 
			
		||||
	}
 | 
			
		||||
	V* get_value() {
 | 
			
		||||
		return value_m;
 | 
			
		||||
	}
 | 
			
		||||
	void_t<error_t> change(
 | 
			
		||||
		V* value_p
 | 
			
		||||
	) {
 | 
			
		||||
		configuration_m->value_m = value_p;
 | 
			
		||||
		for (int i = 0; i < observers_m.size(); i++) {
 | 
			
		||||
			observer_m = observers_m[i];
 | 
			
		||||
			observer_m->on_change(configuration_m->value_m);
 | 
			
		||||
		}
 | 
			
		||||
		void_t<observable_t::error_t> void_l;
 | 
			
		||||
		void_l.error_m = observable_t::error_t::none;
 | 
			
		||||
		return void_l;
 | 
			
		||||
	}
 | 
			
		||||
	private:
 | 
			
		||||
	std::vector<observer_t<V>*> observers_m;
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
};
 | 
			
		||||
template <class V> class observable_factory_t : public observable_t<V> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<observable_t::error_t, observable_t<V> *> create(
 | 
			
		||||
		observable_t::configuration_t configuration_p
 | 
			
		||||
	) {
 | 
			
		||||
		observable_t<V>* observable_l = new observable_t<V>(
 | 
			
		||||
			configuration_p
 | 
			
		||||
		);
 | 
			
		||||
		return_t<observable_t::error_t, observable_t*> return_l;
 | 
			
		||||
		return_l.error_m = observable_t::error_t::none;
 | 
			
		||||
		return_l.value_m = observable_l;
 | 
			
		||||
		return return_l;
 | 
			
		||||
	}
 | 
			
		||||
	void_t<observable_t::error_t> dispose(
 | 
			
		||||
		observable_t<V>* observable_p
 | 
			
		||||
	) {
 | 
			
		||||
		delete observable_p;
 | 
			
		||||
		void_t<observable_t::error_t> void_l;
 | 
			
		||||
		void_l.error_m = observable_t::error_t::none;
 | 
			
		||||
		return void_l;
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										29
									
								
								compile/code/provider.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								compile/code/provider.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
#include "code/provider.h"
 | 
			
		||||
#include "inform/text_service.h"
 | 
			
		||||
#include "draw/window_service.h"
 | 
			
		||||
 | 
			
		||||
provider_t::provider_t(
 | 
			
		||||
	provider_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<provider_t::error_t, provider_t*> provider_factory_t::create(
 | 
			
		||||
	provider_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	return_t<provider_t::error_t, provider_t*> return_l;
 | 
			
		||||
	return_l.error_m = provider_t::error_t::none;
 | 
			
		||||
	return_l.value_m = new provider_t(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<provider_t::error_t> provider_factory_t::dispose(
 | 
			
		||||
	provider_t* provider_p
 | 
			
		||||
) {
 | 
			
		||||
	delete provider_p;
 | 
			
		||||
	void_t<provider_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = provider_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								compile/code/provider.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								compile/code/provider.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
#ifndef CODE_PROVIDER
 | 
			
		||||
#define CODE_PROVIDER
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include "inform/text_service.h"
 | 
			
		||||
#include "draw/window_service.h"
 | 
			
		||||
class provider_t {
 | 
			
		||||
	friend class provider_factory_t;
 | 
			
		||||
	public:
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		text_service_t* text_service_m;
 | 
			
		||||
		window_service_t* window_service_m;
 | 
			
		||||
	};
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
	private:
 | 
			
		||||
	provider_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
class provider_factory_t : public factory_t<provider_t::configuration_t, provider_t, provider_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<provider_t::error_t, provider_t*> create(
 | 
			
		||||
		provider_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<provider_t::error_t> dispose(
 | 
			
		||||
		provider_t* root_controller_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										16
									
								
								compile/code/return.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								compile/code/return.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
#ifndef CODE_RETURN
 | 
			
		||||
#define CODE_RETURN
 | 
			
		||||
class empty_t {
 | 
			
		||||
};
 | 
			
		||||
template <class E, class D> class return_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum component_t {
 | 
			
		||||
		render
 | 
			
		||||
	};
 | 
			
		||||
	component_t component_m;
 | 
			
		||||
	E error_m;
 | 
			
		||||
	D value_m;
 | 
			
		||||
};
 | 
			
		||||
template <class E> class void_t : public return_t<E, empty_t> {
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										81
									
								
								compile/draw/opengl_service.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								compile/draw/opengl_service.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,81 @@
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include "draw/opengl_service.h"
 | 
			
		||||
 | 
			
		||||
opengl_service_t::opengl_service_t(
 | 
			
		||||
	opengl_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_service_t::error_t> opengl_service_t::draw_quad(
 | 
			
		||||
) {
 | 
			
		||||
	glClearColor(1.0, 1.0, 1.0, 1.0);
 | 
			
		||||
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
	glMatrixMode(GL_PROJECTION);
 | 
			
		||||
	glLoadIdentity();
 | 
			
		||||
	glOrtho(-1., 1., -1., 1., 1., 20.);
 | 
			
		||||
 | 
			
		||||
	glMatrixMode(GL_MODELVIEW);
 | 
			
		||||
	glLoadIdentity();
 | 
			
		||||
	gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
 | 
			
		||||
 | 
			
		||||
	glBegin(GL_QUADS);
 | 
			
		||||
	glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
 | 
			
		||||
	glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
 | 
			
		||||
	glColor3f(0., 0., 1.); glVertex3f( .75,  .75, 0.);
 | 
			
		||||
	glColor3f(1., 1., 0.); glVertex3f(-.75,  .75, 0.);
 | 
			
		||||
	glEnd();
 | 
			
		||||
	void_t<opengl_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_service_t::error_t> opengl_service_t::enable_depth_test(
 | 
			
		||||
) {
 | 
			
		||||
	glEnable(
 | 
			
		||||
		GL_DEPTH_TEST
 | 
			
		||||
	);
 | 
			
		||||
	void_t<opengl_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_service_t::error_t> opengl_service_t::resize_viewport(
 | 
			
		||||
	int x,
 | 
			
		||||
	int y,
 | 
			
		||||
	int width,
 | 
			
		||||
	int height
 | 
			
		||||
) {
 | 
			
		||||
	void_t<opengl_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_service_t::error_t::none;
 | 
			
		||||
	glViewport(
 | 
			
		||||
		0,
 | 
			
		||||
		0,
 | 
			
		||||
		width,
 | 
			
		||||
		height
 | 
			
		||||
	);
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<opengl_service_t::error_t, opengl_service_t*> opengl_service_factory_t::create(
 | 
			
		||||
	opengl_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	opengl_service_t* opengl_service_l = new opengl_service_t(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return_t<opengl_service_t::error_t, opengl_service_t*> return_l;
 | 
			
		||||
	return_l.error_m = opengl_service_t::error_t::none;
 | 
			
		||||
	return_l.value_m = opengl_service_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_service_t::error_t> opengl_service_factory_t::dispose(
 | 
			
		||||
	opengl_service_t* opengl_service_p
 | 
			
		||||
) {
 | 
			
		||||
	delete opengl_service_p;
 | 
			
		||||
	void_t<opengl_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								compile/draw/opengl_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								compile/draw/opengl_service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
			
		||||
#ifndef SERVICE_RENDER
 | 
			
		||||
#define SERVICE_RENDER
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <X11/X.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glx.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
class opengl_service_t {
 | 
			
		||||
	friend class opengl_service_factory_t;
 | 
			
		||||
	public:
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
	};
 | 
			
		||||
	void_t<error_t> draw_quad(
 | 
			
		||||
	);
 | 
			
		||||
	void_t<error_t> enable_depth_test(
 | 
			
		||||
	);
 | 
			
		||||
	void_t<error_t> resize_viewport(
 | 
			
		||||
		int x,
 | 
			
		||||
		int y,
 | 
			
		||||
		int width,
 | 
			
		||||
		int height
 | 
			
		||||
	);
 | 
			
		||||
	private:
 | 
			
		||||
	opengl_service_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
};
 | 
			
		||||
class opengl_service_factory_t : public factory_t<opengl_service_t::configuration_t, opengl_service_t, opengl_service_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<opengl_service_t::error_t, opengl_service_t*> create(
 | 
			
		||||
		opengl_service_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<opengl_service_t::error_t> dispose(
 | 
			
		||||
		opengl_service_t* opengl_service_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,11 +0,0 @@
 | 
			
		||||
#ifndef SERVICE_WINDOW
 | 
			
		||||
#define SERVICE_WINDOW
 | 
			
		||||
class window_service_t {
 | 
			
		||||
	public:
 | 
			
		||||
	enum status_t {
 | 
			
		||||
		ok,
 | 
			
		||||
		error
 | 
			
		||||
	};
 | 
			
		||||
	status_t create_window();
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										35
									
								
								compile/draw/window_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								compile/draw/window_service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
#ifndef SERVICE_WINDOW
 | 
			
		||||
#define SERVICE_WINDOW
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include "inform/text_service.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
class window_service_t {
 | 
			
		||||
	friend class window_service_factory_t;
 | 
			
		||||
	public:
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown,
 | 
			
		||||
		x_server_connection_failure
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
	};
 | 
			
		||||
	void_t<error_t>  create_window(
 | 
			
		||||
		std::string* window_title
 | 
			
		||||
	);
 | 
			
		||||
	private:
 | 
			
		||||
	window_service_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
};
 | 
			
		||||
class window_service_factory_t : public factory_t<window_service_t::configuration_t, window_service_t, window_service_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<window_service_t::error_t, window_service_t*> create(
 | 
			
		||||
		window_service_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<window_service_t::error_t> dispose(
 | 
			
		||||
		window_service_t* window_service_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										60
									
								
								compile/inform/text_service.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								compile/inform/text_service.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
			
		||||
#include "inform/text_service.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
text_service_t::text_service_t(
 | 
			
		||||
	text_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void text_service_t::update(
 | 
			
		||||
	text_service_t::text_t text_p,
 | 
			
		||||
	std::string string_p
 | 
			
		||||
) {
 | 
			
		||||
	text_to_string[text_p] = string_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<text_service_t::error_t> text_service_t::initialize(
 | 
			
		||||
) {
 | 
			
		||||
	text_service_t::language_t language_l = configuration_m->language_m;
 | 
			
		||||
	switch (language_l) {
 | 
			
		||||
		case text_service_t::language_t::english:
 | 
			
		||||
			update(text_service_t::text_t::window_title, "Fortuitous Frogs");
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	void_t<text_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = text_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<text_service_t::error_t, std::string> text_service_t::get_text(
 | 
			
		||||
	text_service_t::text_t text_p
 | 
			
		||||
) {
 | 
			
		||||
	std::string string_l = text_to_string[text_p];
 | 
			
		||||
	return_t<text_service_t::error_t, std::string> return_l;
 | 
			
		||||
	return_l.error_m = text_service_t::error_t::none;
 | 
			
		||||
	return_l.value_m = string_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<text_service_t::error_t, text_service_t*> text_service_factory_t::create(
 | 
			
		||||
	text_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	text_service_t* text_service_l = new text_service_t(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return_t<text_service_t::error_t, text_service_t*> return_l;
 | 
			
		||||
	return_l.error_m = text_service_t::error_t::none;
 | 
			
		||||
	return_l.value_m = text_service_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<text_service_t::error_t> text_service_factory_t::dispose(
 | 
			
		||||
	text_service_t* text_service_p
 | 
			
		||||
) {
 | 
			
		||||
	delete text_service_p;
 | 
			
		||||
	void_t<text_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = text_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										52
									
								
								compile/inform/text_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								compile/inform/text_service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
#ifndef INTEGRATE_TEXT_SERVICE
 | 
			
		||||
#define INTEGRATE_TEXT_SERVICE
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <map>
 | 
			
		||||
class text_service_t {
 | 
			
		||||
	friend class text_service_factory_t;
 | 
			
		||||
	public:
 | 
			
		||||
	enum status_t {
 | 
			
		||||
		ok,
 | 
			
		||||
		error
 | 
			
		||||
	};
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown
 | 
			
		||||
	};
 | 
			
		||||
	enum language_t {
 | 
			
		||||
		english
 | 
			
		||||
	};
 | 
			
		||||
	enum text_t {
 | 
			
		||||
		window_title
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		language_t language_m;
 | 
			
		||||
	};
 | 
			
		||||
	return_t<error_t, std::string> get_text(
 | 
			
		||||
		text_t text_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<error_t> initialize(
 | 
			
		||||
	);
 | 
			
		||||
	private:
 | 
			
		||||
	text_service_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
	std::map<text_t, std::string> text_to_string;
 | 
			
		||||
	void update(
 | 
			
		||||
		text_t text_p,
 | 
			
		||||
		std::string string_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
class text_service_factory_t : public factory_t<text_service_t::configuration_t, text_service_t, text_service_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<text_service_t::error_t, text_service_t*> create(
 | 
			
		||||
		text_service_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<text_service_t::error_t> dispose(
 | 
			
		||||
		text_service_t* text_service_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
@ -1 +1,3 @@
 | 
			
		||||
X11
 | 
			
		||||
GL
 | 
			
		||||
GLU
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,60 @@
 | 
			
		||||
#include "act/controller.h"
 | 
			
		||||
#include "act/root.h"
 | 
			
		||||
#include "code/provider.h"
 | 
			
		||||
#include <vector>
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
	root_controller_t::configuration_t configuration_l;
 | 
			
		||||
	configuration_l.mode_m = root_controller_t::mode_t::app;
 | 
			
		||||
	root_controller_t* controller_l = new root_controller_t(&configuration_l);
 | 
			
		||||
	controller_t::status_t status_l = controller_l->on_event(controller_t::event_t::start);
 | 
			
		||||
	delete controller_l;
 | 
			
		||||
	return status_l;
 | 
			
		||||
	// Create text service.
 | 
			
		||||
	text_service_factory_t text_service_factory_l;
 | 
			
		||||
	text_service_t::configuration_t text_service_configuration_l;
 | 
			
		||||
	text_service_configuration_l.language_m = text_service_t::language_t::english;
 | 
			
		||||
	text_service_t* text_service_l = text_service_factory_l.create(
 | 
			
		||||
		&text_service_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	// Create window service.
 | 
			
		||||
	window_service_factory_t window_service_factory_l;
 | 
			
		||||
	window_service_t::configuration_t window_service_configuration_l;
 | 
			
		||||
	window_service_t* window_service_l = window_service_factory_l.create(
 | 
			
		||||
		&window_service_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	// Create provider.
 | 
			
		||||
	provider_factory_t provider_factory_l;
 | 
			
		||||
	provider_t::configuration_t provider_configuration_l;
 | 
			
		||||
	provider_configuration_l.text_service_m = text_service_l;
 | 
			
		||||
	provider_configuration_l.window_service_m = window_service_l;
 | 
			
		||||
	provider_t* provider_l = provider_factory_l.create(
 | 
			
		||||
		&provider_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	// Create root controller.
 | 
			
		||||
	root_controller_factory_t root_controller_factory_l;
 | 
			
		||||
	root_controller_t::configuration_t root_controller_configuration_l;
 | 
			
		||||
	root_controller_configuration_l.provider_m = provider_l;
 | 
			
		||||
	root_controller_t* root_controller_l = root_controller_factory_l.create(
 | 
			
		||||
		&root_controller_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	// Start root controller.
 | 
			
		||||
	controller_t::error_t root_controller_event_l = root_controller_l->on_event(
 | 
			
		||||
		controller_t::event_t::start
 | 
			
		||||
	).error_m;
 | 
			
		||||
 | 
			
		||||
	// Clean up
 | 
			
		||||
	root_controller_factory_l.dispose(
 | 
			
		||||
		root_controller_l
 | 
			
		||||
	);
 | 
			
		||||
	provider_factory_l.dispose(
 | 
			
		||||
		provider_l
 | 
			
		||||
	);
 | 
			
		||||
	window_service_factory_l.dispose(
 | 
			
		||||
		window_service_l
 | 
			
		||||
	);
 | 
			
		||||
	text_service_factory_l.dispose(
 | 
			
		||||
		text_service_l
 | 
			
		||||
	);
 | 
			
		||||
	if (root_controller_event_l == controller_t::error_t::none) {
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,7 @@
 | 
			
		||||
main.cpp
 | 
			
		||||
act/root.cpp
 | 
			
		||||
target/linux/draw/window.cpp
 | 
			
		||||
code/provider.cpp
 | 
			
		||||
draw/opengl_service.cpp
 | 
			
		||||
inform/text_service.cpp
 | 
			
		||||
target/linux/draw/window_service.cpp
 | 
			
		||||
target/linux/draw/opengl_x11_service.cpp
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										115
									
								
								compile/target/linux/draw/opengl_x11_service.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								compile/target/linux/draw/opengl_x11_service.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,115 @@
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include "target/linux/draw/opengl_x11_service.h"
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <X11/X.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glx.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
 | 
			
		||||
opengl_x11_service_t::opengl_x11_service_t(
 | 
			
		||||
	opengl_x11_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<opengl_x11_service_t::error_t, XVisualInfo*> opengl_x11_service_t::get_visual_info(
 | 
			
		||||
	Display* display_p
 | 
			
		||||
) {
 | 
			
		||||
	return_t<opengl_x11_service_t::error_t, XVisualInfo*> return_l;
 | 
			
		||||
	return_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	GLint attributes_l[] = {
 | 
			
		||||
		GLX_RGBA,
 | 
			
		||||
		GLX_DEPTH_SIZE,
 | 
			
		||||
		24,
 | 
			
		||||
		GLX_DOUBLEBUFFER,
 | 
			
		||||
		None
 | 
			
		||||
	};
 | 
			
		||||
	XVisualInfo *visual_info_l = glXChooseVisual(
 | 
			
		||||
		display_p,
 | 
			
		||||
		0,
 | 
			
		||||
		attributes_l
 | 
			
		||||
	);
 | 
			
		||||
	if (visual_info_l == NULL) {
 | 
			
		||||
		return_l.error_m = opengl_x11_service_t::error_t::no_visual_found;
 | 
			
		||||
	}
 | 
			
		||||
	return_l.value_m = visual_info_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::initialize_context(
 | 
			
		||||
	Display* display_p,
 | 
			
		||||
	XVisualInfo* visual_info_p,
 | 
			
		||||
	Window window_p
 | 
			
		||||
){
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> void_l;
 | 
			
		||||
	configuration_m->glx_context_m = glXCreateContext(
 | 
			
		||||
		display_p,
 | 
			
		||||
		visual_info_p,
 | 
			
		||||
		NULL,
 | 
			
		||||
		GL_TRUE
 | 
			
		||||
	);
 | 
			
		||||
	glXMakeCurrent(
 | 
			
		||||
		display_p,
 | 
			
		||||
		window_p,
 | 
			
		||||
		configuration_m->glx_context_m
 | 
			
		||||
	);
 | 
			
		||||
	void_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::swap_buffers(
 | 
			
		||||
	Display* display_p,
 | 
			
		||||
	Window window_p
 | 
			
		||||
) {
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	glXSwapBuffers(
 | 
			
		||||
		display_p,
 | 
			
		||||
		window_p
 | 
			
		||||
	);
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_x11_service_t::error_t> opengl_x11_service_t::dispose(
 | 
			
		||||
	Display* display_p
 | 
			
		||||
) {
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	glXMakeCurrent(
 | 
			
		||||
		display_p,
 | 
			
		||||
		None,
 | 
			
		||||
		NULL
 | 
			
		||||
	);
 | 
			
		||||
	glXDestroyContext(
 | 
			
		||||
		display_p,
 | 
			
		||||
		configuration_m->glx_context_m
 | 
			
		||||
	);
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> opengl_x11_service_factory_t::create(
 | 
			
		||||
	opengl_x11_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	opengl_x11_service_t* opengl_x11_service_l = new opengl_x11_service_t(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> return_l;
 | 
			
		||||
	return_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	return_l.value_m = opengl_x11_service_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<opengl_x11_service_t::error_t> opengl_x11_service_factory_t::dispose(
 | 
			
		||||
	opengl_x11_service_t* opengl_x11_service_p
 | 
			
		||||
) {
 | 
			
		||||
	delete opengl_x11_service_p;
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = opengl_x11_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								compile/target/linux/draw/opengl_x11_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								compile/target/linux/draw/opengl_x11_service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
			
		||||
#ifndef DRAW_OPENGL_X11_SERVICE
 | 
			
		||||
#define DRAW_OPENGL_X11_SERVICE
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "code/return.h"
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <X11/X.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glx.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
class opengl_x11_service_t {
 | 
			
		||||
	friend class opengl_x11_service_factory_t;
 | 
			
		||||
	public:
 | 
			
		||||
	enum error_t {
 | 
			
		||||
		none,
 | 
			
		||||
		unknown,
 | 
			
		||||
		no_visual_found
 | 
			
		||||
	};
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		GLXContext glx_context_m;
 | 
			
		||||
	};
 | 
			
		||||
	return_t<opengl_x11_service_t::error_t, XVisualInfo*> get_visual_info(
 | 
			
		||||
		Display* display_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<error_t> initialize_context(
 | 
			
		||||
		Display* display_p,
 | 
			
		||||
		XVisualInfo* visual_info_p,
 | 
			
		||||
		Window window_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> swap_buffers(
 | 
			
		||||
		Display* display_p,
 | 
			
		||||
		Window window_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<error_t> dispose(
 | 
			
		||||
		Display* display_p
 | 
			
		||||
	);
 | 
			
		||||
	private:
 | 
			
		||||
	opengl_x11_service_t(
 | 
			
		||||
		configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	configuration_t* configuration_m;
 | 
			
		||||
};
 | 
			
		||||
class opengl_x11_service_factory_t : public factory_t<opengl_x11_service_t::configuration_t, opengl_x11_service_t, opengl_x11_service_t::error_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	return_t<opengl_x11_service_t::error_t, opengl_x11_service_t*> create(
 | 
			
		||||
		opengl_x11_service_t::configuration_t* configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	void_t<opengl_x11_service_t::error_t> dispose(
 | 
			
		||||
		opengl_x11_service_t* opengl_x11_service_p
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,31 +0,0 @@
 | 
			
		||||
#include "draw/window.h"
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
window_service_t::status_t window_service_t::create_window() {
 | 
			
		||||
	Display *d;
 | 
			
		||||
	Window w;
 | 
			
		||||
	XEvent e;
 | 
			
		||||
	const char *msg = "Hello, World!";
 | 
			
		||||
	int s;
 | 
			
		||||
	d = XOpenDisplay(NULL);
 | 
			
		||||
	if (d == NULL) {
 | 
			
		||||
		return window_service_t::status_t::error;
 | 
			
		||||
	}
 | 
			
		||||
	s = DefaultScreen(d);
 | 
			
		||||
	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s));
 | 
			
		||||
	XSelectInput(d, w, ExposureMask | KeyPressMask);
 | 
			
		||||
	XMapWindow(d, w);
 | 
			
		||||
	while (true) {
 | 
			
		||||
		XNextEvent(d, &e);
 | 
			
		||||
		if (e.type == Expose) {
 | 
			
		||||
			XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
 | 
			
		||||
			XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
 | 
			
		||||
		}
 | 
			
		||||
		if (e.type == KeyPress)
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	XCloseDisplay(d);
 | 
			
		||||
	return window_service_t::status_t::ok;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										158
									
								
								compile/target/linux/draw/window_service.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								compile/target/linux/draw/window_service.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,158 @@
 | 
			
		||||
#include "draw/opengl_service.h"
 | 
			
		||||
#include "draw/window_service.h"
 | 
			
		||||
#include "inform/text_service.h"
 | 
			
		||||
#include "target/linux/draw/opengl_x11_service.h"
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <X11/X.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glx.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
 | 
			
		||||
window_service_t::window_service_t(
 | 
			
		||||
	window_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<window_service_t::error_t> window_service_t::create_window(
 | 
			
		||||
	std::string* window_title
 | 
			
		||||
) {
 | 
			
		||||
	void_t<window_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = window_service_t::error_t::unknown;
 | 
			
		||||
	Display* display_l = XOpenDisplay(
 | 
			
		||||
		NULL
 | 
			
		||||
	);
 | 
			
		||||
	if (display_l == NULL) {
 | 
			
		||||
		void_l.error_m = window_service_t::error_t::x_server_connection_failure;
 | 
			
		||||
		return void_l;
 | 
			
		||||
	}
 | 
			
		||||
	Window root_window_l = DefaultRootWindow(
 | 
			
		||||
		display_l
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	// Create OpenGL X11 Service for binding
 | 
			
		||||
	opengl_x11_service_t::configuration_t opengl_x11_service_configuration_l;
 | 
			
		||||
	opengl_x11_service_factory_t opengl_x11_service_factory_l;
 | 
			
		||||
	opengl_x11_service_t* opengl_x11_service_l = opengl_x11_service_factory_l.create(
 | 
			
		||||
		&opengl_x11_service_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	XVisualInfo* visual_info_l = opengl_x11_service_l->get_visual_info(
 | 
			
		||||
		display_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
	Colormap colormap_l = XCreateColormap(
 | 
			
		||||
		display_l,
 | 
			
		||||
		root_window_l,
 | 
			
		||||
		visual_info_l->visual,
 | 
			
		||||
		AllocNone
 | 
			
		||||
	);
 | 
			
		||||
	XSetWindowAttributes set_window_attributes_l;
 | 
			
		||||
	set_window_attributes_l.colormap = colormap_l;
 | 
			
		||||
	set_window_attributes_l.event_mask = ExposureMask | KeyPressMask;
 | 
			
		||||
	Window window_l = XCreateWindow(
 | 
			
		||||
		display_l,
 | 
			
		||||
		root_window_l,
 | 
			
		||||
		0,
 | 
			
		||||
		0,
 | 
			
		||||
		320,
 | 
			
		||||
		240,
 | 
			
		||||
		0,
 | 
			
		||||
		visual_info_l->depth,
 | 
			
		||||
		InputOutput,
 | 
			
		||||
		visual_info_l->visual,
 | 
			
		||||
		CWColormap | CWEventMask,
 | 
			
		||||
		&set_window_attributes_l
 | 
			
		||||
	);
 | 
			
		||||
	XMapWindow(
 | 
			
		||||
		display_l,
 | 
			
		||||
		window_l
 | 
			
		||||
	);
 | 
			
		||||
	XStoreName(
 | 
			
		||||
		display_l,
 | 
			
		||||
		window_l,
 | 
			
		||||
		window_title->data()
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	opengl_x11_service_l->initialize_context(
 | 
			
		||||
		display_l,
 | 
			
		||||
		visual_info_l,
 | 
			
		||||
		window_l
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	// Create OpenGL Service for rendering
 | 
			
		||||
	opengl_service_t::configuration_t opengl_service_configuration_l;
 | 
			
		||||
	opengl_service_factory_t opengl_service_factory_l;
 | 
			
		||||
	opengl_service_t* opengl_service_l = opengl_service_factory_l.create(
 | 
			
		||||
		&opengl_service_configuration_l
 | 
			
		||||
	).value_m;
 | 
			
		||||
 | 
			
		||||
	opengl_service_l->enable_depth_test(
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	XEvent event_l;
 | 
			
		||||
	XWindowAttributes window_attributes_l;
 | 
			
		||||
	while(true) {
 | 
			
		||||
		XNextEvent(
 | 
			
		||||
			display_l,
 | 
			
		||||
			&event_l
 | 
			
		||||
		);
 | 
			
		||||
		if (event_l.type == Expose) {
 | 
			
		||||
			XGetWindowAttributes(
 | 
			
		||||
				display_l,
 | 
			
		||||
				window_l,
 | 
			
		||||
				&window_attributes_l
 | 
			
		||||
			);
 | 
			
		||||
			opengl_service_l->resize_viewport(
 | 
			
		||||
				0,
 | 
			
		||||
				0,
 | 
			
		||||
				window_attributes_l.width,
 | 
			
		||||
				window_attributes_l.height
 | 
			
		||||
			);
 | 
			
		||||
			opengl_service_l->draw_quad(
 | 
			
		||||
			);
 | 
			
		||||
			opengl_x11_service_l->swap_buffers(
 | 
			
		||||
				display_l,
 | 
			
		||||
				window_l
 | 
			
		||||
			);
 | 
			
		||||
		} else if (event_l.type == KeyPress) {
 | 
			
		||||
			opengl_x11_service_l->dispose(
 | 
			
		||||
				display_l
 | 
			
		||||
			);
 | 
			
		||||
			XDestroyWindow(
 | 
			
		||||
				display_l,
 | 
			
		||||
				window_l
 | 
			
		||||
			);
 | 
			
		||||
			XCloseDisplay(
 | 
			
		||||
				display_l
 | 
			
		||||
			);
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	void_l.error_m = window_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
return_t<window_service_t::error_t, window_service_t*> window_service_factory_t::create(
 | 
			
		||||
	window_service_t::configuration_t* configuration_p
 | 
			
		||||
) {
 | 
			
		||||
	return_t<window_service_t::error_t, window_service_t*> return_l;
 | 
			
		||||
	return_l.error_m = window_service_t::error_t::none;
 | 
			
		||||
	window_service_t* window_service_l = new window_service_t(
 | 
			
		||||
		configuration_p
 | 
			
		||||
	);
 | 
			
		||||
	return_l.value_m = window_service_l;
 | 
			
		||||
	return return_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void_t<window_service_t::error_t> window_service_factory_t::dispose(
 | 
			
		||||
	window_service_t* window_service_p
 | 
			
		||||
) {
 | 
			
		||||
	delete window_service_p;
 | 
			
		||||
	void_t<window_service_t::error_t> void_l;
 | 
			
		||||
	void_l.error_m = window_service_t::error_t::none;
 | 
			
		||||
	return void_l;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user