opengl – the megastructure development blog http://blog.megastructure.org tracking construction of megaprojects Sun, 23 Dec 2018 15:54:33 +0000 en-US hourly 1 https://wordpress.org/?v=5.0.2 Technical: Depth buffer in OpenGL http://blog.megastructure.org/2009/10/technical-depth-buffer-in-opengl/ Mon, 12 Oct 2009 21:54:10 +0000 http://blog.megastructure.org/?p=130 I just thought I’d post this up here, in case other people had the same problem.

The Megastrata project started out like any other first-time project: cobbled together from examples found on the internet. One of the long-standing traditions regarding development involve the so-called “hack-n-slash” technique: smash the code around until it works.

Megastrata started life out as the NoiseViewer, which was, true to its name, simply a 2D noise patter viewer. Hence, there was originally no need for a depth buffer.

When the leap was made to 3D, I made it work on Windows. But the OS X version didn’t render the same way. Wolfgang put a lot of effort into debugging it, and after sending screenshots back and forth, we understood that the problem was with the depth buffer.

I saw something suspicious when I looked up the OpenGL FAQ on the subject. Step one reads:

1. Ask for a depth buffer when you create your window.

Evidently, Windows automatically specifies a depth buffer created when initializing the window, whereas OS X does not do this by default.

We changed the line in the code that read:

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

to:

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

and the problem was solved.

]]>
NoiseViewer version 1 http://blog.megastructure.org/2009/07/noiseviewer-version-1/ Fri, 10 Jul 2009 10:38:50 +0000 http://blog.megastructure.org/?p=8 The NoiseViewer is a simple program that lets you explore a two-dimensional noise map generated in real-time. This is a preliminary tool designed to be a starting point for mapping out and viewing procedural content. I hope to make the NoiseViewer more and more sophisticated as layers of noise and objects start stacking up.

NoiseViewer v1.0 screenshot

This is terribly preliminary!

  • Uses Stefan Gustavson’s implementation of Simplex Noise (available here). I’ve made a few changes, so that it works better on Windows. The source download (below) includes the modified Simplex Noise code. For more information on Simplex Noise, see Simplex noise and Perlin noise.
  • Uses FreeGLUT, also included in the source below.
  • Some of the code is based on wonderful examples found on the OpenGL site, numerous snippets found online, and of course NeHe’s excellent tutorials.
  • My code is not elegant. This version focuses on making something work, nothing more.

From what I understand of the licenses, I am allowed to use these libraries. Please understand that the code and programs linked to below are provided “as-is”. Also note that running any program found on the internet carries risk, and the responsible user always scans for viruses, etc.

Click and drag to pan around the noise. CTRL+click-and-drag up and down adjusts the zoom level. Shift+click-and-drag adjusts the noise cutoff point.

Compiled executable (Windows, ~266KB): NoiseViewer_v1.zip

Source code, libraries and projects (Visual Studio 2008, ~1,456KB): NoiseViewer_v1_src.zip

Feedback would be greatly appreciated!!

]]>