Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module main;
- import std.stdio;
- import derelict.opengl3.gl;
- import derelict.glfw3.glfw3;
- extern (C) void onError(int error, const (char)* desc) nothrow
- {
- scope(failure) assert(0);
- writeln("Houston, we've had a problem: [", error, "] ", desc);
- }
- extern (C) void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) nothrow
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- }
- extern (C) void onResize(GLFWwindow* window, int width, int height) nothrow
- {
- glViewport(0, 0, width, height);
- }
- void main(string[] args)
- {
- // start
- writeln("Starting...");
- DerelictGLFW3.load();
- DerelictGL.load();
- glfwSetErrorCallback(&onError);
- if (!glfwInit())
- return;
- // init
- GLFWwindow* window = glfwCreateWindow(640, 480, "Snake 4D", null, null);
- if (window == null)
- return;
- glfwSetKeyCallback(window, &onKey);
- glfwSetFramebufferSizeCallback(window, &onResize);
- glfwMakeContextCurrent(window);
- // run
- while (!glfwWindowShouldClose(window))
- {
- float ratio;
- int width, height;
- glfwGetFramebufferSize(window, &width, &height);
- ratio = width / cast(float) height;
- glViewport(0, 0, width, height);
- glClear(GL_COLOR_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-ratio, ratio, -1.0f, 1.0f, 1.0f, -1.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glRotatef(cast(float) glfwGetTime() * 50.0f, 0.0f, 0.0f, 1.0f);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3f(-0.6f, -0.4f, 0.0f);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex3f(0.6f, -0.4f, 0.0f);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex3f(0.0f, 0.6f, 0.0f);
- glEnd();
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- // finish
- if (window != null)
- glfwDestroyWindow(window);
- glfwTerminate();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement