Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.string : toStringz;
- import std.stdio;
- import std.concurrency;
- import derelict.glfw3.glfw3;
- import derelict.opengl3.gl3;
- enum REQ_WIDTH = 600;
- enum REQ_HEIGHT = 300;
- enum APP_TITLE = "window";
- struct Data {
- int x;
- }
- struct Window {
- this(ref Data data) {
- DerelictGLFW3.load();
- DerelictGL3.load();
- glfwInit();
- }
- void create() {
- _wnd = glfwCreateWindow(REQ_WIDTH, REQ_HEIGHT, APP_TITLE.toStringz(), null, null);
- glfwShowWindow(_wnd);
- glfwMakeContextCurrent(_wnd);
- DerelictGL3.reload();
- auto tid = spawn(&runNewView);
- send(tid, _wnd );
- while ( !glfwWindowShouldClose(_wnd) ) {
- glfwWaitEvents();
- glfwSwapBuffers(_wnd);
- }
- }
- GLFWwindow* _wnd;
- }
- void runNewView() {
- while ( true ) {
- receive (
- (string msg) { writeln(msg); },
- (const(GLFWwindow*) window) { glfwMakeContextCurrent(window); }
- );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- // draw stuff
- }
- }
- void main(string[] args) {
- Data mydata = { 0 };
- auto window = Window(mydata);
- // runs main loop
- window.create();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement