### Learning OpenGL for N-body Sims #1 - Using GLFW and C++ with Cmake

I've been wanting to write a C++ real-time N-body simulation using different methods such as CPU/GPU computation, and N-body algorithms such as the Barnes-Hut algorithm which organizes the space with an oct-tree.

For real-time visualization two main contenders are DirectX and OpenGL, I decided to go with OpenGL.

There are many different ways to use OpenGL, NeHe has an amazing set of tutorials for OpenGL, but there are some newer interfaces that can simplify developing a UI with OpenGL and use shaders etc. One tool is GLFW which provides an easy way to make a window, provide context and receive events such as keyboard and mouse commands.

As a first step, we'll make a window with a spinning colored triangle, but not use any shaders etc. yet. Besides some boilerplate setup, it's as as simple as:

For real-time visualization two main contenders are DirectX and OpenGL, I decided to go with OpenGL.

There are many different ways to use OpenGL, NeHe has an amazing set of tutorials for OpenGL, but there are some newer interfaces that can simplify developing a UI with OpenGL and use shaders etc. One tool is GLFW which provides an easy way to make a window, provide context and receive events such as keyboard and mouse commands.

As a first step, we'll make a window with a spinning colored triangle, but not use any shaders etc. yet. Besides some boilerplate setup, it's as as simple as:

// Rotate our frame of reference glLoadIdentity(); glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f); // Draw triangle | |

glBegin(GL_TRIANGLES); | |

glColor3f(1.f, 0.f, 0.f); | |

glVertex3f(-0.6f, -0.4f, 0.f); | |

glColor3f(0.f, 1.f, 0.f); | |

glVertex3f(0.6f, -0.4f, 0.f); | |

glColor3f(0.f, 0.f, 1.f); | |

glVertex3f(0.f, 0.6f, 0.f); | |

glEnd(); | |

Spinning triangle using OpenGL, GLFW with C++ and Cmake for compiling |