To home page

Source code. Water rendering

Home page

This code contains a DLL implementing water rendering with OpenGL, and you can directly use it in your projects to render water surface.
The DLL is actually a COM object which should be registered with Windows regsvr32.exe (interface function file is attached).
A sample project (Visual C++ 6.0) is also provided.

The code is based upon a brilliant article "Using vertex texture displacement for realistic water rendering".

List of files:

  • runtest.bat - registers STVisualSea.dll with regsvr32.exe and runs the demo SeaTest.exe
  • STVisualSea.dll - DLL which implements water rendering, this is that big because its resources contain a number of big (but compressed) bitmaps
  • SeaTest.exe - demo which calls STVisualSea.dll
  • STVisualSea.idl, STVisualSea_i.c, STVisualSea_p.c, - interface files for STVisualSea.dll
  • STSeaTestProject.zip - sample project to compile SeaTest.exe demo
  • Interface functions:

  • Init() - allocates memory, loads resources etc. Should be called first after OpenGL is started, CoInitialize() called and a COM object by CreateInstance is created.
  • Start(float frustumangle, float waveheight, long wpointsptr, long numwpoints) - sets rendering parameters : frustum angle in degrees (default 45.0); wave height in metres; wpointsptr - pointer to an array of X-Y float pairs which represent your ship waterline shape (Y points forward, points go counterclockwise); numpoints - number of such points. The waterline shape can specified to avoid waves penetrating ship hull. Set wpointsptr to NULL and numpoints to 0 if not needed.
  • Render(float coursedeg, float speedx, float speedy, float windx, float windy) - call this function for every frame. coursedeg - ship course in degrees, speedx, speedy - ship speed vector components in m/s; windx, windy - wind vector component along X and Y in m/s. Y axis is directed upwards to the North, X - to the starboard.
  • Stop() - stop rendering
  • Quit() - deallocate memory etc.
  • For the sample code look at full source in STSeaTestProject.zip, file SeaTest.cpp

    © Copyright 2007..2009 MI Simulators