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.
Prerequisites
Section titled “Prerequisites”henc.hinclude andhenc.liblinking- A valid OpenGL context (Win32
wglCreateContextor QtQOpenGLWidget) data/encoptions.iniand 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;}Flow at a glance
Section titled “Flow at a glance”- hencInit - once, at app startup
- hencCreate - once per view (multi-view: repeat)
- hencSelect - bind to the current GL context
- hencSetViewport - sync with window size
- hencLoad - cell or catalog
- hencSetCenter / hencSetZoom - initial position
- hencRender + hencSwapBuffer - every frame
- hencDelete / hencDeinit - at shutdown
Common pitfalls
Section titled “Common pitfalls”hencInitfails:data/encoptions.iniis resolved relative to the working directory. If your launch path differs, use an absolute path.- Blank screen:
hencSelectwas not called, or the OpenGL context is not current on the active thread. CallwglMakeCurrentbeforehencSelect. - Cell loads but nothing draws: zoom may be outside the cell’s min/max scale band. Try hencSetViewMapByScale or hencSetUseScaleMinMax to debug.