• 프로그램을 삭제하거나 정품 등록을 해제하면 다른 PC에서 시리얼 번호를 다시 사용 할 수 있습니다. » 자세히
  • 빠르고 정확한 답변을 원하실 경우, bandicam@bandicam.com으로 문의 바랍니다.

반디캠 OpenGL 동영상캡처 에러

2015.04.16 00:34

다메즈마 조회 수:4229

초보프로그래머인데, OpenGL 프로그래밍 공부를 하고 있었는데
제 프로그램을 반디캠으로 동영상찰열을 하려 하니 제 프로그램에서 에러를 뿜고 죽어버리네요.
컴파일러는 비주얼스튜디오2013
운영체제는 윈도우8.1
사양은 모바일 I7 8Gib GTX 765M입니다.

제 코드에 문제가 있다면 어쩔 수 없지만
반디캠에 문제가 있는거라면 수정해 주셨으면 좋겠습니다.

#include <tchar.h>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <memory>
#include <vector>
#include "FreeImage.h"
#include <string>
#include <memory.h>
#pragma comment(lib,"FreeImage.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[] = _T("CodeBlocksWindowsApp");

HDC g_hdc;
HGLRC g_hrc;
LRESULT OnCreate(HWND, UINT, WPARAM, LPARAM);
LRESULT OnDestroy(HWND, UINT, WPARAM, LPARAM);
LRESULT OnPaint(HWND, UINT, WPARAM, LPARAM);
LRESULT OnSize(HWND, UINT, WPARAM, LPARAM);
void Paint(HWND hWnd);
class SurfaceManager;
class Surface{
    friend class SurfaceManager;
public:
    Surface(int width, int height) {

        GLfloat t[] = { 0.0f, 0.0f, 1.0f, 0.f, 1.f, 1.0f, 0.f, 0.f, 1.f, 1.0f, 0.f, 1.f };
        GLfloat t2[] = {
            -width/2.0f, -height/2.0f,
            width / 2.0f, -height / 2.0f,
            width / 2.0f, height / 2.0f,
            -width / 2.0f, -height / 2.0f,
            width / 2.0f, height / 2.0f,
            -width / 2.0f, height / 2.0f
        };
        memcpy(m_textureVertArr, t, sizeof(GLfloat) * 12);
        memcpy(m_vertArr, t2, sizeof(GLfloat) * 12);

        m_x = 0;
        m_y = 0;
        m_angle = 0;

        m_width = width;
        m_height = height;
    }
    void Move(GLfloat dx, GLfloat dy){
        m_x += dx; m_y += dy;
    }
    void Rotate(GLfloat dangle)
    {
        m_angle += dangle;
        if (m_angle >= 360.0f)
        {
            m_angle -= 360.0f;
        }
        else if (m_angle < 0)
        {
            m_angle += 360.0f;
        }
    }
    int GetOriginWidth()
    {
        return m_width;
    }
    int GetOriginHeight()
    {
        return m_height;
    }
    GLfloat GetWidth()
    {
        return 0.0f;
    }
    GLfloat GetHeight()
    {
        return 0.0f;
    }
    void Draw(){
        glTranslatef(m_x, m_y, 0);
        glRotatef(m_angle, 0, 0, 1);
        glBindTexture(GL_TEXTURE_2D, m_textureId);
        glVertexPointer(2, GL_FLOAT, 0, m_vertArr);
        glTexCoordPointer(2, GL_FLOAT, 0, m_textureVertArr);
        glDrawArrays(GL_TRIANGLES, 0, 6);
    }
private:
    GLfloat m_vertArr[12];
    GLfloat m_textureVertArr[12];
    GLuint m_textureId;
    GLfloat m_x;
    GLfloat m_y;
    GLfloat m_angle;

    int m_width;
    int m_height;
};
class SurfaceManager{
public:
    SurfaceManager(int size = 64){
        m_textureIdxs = new GLuint[size];
        m_size = size;
        m_cur = 0;
        glGenTextures(m_size, m_textureIdxs);
    }
    ~SurfaceManager(){
        delete[] m_textureIdxs;
    }
    std::shared_ptr<Surface> CreateSurface(const std::wstring & fileName){
        bool isExistInLoadFile = false;
        for (auto & f : m_loadingFile)
        {
            if (f.m_name == fileName)
            {
                isExistInLoadFile = true;
                break;
            }
        }
        if (isExistInLoadFile == false)
        {

       
            FIBITMAP * pBitmap = FreeImage_LoadU(FREE_IMAGE_FORMAT::FIF_PNG, fileName.c_str());
            if (pBitmap == nullptr){
                return std::shared_ptr<Surface>(nullptr);
            }
            BYTE * bits = FreeImage_GetBits(pBitmap);

            BITMAPINFO * info = FreeImage_GetInfo(pBitmap);
            unsigned pitch = FreeImage_GetPitch(pBitmap);
            for (int y = 0; y < info->bmiHeader.biHeight; y++){
                for (int x = 0; x < info->bmiHeader.biWidth; x++){
                    BYTE temp = bits[y * pitch + x * 4 + FI_RGBA_BLUE];
                    bits[y * pitch + x * 4 + FI_RGBA_BLUE] = bits[y * pitch + x * 4 + FI_RGBA_RED];
                    bits[y * pitch + x * 4 + FI_RGBA_RED] = temp;
                    BYTE alpha = bits[y * pitch + x * 4 + FI_RGBA_ALPHA];

                    if (alpha != 0){
                        printf("%d", alpha);
                    }
                }
            }
            glBindTexture(GL_TEXTURE_2D, m_textureIdxs[m_cur]);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, info->bmiHeader.biWidth, info->bmiHeader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

            std::shared_ptr<Surface> res(new Surface(info->bmiHeader.biWidth, info->bmiHeader.biHeight));
            res->m_textureId = m_textureIdxs[m_cur];

            FreeImage_Unload(pBitmap);
            _tagTexture n;
            n.m_idx = m_cur;
            n.m_name = fileName;
            m_loadingFile.push_back(n);
            m_cur++;
            return res;
        }
        else
        {

        }
    }
    void Draw();
private:
    struct _tagTexture
    {
        std::wstring m_name;
        GLuint m_idx;
        int m_width;
        int m_height;
    };
    std::vector<_tagTexture> m_loadingFile;
    GLuint * m_textureIdxs;
    int m_size;
    int m_cur;
};
SurfaceManager * g_sm;
std::shared_ptr<Surface> g_humi;
std::shared_ptr<Surface> g_sur;
int WINAPI WinMain(HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszArgument,
    int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS | CS_OWNDC ;                 /* Catch double-clicks */
    wincl.cbSize = sizeof(WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx(&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx(
        0,                   /* Extended possibilites for variation */
        szClassName,         /* Classname */
        _T("Code::Blocks Template Windows App"),       /* Title Text */
        WS_OVERLAPPEDWINDOW, /* default window */
        CW_USEDEFAULT,       /* Windows decides the position */
        CW_USEDEFAULT,       /* where the window ends up on the screen */
        544,                 /* The programs width */
        375,                 /* and height in pixels */
        HWND_DESKTOP,        /* The window is a child-window to desktop */
        NULL,                /* No menu */
        hThisInstance,       /* Program Instance handler */
        NULL                 /* No Window Creation data */
        );

    /* Make the window visible on the screen */
    ShowWindow(hwnd, nCmdShow);

    int tick = GetTickCount();
    int preTick = tick;
    double timeDelta = (tick - preTick) / 1000.0;
    double fpsLimit = 0.0;
    while (true)
    {
        tick = GetTickCount();
        timeDelta = (tick - preTick) / 1000.0;
        if (PeekMessage(&messages, NULL, NULL, NULL, PM_REMOVE))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        else
        {
            if (timeDelta < 1 / 60.0)
            {
                fpsLimit += timeDelta;

            }
            while (fpsLimit > 1 / 60.0)
            {
                Paint(messages.hwnd);
                InvalidateRect(hwnd, NULL, false);
                fpsLimit -= 1 / 60.0;
            }
        }
        if (messages.message == WM_QUIT)
        {
            break;
        }
        g_humi->Rotate(timeDelta * 180);
       
       
       
        preTick = tick;
       
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
LRESULT OnCreate(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PIXELFORMATDESCRIPTOR pfd = { 0, };
    int nPixelFormat;
    g_hdc = GetDC(hWnd);
   
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
        PFD_SUPPORT_OPENGL |
        PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;

    nPixelFormat = ChoosePixelFormat(g_hdc, &pfd);
    SetPixelFormat(g_hdc, nPixelFormat, &pfd);
    g_hrc = wglCreateContext(g_hdc);
    wglMakeCurrent(g_hdc, g_hrc);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_COLOR_MATERIAL);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    g_sm = new SurfaceManager();
    g_sur = g_sm->CreateSurface(L"074_4.png");
    g_humi = g_sm->CreateSurface(L"074_3.png");
    g_sur->Move(400, 0);
    return 0;
}
LRESULT OnDestroy(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    delete g_sm;
    g_humi.reset();
    g_sur.reset();
    wglMakeCurrent(g_hdc, NULL);
    wglDeleteContext(g_hrc);
    ReleaseDC(hWnd, g_hdc);
    PostQuitMessage(0);
    return 0;
}
void Paint(HWND hWnd)
{
    RECT rc = { 0, };
    GetClientRect(hWnd, &rc);
   
    glClearColor(1, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-rc.right, rc.right, -rc.bottom, rc.bottom);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //glColor3f(1.0f, 1.0f, 1.0f);

    glPushMatrix();
    g_sur->Draw();
    glPopMatrix();

    glPushMatrix();
    g_humi->Draw();
    glPopMatrix();

   
   
}
LRESULT OnPaint(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    //Paint(hWnd);
    SwapBuffers(g_hdc);
    ValidateRect(hWnd, NULL);
    return 0;
}
LRESULT OnSize(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
    //OnPaint(hWnd, uMsg, wParam, lParam);
    Paint(hWnd);
    return 0;
}
/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch (message){
    case WM_CREATE:
        return OnCreate(hwnd, message, wParam, lParam);
    case WM_DESTROY:
        return OnDestroy(hwnd, message, wParam, lParam);
    case WM_PAINT:
        return OnPaint(hwnd, message, wParam, lParam);
    case WM_SIZE:
        return OnSize(hwnd, message, wParam, lParam);
    default:                      /* for messages that we don't deal with */
        return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}

번호 제목 글쓴이 날짜 조회 수
4015 2560 쿼드 또는 4k 듀얼 녹화 [1] 초고해상도 2015.06.23 2927
4014 시리얼넘버 관련 질문 [3] secret 심근섭 2015.06.22 5
4013 강의녹화 [1] monkey 2015.06.21 5453
4012 등록이 되어 있지 않다고 하네;요 [4] kyy2394 2015.06.20 2890
4011 정품 구입시에 [1] secret 반디캠 2015.06.20 2
4010 반디캠 관련 질문드려요. [1] secret 디캠이짱 2015.06.20 3
4009 쉐도우레코딩 기능이 있었으면 좋겠어요 [3] 인실 2015.06.19 2641
4008 마이크로 소프트 오피스 365 원노트와 충돌. [3] 2015.06.19 3616
4007 문의 드립니다 [1] 이승환 2015.06.18 2613
4006 MP4로 녹화시 소리가 안나와요 [1] 소리 2015.06.18 3952
4005 구매한 제품 컴 셋팅후 사용하려는데? [1] 이병기 2015.06.18 2818
4004 아프리카tv 녹화문제관련 [2] secret 아프리카 2015.06.17 14
4003 강의 녹화 [1] secret john888 2015.06.17 7
4002 반디캠 기능 추가 건의 합니다. [1] file 화이팅 2015.06.17 2906
4001 아프리카 녹화하다가 신기한점(?) 발견해서 문의드립니다 [1] A-tek 2015.06.16 2938
4000 반디캠 녹화를 시작하면 녹화하려는 영상이 느려집니다! [1] 영영 2015.06.14 2656
3999 반디캠 라이선스 관련 문의 [1] 반디고 2015.06.14 3164
3998 반디캠 시리얼 번호 재발급 [1] secret 강민기 2015.06.13 6
3997 회색화면..게임은 녹화가 안되요 [1] 문주성 2015.06.13 3029
3996 H264로 녹화를 시작하면 게임이 팅깁니다. [1] 래리 2015.06.12 2733