From 8cf216ee1cc6d68d2570bfb4e2d92405d469bbb1 Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Sat, 18 Apr 2020 20:05:18 +0300 Subject: [PATCH] initial commit: a line and 5 points --- Makefile | 24 +++++++++++++++++++ src/main.cc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tentacle.cc | 48 +++++++++++++++++++++++++++++++++++++ src/tentacle.h | 20 ++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100755 Makefile create mode 100644 src/main.cc create mode 100644 src/tentacle.cc create mode 100644 src/tentacle.h diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..f2fc953 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +src = $(wildcard src/*.cc) +obj = $(src:.cc=.o) +dep = $(obj:.o=.d) +bin = splines + +dbg = -g +opt = -O0 +inc = -Isrc + +CXX = g++ +CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) +LDFLAGS = -lGL -lGLU -lglut -lGLEW -limago -lgmath + +$(bin): $(obj) + $(CXX) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +%.d: %.cc + @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) $(dep) diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..c5ebc84 --- /dev/null +++ b/src/main.cc @@ -0,0 +1,72 @@ +#include +#include +#include + +#include "tentacle.h" + +static bool init(); +static void cleanup(); + +static void display(); +static void keyboard(unsigned char key, int x, int y); + +/* XXX FIXME */ +static Tentacle tentacle; + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitWindowSize(800, 600); + glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); + + glutCreateWindow("ludu mice"); + glutDisplayFunc(display); + glutKeyboardFunc(keyboard); + + if (!init()) + exit(1); + + atexit(cleanup); + + glutMainLoop(); +} + +static bool init() +{ + glewInit(); + glClearColor(1.0, 1.0, 0.0, 1.0); + + if (!tentacle.init()) { + fprintf(stderr, "Failed to initialize tentacle control points.\n"); + return false; + } + + return true; +} + +static void cleanup() +{ +} + +static void display() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + //XXX FIXME + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + tentacle.draw(); + + glutSwapBuffers(); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch(key) { + case 27: + exit(0); + default: + break; + } +} diff --git a/src/tentacle.cc b/src/tentacle.cc new file mode 100644 index 0000000..7a69c29 --- /dev/null +++ b/src/tentacle.cc @@ -0,0 +1,48 @@ +#include +#include "tentacle.h" + +Tentacle::Tentacle() +{ +} + +Tentacle::~Tentacle() +{ +} + +bool +Tentacle::init() +{ + for (int i=0; i<5; i++) { + add_control_point(Vec3(0.5, i / 10.0, 0.0)); + } + return true; +} + +void +Tentacle::add_control_point(const Vec3 &point) +{ + cpoints.push_back(point); +} + +void +Tentacle::draw() +{ + glLineWidth(2.0); + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 0.0, 1.0); + for(size_t i=0; i +#include + +class Tentacle { +private: + std::vector cpoints; + +public: + Tentacle(); + ~Tentacle(); + + bool init(); + void add_control_point(const Vec3 &point); + void draw(); +}; + +#endif // TENTACLE_H_ -- 1.7.10.4