commit fcf17760bb747380a3dd3f883740f27164865984
parent fe75fb0bfebc9f81bd35ed45aaee8b5db50c1a75
Author: William Casarin <bill@casarin.me>
Date: Wed, 25 Mar 2015 23:52:45 -0700
Initial stuff
Diffstat:
12 files changed, 131 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,15 +1,20 @@
BIN ?= polyadvent
PREFIX ?= /usr/local
-LDFLAGS = -lglfw3 -lX11 -lGL -lXi -lXrandr -lXxf86vm
+LDFLAGS = -lglfw3 -lX11 -lGL -lXi -lXrandr -lXxf86vm -lepoxy
+DEFS= -DGLFW_INCLUDE_NONE
+
+OBJS = render.o
+OBJS += window.o
+OBJS += buffer.o
all: $(BIN)
-%.o: %.c
- $(CXX) -o $@ -c $<
+%.o: %.cc
+ $(CXX) $(DEFS) -c $< -o $@
$(BIN): $(OBJS)
- $(CXX) $^ main.cc $(LDFLAGS) -o $@
+ $(CXX) $(DEFS) $^ main.cc $(LDFLAGS) -o $@
install: $(BIN)
install -d $(PREFIX)/bin
diff --git a/buffer.cc b/buffer.cc
@@ -0,0 +1,14 @@
+
+#include "buffer.h"
+
+/*
+ * Functions for creating OpenGL objects:
+ */
+GLuint
+make_buffer(GLenum target, const void *buffer_data, GLsizei buffer_size) {
+ GLuint buffer;
+ glGenBuffers(1, &buffer);
+ glBindBuffer(target, buffer);
+ glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW);
+ return buffer;
+}
diff --git a/buffer.h b/buffer.h
@@ -0,0 +1,8 @@
+#ifndef POLYADVENT_BUFFER_H
+#define POLYADVENT_BUFFER_H
+
+#include "gl.h"
+
+GLuint make_buffer(GLenum target, const void *buffer_data, GLsizei buffer_size);
+
+#endif /* POLYADVENT_BUFFER_H */
diff --git a/common.h b/common.h
@@ -0,0 +1,5 @@
+
+#ifndef POLYADVENT_COMMON_H
+#define POLYADVENT_COMMON_H
+
+#endif /* POLYADVENT_COMMON_H */
diff --git a/default.nix b/default.nix
@@ -1,21 +1,21 @@
-{clangStdenv, glfw, mesa, xlibs}:
+{clangStdenv, glfw, mesa, xlibs, epoxy}:
let
stdenv = clangStdenv;
in stdenv.mkDerivation rec {
- name = "polycraft";
+ name = "polyadvent";
version = "0.1";
src = ./.;
makeFlags = "PREFIX=$(out)";
- buildInputs = [ glfw mesa ]
+ buildInputs = [ glfw mesa epoxy ]
++ (with xlibs; [ libX11 libXi libXrandr libXxf86vm ] );
meta = with stdenv.lib; {
description = "Procedural low poly fun";
- homepage = "https://jb55.com/polycraft";
+ homepage = "https://jb55.com/polyadvent";
maintainers = with maintainers; [ jb55 ];
license = licenses.gpl2;
};
diff --git a/delaunay.cc b/delaunay.cc
@@ -0,0 +1 @@
+
diff --git a/gl.h b/gl.h
@@ -0,0 +1,7 @@
+#ifndef POLYADVENT_GL_H
+#define POLYADVENT_GL_H
+
+#include <GLFW/glfw3.h>
+#include <epoxy/gl.h>
+
+#endif /* POLYADVENT_GL_H */
diff --git a/main.cc b/main.cc
@@ -1,37 +1,47 @@
-#include <GLFW/glfw3.h>
+#include "gl.h"
+#include "window.h"
+#include "render.h"
int main(void)
{
- GLFWwindow* window;
+ GLFWwindow* window;
- /* Initialize the library */
- if (!glfwInit())
- return -1;
+ /* Initialize the library */
+ if (!glfwInit())
+ return -1;
- /* Create a windowed mode window and its OpenGL context */
- window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
- if (!window)
- {
- glfwTerminate();
- return -1;
- }
+ /* Create a windowed mode window and its OpenGL context */
+ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
+ if (!window) {
+ glfwTerminate();
+ return -1;
+ }
- /* Make the window's context current */
- glfwMakeContextCurrent(window);
+ /* Make the window's context current */
+ glfwMakeContextCurrent(window);
+ glfwSetWindowSizeCallback(window, handle_resize);
- /* Loop until the user closes the window */
- while (!glfwWindowShouldClose(window))
- {
- /* Render here */
+ init_gl();
- /* Swap front and back buffers */
- glfwSwapBuffers(window);
+ /* Loop until the user closes the window */
+ while (!glfwWindowShouldClose(window)) {
+ glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); //clear background screen to black
+ glClear( GL_COLOR_BUFFER_BIT );
- /* Poll for and process events */
- glfwPollEvents();
- }
+ glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
+ glLoadIdentity(); //Reset the drawing perspective
- glfwTerminate();
- return 0;
+ render();
+
+ /* Swap front and back buffers */
+ glfwSwapBuffers(window);
+
+ /* Poll for and process events */
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ return 0;
}
+
diff --git a/render.cc b/render.cc
@@ -0,0 +1,21 @@
+
+#include "gl.h"
+
+
+void
+init_gl() {
+ glEnable(GL_DEPTH_TEST);
+}
+
+
+void
+render () {
+ glBegin(GL_TRIANGLES); //Begin triangle coordinates
+
+ //Triangle
+ glVertex3f(-0.5f, 0.5f, -5.0f);
+ glVertex3f(-1.0f, 1.5f, -5.0f);
+ glVertex3f(-1.5f, 0.5f, -5.0f);
+
+ glEnd(); //End triangle coordinates
+}
diff --git a/render.h b/render.h
@@ -0,0 +1,7 @@
+#ifndef POLYADVENT_RENDER_H
+#define POLYADVENT_RENDER_H
+
+void init_gl();
+void render();
+
+#endif /* POLYADVENT_RENDER_H */
diff --git a/window.cc b/window.cc
@@ -0,0 +1,12 @@
+
+
+#include "gl.h"
+
+void
+handle_resize(GLFWwindow * window, int width, int height) {
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION ); //Switch to setting the camera perspective
+ //Set the camera perspective
+ glLoadIdentity(); //reset the camera
+}
diff --git a/window.h b/window.h
@@ -0,0 +1,8 @@
+
+#ifndef POLYADVENT_WINDOW_H
+#define POLYADVENT_WINDOW_H
+
+void handle_resize(GLFWwindow * window, int width, int height);
+
+
+#endif /* POLYADVENT_WINDOW_H */