Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.conv;
- import derelict.glfw3.glfw3;
- import derelict.opengl3.gl;
- extern(C) void glfw_error_callback(int error, const(char) *description) nothrow {
- printf("%s\n", description);
- }
- void draw(GLFWwindow *window) {
- int width;
- int height;
- glfwGetFramebufferSize(window, &width, &height);
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, height, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClearColor(0, 0, 0, 1);
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- glBegin(GL_QUADS);
- glColor4f(1, 0, 0, 1); glVertex2f(0, 0);
- glColor4f(0, 1, 0, 1); glVertex2f(0, 1);
- glColor4f(0, 0, 1, 1); glVertex2f(1, 1);
- glColor4f(1, 0, 1, 1); glVertex2f(1, 0);
- glEnd();
- glFlush();
- }
- void main() {
- DerelictGLFW3.load();
- DerelictGL.load();
- if(glfwInit() != GLFW_TRUE) {
- glfwTerminate();
- writeln("Failed to initialize GLFW3");
- return;
- }
- printf("GLFW Version: %s\n", glfwGetVersionString());
- glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
- glfwSetErrorCallback(&glfw_error_callback);
- GLFWwindow *window = glfwCreateWindow(800, 600, "The Source", null, null);
- if(!window) {
- glfwTerminate();
- writeln("Failed to initialize window");
- return;
- }
- glfwMakeContextCurrent(window);
- printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
- glfwSwapInterval(1);
- writeln("Welcome to the Source.");
- stdout.flush();
- while(!glfwWindowShouldClose(window)) {
- draw(window);
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwTerminate();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement