Skocz do zawartości

Okno w OpenGL


Lunatyk

Rekomendowane odpowiedzi

Ten program ma rysować i obracać trójkąt, ale nie działa. W Visual'u niezbyt rozumiem te błędy jak nie ma nigdzie podkreślenia.

 

#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <GL/GL.H>
#include <GL/GLU.H>
#include <GL/GLAUX.H>

float angle = 0.0f;
HDC g_HDC;

void SetupPixelFormat (HDC hDC)
{
    int nPixelFormat;

    static PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW |
        PFD_SUPPORT_OPENGL |
        PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        32,
        0, 0, 0, 0, 0, 0,
        0,
        0,
        0,
        0, 0, 0, 0,
        16,
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0, 0, 0 };

    nPixelFormat = ChoosePixelFormat (hDC, &pfd);

    SetPixelFormat (hDC, nPixelFormat, &pfd);
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HGLRC hRC;
    static HDC hDC;
    int width, height;

    switch (message)
    {
    case WM_CREATE:

        hDC = GetDC (hwnd);
        g_HDC = hDC;
        SetupPixelFormat (hDC);

        hRC = wglCreateContext (hDC);
        wglMakeCurrent (hDC, hRC);

        return 0;
        break;

    case WM_CLOSE:

        wglMakeCurrent (hDC, NULL);
        wglDeleteContext (hRC);

        PostQuitMessage (0);

        return 0;
        break;

    case WM_SIZE:
        height = HIWORD (lParam);
        width = LOWORD (lParam);

        if (height == 0)
        {
            height = 1;
        }

        glViewport (0, 0, width, height);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity();

        gluPerspective (45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity();

        return 0;
        break;

    default:
        break;
    }

    return (DefWindowProc (hwnd, message, wParam, lParam));
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    WNDCLASSEX windowClass;
    HWND hwnd;
    MSG msg;
    bool done;
    LPCWSTR myClass = TEXT ("MojaKlasa");

    windowClass.cbSize = sizeof (WNDCLASSEX);
    windowClass.style = CS_HREDRAW | CS_VREDRAW;
    windowClass.lpfnWndProc = 0;
    windowClass.cbClsExtra = 0;
    windowClass.hInstance = hInstance;
    windowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    windowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    windowClass.hbrBackground = NULL;
    windowClass.lpszMenuName = NULL;
    windowClass.lpszClassName = myClass;
    windowClass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);

    if (!RegisterClassEx (&windowClass))
        return 0;

    hwnd = CreateWindowEx (NULL,
        myClass,
        TEXT ("Aplikacja OpenGL"),
        WS_OVERLAPPEDWINDOW | WS_VISIBLE |
        WS_SYSMENU | WS_CLIPCHILDREN |
        WS_CLIPSIBLINGS,
        100, 100,
        400, 400,
        NULL,
        NULL,
        hInstance,
        NULL);

    if (!hwnd)
        return 0;

    ShowWindow (hwnd, SW_SHOW);
    UpdateWindow (hwnd);

    done = false;

    while (!done)
    {
        PeekMessage (&msg, hwnd, NULL, NULL, PM_REMOVE);

        if (msg.message == WM_QUIT)
        {
            done = true;
        }
        else
        {
            glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();

            angle = angle + 0.1f;
            if (angle >= 360.0f)
                angle = 0.0f;
            glTranslatef (0.0f, 0.0f, -5.0f);
            glRotatef (angle, 0.0f, 0.0f, 1.0f);

            glColor3f (1.0f, 0.0f, 0.0f);
            glBegin (GL_TRIANGLES);
                glVertex3f (0.0f, 0.0f, 0.0f);
                glVertex3f (1.0f, 0.0f, 0.0f);
                glVertex3f (1.0f, 1.0f, 0.0f);
            glEnd();
            SwapBuffers (g_HDC);

            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
    }
    return msg.wParam;
}

 

 

 

1>------ Build started: Project: OpenGL, Configuration: Debug Win32 ------
1>Build started 2010-10-23 11:20:55.
1>InitializeBuildStatus:
1>  Touching "Debug\OpenGL.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol __imp__gluPerspective@32 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _WinMain@16
1>C:\Documents and Settings\Mannor\Pulpit\test\opengl\OpenGL\Debug\OpenGL.exe : fatal error LNK1120: 14 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.82
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Odnośnik do komentarza
Udostępnij na innych stronach

unresolved external symbol

oznacza że nie podałeś linkerowi plików .lib których wymaga aplikacja OGL. u Ciebie to będą: opengl32.lib, glu32.lib

Odnośnik do komentarza
Udostępnij na innych stronach

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...