Skip to content

Basic Chart Loading & Display

The most basic ENC Kernel SDK usage flow - load one S-57 cell and display it inside a Win32 or Qt OpenGL widget.

  • henc.h include and henc.lib linking
  • A valid OpenGL context (Win32 wglCreateContext or Qt QOpenGLWidget)
  • data/encoptions.ini and the S-52 data directory present at runtime
  • One S-57 cell (e.g. S57/KR4A4061.000)
#include "henc.h"
#include <stdio.h>
// Assumes a Win32 + OpenGL context has already been prepared by the host app.
int main(int argc, char** argv) {
// 1. Library init - loads S-52 data + user settings
if (hencInit() != 0) {
fprintf(stderr, "hencInit failed - check encoptions.ini and S-52 data path\n");
return -1;
}
// 2. Create a view handle (call hencCreate again per additional view)
int view = hencCreate();
if (view < 0) {
hencDeinit();
return -2;
}
// 3. Bind the current OpenGL context to this view
hencSelect(view);
// 4. Viewport - call again from OnSize when the window resizes
hencSetViewport(view, 0, 0, 1024, 768);
// 5. Load an S-57 cell (auto-converts to SENC when absent)
if (hencLoad("S57/KR4A4061.000") != 0) {
fprintf(stderr, "chart load failed\n");
hencDelete(view);
hencDeinit();
return -3;
}
// 6. Initial center + zoom - units are decimal degrees
hencSetCenter(view, 129.42, 35.10); // off Busan
hencSetZoom(view, 12.0);
// 7. Render - into the back buffer
hencClearBackground(view);
hencRender(view);
hencSwapBuffer(view); // double-buffer swap
// ... your message loop (mouse / keyboard input, re-render as needed) ...
// 8. Shutdown
hencDelete(view); // release the view handle
hencDeinit(); // library + memory teardown
return 0;
}
  1. hencInit - once, at app startup
  2. hencCreate - once per view (multi-view: repeat)
  3. hencSelect - bind to the current GL context
  4. hencSetViewport - sync with window size
  5. hencLoad - cell or catalog
  6. hencSetCenter / hencSetZoom - initial position
  7. hencRender + hencSwapBuffer - every frame
  8. hencDelete / hencDeinit - at shutdown
  • hencInit fails: data/encoptions.ini is resolved relative to the working directory. If your launch path differs, use an absolute path.
  • Blank screen: hencSelect was not called, or the OpenGL context is not current on the active thread. Call wglMakeCurrent before hencSelect.
  • Cell loads but nothing draws: zoom may be outside the cell’s min/max scale band. Try hencSetViewMapByScale or hencSetUseScaleMinMax to debug.