2

I'm trying to use OpenGL to draw the picture from kinect. Following this article

I'm using visual studio 2012 and have linked the freeglut.lib in the linker property

I've also put the .dll files to my System32 and SysWOW64 directory

Got these errors while compiling:

Error   9   error LNK2019: unresolved external symbol __imp__NuiGetSensorCount@4 referenced in function "bool __cdecl initKinect(void)" (?initKinect@@YA_NXZ)   
Error   10  error LNK2019: unresolved external symbol __imp__NuiCreateSensorByIndex@8 referenced in function "bool __cdecl initKinect(void)" (?initKinect@@YA_NXZ)  
Error   4   error LNK2019: unresolved external symbol __imp__glutSwapBuffers@0 referenced in function "void __cdecl draw(void)" (?draw@@YAXXZ)  
Error   3   error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function "void __cdecl execute(void)" (?execute@@YAXXZ)   
Error   1   error LNK2019: unresolved external symbol __imp__glutInitWindowSize@8 referenced in function "bool __cdecl init(int,char * * const)" (?init@@YA_NHQAPAD@Z)  
Error   2   error LNK2019: unresolved external symbol __imp__glutInitDisplayMode@4 referenced in function "bool __cdecl init(int,char * * const)" (?init@@YA_NHQAPAD@Z) 
Error   5   error LNK2019: unresolved external symbol __imp__glutIdleFunc@4 referenced in function "bool __cdecl init(int,char * * const)" (?init@@YA_NHQAPAD@Z)
Error   6   error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function "bool __cdecl init(int,char * * const)" (?init@@YA_NHQAPAD@Z)
Error   7   error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8   
Error   8   error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4    
Error   11  error LNK1120: 10 unresolved externals

Here's the code:

#include <iostream>
#include <Windows.h>
#include <Ole2.h>

#include <gl/GL.h>
#include <gl/GLU.h>
#include <glut.h>

#include <NuiApi.h>
#include <NuiImageCamera.h>
#include <NuiSensor.h>

using namespace std;
#define width 640
#define height 480
#define GL_BGRA 0x80E1
// OpenGL Variables
GLuint textureId;              // ID of the texture to contain Kinect RGB Data
GLubyte data[width*height*4];  // BGRA array containing the texture data

// Kinect variables
HANDLE rgbStream;              // The identifier of the Kinect's RGB Camera
INuiSensor* sensor;            // The kinect sensor

bool initKinect() {
    // Get a working kinect sensor
    int numSensors;
    if (NuiGetSensorCount(&numSensors) < 0 || numSensors < 1) return false;
    if (NuiCreateSensorByIndex(0, &sensor) < 0) return false;

    // Initialize sensor
    sensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_COLOR);
    sensor->NuiImageStreamOpen(
        NUI_IMAGE_TYPE_COLOR,            // Depth camera or rgb camera?
        NUI_IMAGE_RESOLUTION_640x480,    // Image resolution
        0,      // Image stream flags, e.g. near mode
        2,      // Number of frames to buffer
        NULL,   // Event handle
        &rgbStream);
    return sensor;
}

void getKinectData(GLubyte* dest) {
    NUI_IMAGE_FRAME imageFrame;
    NUI_LOCKED_RECT LockedRect;
    if (sensor->NuiImageStreamGetNextFrame(rgbStream, 0, &imageFrame) < 0) return;
    INuiFrameTexture* texture = imageFrame.pFrameTexture;
    texture->LockRect(0, &LockedRect, NULL, 0);
    if (LockedRect.Pitch != 0)
    {
        const BYTE* curr = (const BYTE*) LockedRect.pBits;
        const BYTE* dataEnd = curr + (width*height)*4;

        while (curr < dataEnd) {
            *dest++ = *curr++;
        }
    }
    texture->UnlockRect(0);
    sensor->NuiImageStreamReleaseFrame(rgbStream, &imageFrame);
}

void drawKinectData() {
    glBindTexture(GL_TEXTURE_2D, textureId);
    getKinectData(data);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)data);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0, 0, 0);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(width, 0, 0);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(width, height, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0, height, 0.0f);
    glEnd();
}

void draw() {
   drawKinectData();
   glutSwapBuffers();
}

void execute() {
    glutMainLoop();
}

bool init(int argc, char* argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(width,height);
    glutCreateWindow("Kinect SDK Tutorial");
    glutDisplayFunc(draw);
    glutIdleFunc(draw);
    return true;
}




int main(int argc, char* argv[]) {
    if (!init(argc, argv)) return 1;
    if (!initKinect()) return 1;

    /* ...OpenGL texture and camera initialization... */
        // Initialize textures
    glGenTextures(1, &textureId);
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,                 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*) data);
    glBindTexture(GL_TEXTURE_2D, 0);

    // OpenGL setup
    glClearColor(0,0,0,0);
    glClearDepth(1.0f);
    glEnable(GL_TEXTURE_2D);

    // Camera setup
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, height, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    // Main loop
    execute();
    return 0;
}
Edward
  • 161
  • 1
  • 1
  • 12
  • It looks like this is a problem with linking to the glut and kinect libraries your using. You should see http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix. – Timothy Murphy Jan 02 '16 at 08:07
  • It turns out I have the wrong glut.h and wrong kinect10.dll should use the one from opengl directly not the one provided in the above link – Edward Jan 02 '16 at 08:31

0 Answers0