Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.60 KB | None | 0 0
  1. import std.stdio;
  2. import std.conv;
  3.  
  4. import derelict.glfw3.glfw3;
  5. import derelict.opengl3.gl;
  6.  
  7. extern(C) void glfw_error_callback(int error, const(char) *description) nothrow {
  8.     printf("%s\n", description);
  9. }
  10.  
  11. void draw(GLFWwindow *window) {
  12.     int width;
  13.     int height;
  14.     glfwGetFramebufferSize(window, &width, &height);
  15.     glViewport(0, 0, width, height);
  16.  
  17.     glMatrixMode(GL_PROJECTION);
  18.     glLoadIdentity();
  19.     glOrtho(0, width, height, 0, -1, 1);
  20.     glMatrixMode(GL_MODELVIEW);
  21.     glLoadIdentity();
  22.  
  23.     glClearColor(0, 0, 0, 1);
  24.     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  25.    
  26.     glBegin(GL_QUADS);
  27.     glColor4f(1, 0, 0, 1); glVertex2f(0, 0);
  28.     glColor4f(0, 1, 0, 1); glVertex2f(0, 1);
  29.     glColor4f(0, 0, 1, 1); glVertex2f(1, 1);
  30.     glColor4f(1, 0, 1, 1); glVertex2f(1, 0);
  31.     glEnd();
  32.  
  33.     glFlush();
  34. }
  35.  
  36. void main() {
  37.     DerelictGLFW3.load();
  38.     DerelictGL.load();
  39.  
  40.     if(glfwInit() != GLFW_TRUE) {
  41.         glfwTerminate();
  42.         writeln("Failed to initialize GLFW3");
  43.         return;
  44.     }
  45.  
  46.     printf("GLFW Version: %s\n", glfwGetVersionString());
  47.  
  48.     glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
  49.     glfwSetErrorCallback(&glfw_error_callback);
  50.  
  51.     GLFWwindow *window = glfwCreateWindow(800, 600, "The Source", null, null);
  52.     if(!window) {
  53.         glfwTerminate();
  54.         writeln("Failed to initialize window");
  55.         return;
  56.     }
  57.  
  58.     glfwMakeContextCurrent(window);
  59.    
  60.     printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
  61.  
  62.     glfwSwapInterval(1);
  63.  
  64.     writeln("Welcome to the Source.");
  65.  
  66.     stdout.flush();
  67.  
  68.     while(!glfwWindowShouldClose(window)) {
  69.         draw(window);
  70.  
  71.         glfwSwapBuffers(window);
  72.         glfwPollEvents();
  73.     }
  74.  
  75.     glfwTerminate();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement