Thursday, December 18, 2014

Voronoi Diagram c++ code example

I found the following c++ OpenGL Voronoi  found here example.

I presume you'd have the GLUT and GLEW libraries installed (or otherwise given by the package FreeGlut) with dev libraries.  

Additionally you may want to install, 

sudo apt-get install libxmu-dev libxi-dev

for instance, Ubuntu, or Debian variant (hopefully your OS distro has it).

Then presuming you have cmake installed on your system (version 2.8 or greater),
you can add the following to a file called:

CMakeLists.txt


cmake_minimum_required(VERSION 2.8)
# Project Name
PROJECT(HW_OPENGL)

#########################################################
# FIND GLUT
#########################################################
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
if(NOT GLUT_FOUND)
    message(ERROR " GLUT not found!")
endif(NOT GLUT_FOUND)
#########################################################
# FIND OPENGL
#########################################################
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
    message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)
#########################################################
# Include Files
#########################################################
file(GLOB helloworld_SRC
    "*.h"
    "*.cpp"
)

add_executable(test main.cpp ${helloworld_SRC})

########################################################
# Linking & stuff
#########################################################

  # create the program "test"
  target_link_libraries(test ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )


because I am lazy and hadn't wanted to parse the individual .cpp and.h files in our given source directory for reference.  I manually deleted the old_main.cpp file from the source directory, and 
linux there is funny compiler error where sqrt is not found in the std:: namespace.  So you can simply add on your voronoi.cpp file 

#include ..cmath ..  

which seems to resolve this.

while you can likely try to find through all the various g++ command options, linking directories and files, I personally as a noob am clueless and resort to cmake for ease in program compilations and builds.  Highly recommend this for a command line compilation and configuration.

In the source directory, then you should be able at console type:

cmake .

then after successful cmake compilation type:

make

which will compile and build the program executable.

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...